Use inet_aton() instead of inet_addr() as it allows us to distinguish

between the address (or mask 255.255.255.255) and an error.  In the
future we may consider switching to inet_pton() for IPv4 too.
This commit is contained in:
Todd C. Miller
2014-01-26 13:23:09 -07:00
parent 7e008eb677
commit aaecd326e4
4 changed files with 54 additions and 64 deletions

View File

@@ -87,10 +87,8 @@ set_interfaces(const char *ai)
} else {
/* IPv4 */
ifp->family = AF_INET;
ifp->addr.ip4.s_addr = inet_addr(addr);
ifp->netmask.ip4.s_addr = inet_addr(mask);
if (ifp->addr.ip4.s_addr == INADDR_NONE ||
ifp->netmask.ip4.s_addr == INADDR_NONE) {
if (inet_aton(addr, &ifp->addr.ip4) != 1 ||
inet_aton(mask, &ifp->netmask.ip4) != 1) {
efree(ifp);
continue;
}