Skip to content

Commit

Permalink
am 4966600: am 6ee3ecc: Decode DHCP netmask option correctly
Browse files Browse the repository at this point in the history
* commit '49666005b22519ddd628d7bd262b778d130d6e8b':
  Decode DHCP netmask option correctly
  • Loading branch information
chrisdearman authored and Android Git Automerger committed Aug 8, 2012
2 parents 34af360 + 4966600 commit 9303398
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion libnetutils/dhcpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions libnetutils/ifc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 9303398

Please sign in to comment.