aboutsummaryrefslogtreecommitdiffstats
path: root/netcfg
diff options
context:
space:
mode:
authorSzymon Jakubczak <szym@google.com>2010-06-09 16:11:09 -0400
committerJean-Baptiste Queru <jbq@google.com>2010-08-25 08:13:42 -0700
commit8c85a00db6da092ec3766facd49132fa4fc319a1 (patch)
tree4d7015b3de6955bb0ef9b10efeef039fd9e0a542 /netcfg
parent2c72df998799738662a77cef3f522fdc6ae22fde (diff)
downloadsystem_core-8c85a00db6da092ec3766facd49132fa4fc319a1.tar.gz
system_core-8c85a00db6da092ec3766facd49132fa4fc319a1.tar.bz2
system_core-8c85a00db6da092ec3766facd49132fa4fc319a1.zip
- creates proper ifc.h and dhcp.h headers for libnetutils
- adds ifc_set_hwaddr - adds hwaddr command to netcfg - code reuse: dhcp_configure calls ifc_configure; inet_ntoa is used for printing - consistency: use net.XXX.dnsX properties in favor of dhcp.XXX.dnsX properties (see related change to WifiStateTracker) - updated system/core/nexus to use new headers, although not sure if anybody still uses nexus Change-Id: Idd70c0ac6e89b38e86816578c33eff805d30cac4
Diffstat (limited to 'netcfg')
-rw-r--r--netcfg/netcfg.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/netcfg/netcfg.c b/netcfg/netcfg.c
index fc9cf48b..9cd883a8 100644
--- a/netcfg/netcfg.c
+++ b/netcfg/netcfg.c
@@ -19,17 +19,13 @@
#include <stdlib.h>
#include <errno.h>
#include <dirent.h>
+#include <netinet/ether.h>
+
+#include <netutils/ifc.h>
+#include <netutils/dhcp.h>
static int verbose = 0;
-int ifc_init();
-void ifc_close();
-int ifc_up(char *iname);
-int ifc_down(char *iname);
-int ifc_remove_host_routes(char *iname);
-int ifc_remove_default_route(char *iname);
-int ifc_get_info(const char *name, unsigned *addr, unsigned *mask, unsigned *flags);
-int do_dhcp(char *iname);
void die(const char *reason)
{
@@ -37,16 +33,12 @@ void die(const char *reason)
exit(1);
}
-const char *ipaddr(unsigned addr)
+const char *ipaddr(in_addr_t addr)
{
- static char buf[32];
-
- sprintf(buf,"%d.%d.%d.%d",
- addr & 255,
- ((addr >> 8) & 255),
- ((addr >> 16) & 255),
- (addr >> 24));
- return buf;
+ struct in_addr in_addr;
+
+ in_addr.s_addr = addr;
+ return inet_ntoa(in_addr);
}
void usage(void)
@@ -86,6 +78,15 @@ int dump_interfaces(void)
return 0;
}
+int set_hwaddr(const char *name, const char *asc) {
+ struct ether_addr *addr = ether_aton(asc);
+ if (!addr) {
+ printf("Failed to parse '%s'\n", asc);
+ return -1;
+ }
+ return ifc_set_hwaddr(name, addr->ether_addr_octet);
+}
+
struct
{
const char *name;
@@ -97,6 +98,7 @@ struct
{ "down", 1, ifc_down },
{ "flhosts", 1, ifc_remove_host_routes },
{ "deldefault", 1, ifc_remove_default_route },
+ { "hwaddr", 2, set_hwaddr },
{ 0, 0, 0 },
};