fix getifaddr() error case

see #670
This commit is contained in:
Thomas Bernard 2023-11-14 21:15:58 +01:00
parent fb5c328a5e
commit 096478dce1
1 changed files with 7 additions and 1 deletions

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2022 Thomas Bernard
* (c) 2006-2023 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -148,6 +148,12 @@ getifaddr(const char * ifname, char * buf, int len,
if(addr) *addr = ((struct sockaddr_in *)candidate->ifa_addr)->sin_addr;
if(mask) *mask = ((struct sockaddr_in *)candidate->ifa_netmask)->sin_addr;
}
else
{
syslog(LOG_WARNING, "no AF_INET address found for %s", ifname);
freeifaddrs(ifap);
return -1;
}
freeifaddrs(ifap);
#endif
return 0;