From 2af699ea51cca49bd0f19080c9d73170e5bdadbc Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Mon, 23 Jul 2012 15:59:31 -0700 Subject: Fix netmask retrival from ifc_get_info() Change-Id: I67b06887a72869d48e0c6c2fcacf8c99153d7f82 Signed-off-by: Dmitry Shmidt --- ifaddrs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ifaddrs.c b/ifaddrs.c index cb8fd76..0554ee7 100644 --- a/ifaddrs.c +++ b/ifaddrs.c @@ -32,14 +32,15 @@ struct ifaddrs *get_interface(const char *name, sa_family_t family) { - unsigned addr, mask, flags; + unsigned addr, flags; + int masklen; struct ifaddrs *ifa; struct sockaddr_in *saddr = NULL; struct sockaddr_in *smask = NULL; struct sockaddr_ll *hwaddr = NULL; unsigned char hwbuf[ETH_ALEN]; - if(ifc_get_info(name, &addr, &mask, &flags)) + if (ifc_get_info(name, &addr, &masklen, &flags)) return NULL; if ((family == AF_INET) && (addr == 0)) @@ -66,10 +67,10 @@ struct ifaddrs *get_interface(const char *name, sa_family_t family) } ifa->ifa_addr = (struct sockaddr *)saddr; - if (mask != 0) { + if (masklen != 0) { smask = malloc(sizeof(struct sockaddr_in)); if (smask) { - smask->sin_addr.s_addr = mask; + smask->sin_addr.s_addr = prefixLengthToIpv4Netmask(masklen); smask->sin_family = family; } } -- cgit v1.1