--- embedaddon/miniupnpd/getifaddr.c 2012/05/29 12:55:57 1.1.1.2 +++ embedaddon/miniupnpd/getifaddr.c 2013/07/22 00:32:35 1.1.1.3 @@ -1,7 +1,7 @@ -/* $Id: getifaddr.c,v 1.1.1.2 2012/05/29 12:55:57 misho Exp $ */ +/* $Id: getifaddr.c,v 1.1.1.3 2013/07/22 00:32:35 misho Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2011 Thomas Bernard + * (c) 2006-2011 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include #if defined(sun) #include #endif @@ -74,9 +74,11 @@ getifaddr(const char * ifname, char * buf, int len) } for(ife = ifap; ife; ife = ife->ifa_next) { - /* skip other interfaces */ - if(0 != strcmp(ifname, ife->ifa_name)) + /* skip other interfaces if one was specified */ + if(ifname && (0 != strcmp(ifname, ife->ifa_name))) continue; + if(ife->ifa_addr == NULL) + continue; switch(ife->ifa_addr->sa_family) { case AF_INET: @@ -121,6 +123,8 @@ find_ipv6_addr(const char * ifname, /* skip other interfaces if one was specified */ if(ifname && (0 != strcmp(ifname, ife->ifa_name))) continue; + if(ife->ifa_addr == NULL) + continue; if(ife->ifa_addr->sa_family == AF_INET6) { addr = (const struct sockaddr_in6 *)ife->ifa_addr; @@ -136,6 +140,7 @@ find_ipv6_addr(const char * ifname, } } } + freeifaddrs(ifap); return r; } #endif