diff options
author | Szymon Jakubczak <szym@google.com> | 2010-06-09 16:11:09 -0400 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2010-08-25 08:13:42 -0700 |
commit | 8c85a00db6da092ec3766facd49132fa4fc319a1 (patch) | |
tree | 4d7015b3de6955bb0ef9b10efeef039fd9e0a542 /libnetutils/dhcpclient.c | |
parent | 2c72df998799738662a77cef3f522fdc6ae22fde (diff) | |
download | core-8c85a00db6da092ec3766facd49132fa4fc319a1.tar.gz core-8c85a00db6da092ec3766facd49132fa4fc319a1.tar.bz2 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 'libnetutils/dhcpclient.c')
-rw-r--r-- | libnetutils/dhcpclient.c | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/libnetutils/dhcpclient.c b/libnetutils/dhcpclient.c index 6755ba1f6..ff00432b6 100644 --- a/libnetutils/dhcpclient.c +++ b/libnetutils/dhcpclient.c @@ -36,8 +36,8 @@ #include <dirent.h> +#include <netutils/ifc.h> #include "dhcpmsg.h" -#include "ifc_utils.h" #include "packet.h" #define VERBOSE 2 @@ -85,16 +85,12 @@ int fatal(const char *reason) // exit(1); } -const char *ipaddr(uint32_t 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); } typedef struct dhcp_info dhcp_info; @@ -128,31 +124,11 @@ void get_dhcp_info(uint32_t *ipaddr, uint32_t *gateway, uint32_t *mask, *lease = last_good_info.lease; } -static int ifc_configure(const char *ifname, dhcp_info *info) +static int dhcp_configure(const char *ifname, dhcp_info *info) { - char dns_prop_name[PROPERTY_KEY_MAX]; - - if (ifc_set_addr(ifname, info->ipaddr)) { - printerr("failed to set ipaddr %s: %s\n", ipaddr(info->ipaddr), strerror(errno)); - return -1; - } - if (ifc_set_mask(ifname, info->netmask)) { - printerr("failed to set netmask %s: %s\n", ipaddr(info->netmask), strerror(errno)); - return -1; - } - if (ifc_create_default_route(ifname, info->gateway)) { - printerr("failed to set default route %s: %s\n", ipaddr(info->gateway), strerror(errno)); - return -1; - } - - snprintf(dns_prop_name, sizeof(dns_prop_name), "net.%s.dns1", ifname); - property_set(dns_prop_name, info->dns1 ? ipaddr(info->dns1) : ""); - snprintf(dns_prop_name, sizeof(dns_prop_name), "net.%s.dns2", ifname); - property_set(dns_prop_name, info->dns2 ? ipaddr(info->dns2) : ""); - last_good_info = *info; - - return 0; + return ifc_configure(ifname, info->ipaddr, info->netmask, info->gateway, + info->dns1, info->dns2); } static const char *dhcp_type_to_name(uint32_t type) @@ -449,7 +425,7 @@ int dhcp_init_ifc(const char *ifname) printerr("timed out\n"); if ( info.type == DHCPOFFER ) { printerr("no acknowledgement from DHCP server\nconfiguring %s with offered parameters\n", ifname); - return ifc_configure(ifname, &info); + return dhcp_configure(ifname, &info); } errno = ETIME; close(s); @@ -530,7 +506,7 @@ int dhcp_init_ifc(const char *ifname) if (info.type == DHCPACK) { printerr("configuring %s\n", ifname); close(s); - return ifc_configure(ifname, &info); + return dhcp_configure(ifname, &info); } else if (info.type == DHCPNAK) { printerr("configuration request denied\n"); close(s); |