From f789a3bab755850d22335f292766ea9c051ed45b Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 11 Apr 2014 00:03:13 +0200 Subject: [PATCH] miniupnpd/getifaddr.c: check if interface is up --- miniupnpd/getifaddr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/miniupnpd/getifaddr.c b/miniupnpd/getifaddr.c index be57050..f9e2c6d 100644 --- a/miniupnpd/getifaddr.c +++ b/miniupnpd/getifaddr.c @@ -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");