am 8076b212: Merge "Decode DHCP netmask option correctly"

* commit '8076b212574afe39ed6152ddf88a3c8c63b0c87c':
  Decode DHCP netmask option correctly
This commit is contained in:
Jean-Baptiste Queru 2012-08-09 11:39:58 -07:00 committed by Android Git Automerger
commit 5f6d2529bb
2 changed files with 7 additions and 4 deletions

View file

@ -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);

View file

@ -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);
}
}