miniupnpd/getifaddr.c: check if interface is up

This commit is contained in:
Thomas Bernard 2014-04-11 00:03:13 +02:00
parent 29e951c1e5
commit f789a3bab7
1 changed files with 13 additions and 0 deletions

View File

@ -47,6 +47,19 @@ getifaddr(const char * ifname, char * buf, int len,
return -1;
}
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
if(ioctl(s, SIOCGIFFLAGS, &ifr, &ifrlen) < 0)
{
syslog(LOG_DEBUG, "ioctl(s, SIOCGIFFLAGS, ...): %m");
close(s);
return -1;
}
if ((ifr.ifr_flags & IFF_UP) == 0)
{
syslog(LOG_DEBUG, "network interface %s is down", ifname);
close(s);
return -1;
}
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
if(ioctl(s, SIOCGIFADDR, &ifr, &ifrlen) < 0)
{
syslog(LOG_ERR, "ioctl(s, SIOCGIFADDR, ...): %m");