miniupnpd/getifaddr.c: fix getifaddr_in6()

-1 is returned if no address is found
This commit is contained in:
Thomas Bernard 2014-03-13 09:56:34 +01:00
parent 081c46338c
commit d397d73628
1 changed files with 3 additions and 6 deletions

View File

@ -122,6 +122,7 @@ getifaddr(const char * ifname, char * buf, int len,
int getifaddr_in6(const char * ifname, struct in6_addr * addr){ int getifaddr_in6(const char * ifname, struct in6_addr * addr){
struct ifaddrs * ifap; struct ifaddrs * ifap;
struct ifaddrs * ife; struct ifaddrs * ife;
int found = 0;
if(!ifname || ifname[0]=='\0') if(!ifname || ifname[0]=='\0')
return -1; return -1;
@ -130,9 +131,8 @@ int getifaddr_in6(const char * ifname, struct in6_addr * addr){
syslog(LOG_ERR, "getifaddrs: %m"); syslog(LOG_ERR, "getifaddrs: %m");
return -1; return -1;
} }
for(ife = ifap; ife; ife = ife->ifa_next) for(ife = ifap; ife && !found; ife = ife->ifa_next)
{ {
int found = 0;
/* skip other interfaces if one was specified */ /* skip other interfaces if one was specified */
if(ifname && (0 != strcmp(ifname, ife->ifa_name))) if(ifname && (0 != strcmp(ifname, ife->ifa_name)))
continue; continue;
@ -165,12 +165,9 @@ int getifaddr_in6(const char * ifname, struct in6_addr * addr){
} }
break; break;
} }
if (found) {
break;
}
} }
freeifaddrs(ifap); freeifaddrs(ifap);
return 0; return (found ? 0 : -1);
} }
#endif #endif