diff options
author | Chris Dearman <chris@mips.com> | 2011-06-17 17:07:46 -0700 |
---|---|---|
committer | Dmitry Shmidt <dimitrysh@google.com> | 2012-08-08 15:50:03 -0700 |
commit | 6ee3ecc03a7cf9118e6a0b2577f15c76244bc408 (patch) | |
tree | 2bc6d882fe24ba7ec4cca5db72068fa41fa914d5 /libnetutils | |
parent | ff5c802e6ce489a36ac28e3d93b7e8541b3e4d81 (diff) | |
download | system_core-6ee3ecc03a7cf9118e6a0b2577f15c76244bc408.zip system_core-6ee3ecc03a7cf9118e6a0b2577f15c76244bc408.tar.gz system_core-6ee3ecc03a7cf9118e6a0b2577f15c76244bc408.tar.bz2 |
Decode DHCP netmask option correctly
Signed-off-by: Chris Dearman <chris@mips.com>
Change-Id: Ibc288458baf2f75c5b19a46e4c97ee59521cc9a5
Diffstat (limited to 'libnetutils')
-rw-r--r-- | libnetutils/dhcpclient.c | 6 | ||||
-rw-r--r-- | libnetutils/ifc_utils.c | 5 |
2 files changed, 7 insertions, 4 deletions
diff --git a/libnetutils/dhcpclient.c b/libnetutils/dhcpclient.c index b38e258..34500e7 100644 --- a/libnetutils/dhcpclient.c +++ b/libnetutils/dhcpclient.c @@ -197,7 +197,11 @@ int decode_dhcp_msg(dhcp_msg *msg, int len, dhcp_info *info) } switch(opt) { case OPT_SUBNET_MASK: - if (optlen >= 4) info->prefixLength = ipv4NetmaskToPrefixLength(*((uint32_t*)x)); + if (optlen >= 4) { + in_addr_t mask; + memcpy(&mask, x, 4); + info->prefixLength = ipv4NetmaskToPrefixLength(mask); + } break; case OPT_GATEWAY: if (optlen >= 4) memcpy(&info->gateway, x, 4); diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index 50095ab..eb33d06 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c @@ -75,9 +75,8 @@ in_addr_t prefixLengthToIpv4Netmask(int prefix_length) int ipv4NetmaskToPrefixLength(in_addr_t mask) { - mask = ntohl(mask); int prefixLength = 0; - uint32_t m = (uint32_t)mask; + uint32_t m = (uint32_t)ntohl(mask); while (m & 0x80000000) { prefixLength++; m = m << 1; @@ -486,7 +485,7 @@ int ifc_get_info(const char *name, in_addr_t *addr, int *prefixLength, unsigned if(ioctl(ifc_ctl_sock, SIOCGIFNETMASK, &ifr) < 0) { *prefixLength = 0; } else { - *prefixLength = ipv4NetmaskToPrefixLength((int) + *prefixLength = ipv4NetmaskToPrefixLength( ((struct sockaddr_in*) &ifr.ifr_addr)->sin_addr.s_addr); } } |