--- a/src/network.c
+++ b/src/network.c
@@ -4,12 +4,12 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 dated June, 1991, or
    (at your option) version 3 dated 29 June, 2007.
- 
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-     
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -21,7 +21,7 @@
 int indextoname(int fd, int index, char *name)
 {
   struct ifreq ifr;
-  
+
   if (index == 0)
     return 0;
 
@@ -50,42 +50,42 @@ int indextoname(int fd, int index, char
   int numifs, bufsize, i;
   struct lifconf lifc;
   struct lifreq *lifrp;
-  
+
   if (index == 0)
     return 0;
-  
-  if (getzoneid() == GLOBAL_ZONEID) 
+
+  if (getzoneid() == GLOBAL_ZONEID)
     {
       if (!if_indextoname(index, name))
 	return 0;
       return 1;
     }
-  
+
   lifc_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES | LIFC_UNDER_IPMP;
   lifn.lifn_family = AF_UNSPEC;
   lifn.lifn_flags = lifc_flags;
-  if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0) 
+  if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0)
     return 0;
-  
+
   numifs = lifn.lifn_count;
   bufsize = numifs * sizeof(struct lifreq);
-  
+
   lifc.lifc_family = AF_UNSPEC;
   lifc.lifc_flags = lifc_flags;
   lifc.lifc_len = bufsize;
   lifc.lifc_buf = alloca(bufsize);
-  
-  if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)  
+
+  if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)
     return 0;
-  
+
   lifrp = lifc.lifc_req;
-  for (i = lifc.lifc_len / sizeof(struct lifreq); i; i--, lifrp++) 
+  for (i = lifc.lifc_len / sizeof(struct lifreq); i; i--, lifrp++)
     {
       struct lifreq lifr;
       strncpy(lifr.lifr_name, lifrp->lifr_name, IF_NAMESIZE);
-      if (ioctl(fd, SIOCGLIFINDEX, &lifr) < 0) 
+      if (ioctl(fd, SIOCGLIFINDEX, &lifr) < 0)
 	return 0;
-      
+
       if (lifr.lifr_index == index) {
 	strncpy(name, lifr.lifr_name, IF_NAMESIZE);
 	return 1;
@@ -98,7 +98,7 @@ int indextoname(int fd, int index, char
 #else
 
 int indextoname(int fd, int index, char *name)
-{ 
+{
   (void)fd;
 
   if (index == 0 || !if_indextoname(index, name))
@@ -118,10 +118,10 @@ int iface_check(int family, struct all_a
      "used" flags.
 
      May be called with family == AF_LOCALto check interface by name only. */
-  
+
   if (auth)
     *auth = 0;
-  
+
   if (daemon->if_names || daemon->if_addrs)
     {
       ret = 0;
@@ -129,7 +129,7 @@ int iface_check(int family, struct all_a
       for (tmp = daemon->if_names; tmp; tmp = tmp->next)
 	if (tmp->name && wildcard_match(tmp->name, name))
 	  ret = tmp->used = 1;
-	        
+
       if (addr)
 	for (tmp = daemon->if_addrs; tmp; tmp = tmp->next)
 	  if (tmp->addr.sa.sa_family == family)
@@ -139,18 +139,18 @@ int iface_check(int family, struct all_a
 		ret = match_addr = tmp->used = 1;
 #ifdef HAVE_IPV6
 	      else if (family == AF_INET6 &&
-		       IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr, 
+		       IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr,
 					  &addr->addr.addr6))
 		ret = match_addr = tmp->used = 1;
 #endif
-	    }          
+	    }
     }
-  
+
   if (!match_addr)
     for (tmp = daemon->if_except; tmp; tmp = tmp->next)
       if (tmp->name && wildcard_match(tmp->name, name))
 	ret = 0;
-    
+
 
   for (tmp = daemon->authinterface; tmp; tmp = tmp->next)
     if (tmp->name)
@@ -166,24 +166,24 @@ int iface_check(int family, struct all_a
     else if (addr && tmp->addr.sa.sa_family == AF_INET6 && family == AF_INET6 &&
 	     IN6_ARE_ADDR_EQUAL(&tmp->addr.in6.sin6_addr, &addr->addr.addr6))
       break;
-#endif      
+#endif
 
-  if (tmp && auth) 
+  if (tmp && auth)
     {
       *auth = 1;
       ret = 1;
     }
 
-  return ret; 
+  return ret;
 }
 
 
 /* Fix for problem that the kernel sometimes reports the loopback inerface as the
-   arrival interface when a packet originates locally, even when sent to address of 
-   an interface other than the loopback. Accept packet if it arrived via a loopback 
+   arrival interface when a packet originates locally, even when sent to address of
+   an interface other than the loopback. Accept packet if it arrived via a loopback
    interface, even when we're not accepting packets that way, as long as the destination
    address is one we're believing. Interface list must be up-to-date before calling. */
-int loopback_exception(int fd, int family, struct all_addr *addr, char *name)    
+int loopback_exception(int fd, int family, struct all_addr *addr, char *name)
 {
   struct ifreq ifr;
   struct irec *iface;
@@ -204,7 +204,7 @@ int loopback_exception(int fd, int famil
 	    else if (IN6_ARE_ADDR_EQUAL(&iface->addr.in6.sin6_addr, &addr->addr.addr6))
 	      return 1;
 #endif
-	    
+
 	  }
     }
   return 0;
@@ -212,7 +212,7 @@ int loopback_exception(int fd, int famil
 
 /* If we're configured with something like --interface=eth0:0 then we'll listen correctly
    on the relevant address, but the name of the arrival interface, derived from the
-   index won't match the config. Check that we found an interface address for the arrival 
+   index won't match the config. Check that we found an interface address for the arrival
    interface: daemon->interfaces must be up-to-date. */
 int label_exception(int index, int family, struct all_addr *addr)
 {
@@ -236,7 +236,7 @@ struct iface_param {
 };
 
 static int iface_allowed(struct iface_param *param, int if_index, char *label,
-			 union mysockaddr *addr, struct in_addr netmask, int prefixlen, int iface_flags) 
+			 union mysockaddr *addr, struct in_addr netmask, int prefixlen, int iface_flags)
 {
   struct irec *iface;
   int mtu = 0, loopback;
@@ -253,18 +253,18 @@ static int iface_allowed(struct iface_pa
   if (!indextoname(param->fd, if_index, ifr.ifr_name) ||
       ioctl(param->fd, SIOCGIFFLAGS, &ifr) == -1)
     return 0;
-   
+
   loopback = ifr.ifr_flags & IFF_LOOPBACK;
-  
+
   if (loopback)
     dhcp_ok = 0;
-  
+
   if (ioctl(param->fd, SIOCGIFMTU, &ifr) != -1)
     mtu = ifr.ifr_mtu;
-  
+
   if (!label)
     label = ifr.ifr_name;
- 
+
   /* maintain a list of all addresses on all interfaces for --local-service option */
   if (option_bool(OPT_LOCAL_SERVICE))
     {
@@ -277,13 +277,13 @@ static int iface_allowed(struct iface_pa
 	}
       else
 	al = whine_malloc(sizeof(struct addrlist));
-      
+
       if (al)
 	{
 	  al->next = daemon->interface_addrs;
 	  daemon->interface_addrs = al;
 	  al->prefixlen = prefixlen;
-	  
+
 	  if (addr->sa.sa_family == AF_INET)
 	    {
 	      al->addr.addr.addr4 = addr->in.sin_addr;
@@ -294,11 +294,11 @@ static int iface_allowed(struct iface_pa
 	    {
 	      al->addr.addr.addr6 = addr->in6.sin6_addr;
 	      al->flags = ADDRLIST_IPV6;
-	    } 
+	    }
 #endif
 	}
     }
-  
+
 #ifdef HAVE_IPV6
   if (addr->sa.sa_family != AF_INET6 || !IN6_IS_ADDR_LINKLOCAL(&addr->in6.sin6_addr))
 #endif
@@ -323,7 +323,7 @@ static int iface_allowed(struct iface_pa
 		    }
 		  else
 		    al = whine_malloc(sizeof(struct addrlist));
-		  
+
 		  if (al)
 		    {
 		      al->next = zone->subnet;
@@ -333,7 +333,7 @@ static int iface_allowed(struct iface_pa
 		      al->flags = 0;
 		    }
 		}
-	      
+
 #ifdef HAVE_IPV6
 	      if (addr->sa.sa_family == AF_INET6 && (name->flags & AUTH6))
 		{
@@ -344,7 +344,7 @@ static int iface_allowed(struct iface_pa
 		    }
 		  else
 		    al = whine_malloc(sizeof(struct addrlist));
-		  
+
 		  if (al)
 		    {
 		      al->next = zone->subnet;
@@ -353,16 +353,16 @@ static int iface_allowed(struct iface_pa
 		      al->addr.addr.addr6 = addr->in6.sin6_addr;
 		      al->flags = ADDRLIST_IPV6;
 		    }
-		} 
+		}
 #endif
-	      
+
 	    }
 #endif
-       
+
       /* Update addresses from interface_names. These are a set independent
-	 of the set we're listening on. */  
+	 of the set we're listening on. */
       for (int_name = daemon->int_names; int_name; int_name = int_name->next)
-	if (strncmp(label, int_name->intr, IF_NAMESIZE) == 0 && 
+	if (strncmp(label, int_name->intr, IF_NAMESIZE) == 0 &&
 	    (addr->sa.sa_family == int_name->family || int_name->family == 0))
 	  {
 	    if (param->spare)
@@ -372,12 +372,12 @@ static int iface_allowed(struct iface_pa
 	      }
 	    else
 	      al = whine_malloc(sizeof(struct addrlist));
-	    
+
 	    if (al)
 	      {
 		al->next = int_name->addr;
 		int_name->addr = al;
-		
+
 		if (addr->sa.sa_family == AF_INET)
 		  {
 		    al->addr.addr.addr4 = addr->in.sin_addr;
@@ -392,15 +392,15 @@ static int iface_allowed(struct iface_pa
 		       don't appear in forward queries, but will in reverse ones. */
 		    if (!(iface_flags & IFACE_PERMANENT) || (iface_flags & (IFACE_DEPRECATED | IFACE_TENTATIVE)))
 		      al->flags |= ADDRLIST_REVONLY;
-		 } 
+		 }
 #endif
 	      }
 	  }
     }
- 
-  /* check whether the interface IP has been added already 
+
+  /* check whether the interface IP has been added already
      we call this routine multiple times. */
-  for (iface = daemon->interfaces; iface; iface = iface->next) 
+  for (iface = daemon->interfaces; iface; iface = iface->next)
     if (sockaddr_isequal(&iface->addr, addr))
       {
 	iface->dad = !!(iface_flags & IFACE_TENTATIVE);
@@ -416,8 +416,8 @@ static int iface_allowed(struct iface_pa
       for (lo = daemon->if_names; lo; lo = lo->next)
 	if (lo->name && strcmp(lo->name, ifr.ifr_name) == 0)
 	  break;
-      
-      if (!lo && (lo = whine_malloc(sizeof(struct iname)))) 
+
+      if (!lo && (lo = whine_malloc(sizeof(struct iname))))
 	{
 	  if ((lo->name = whine_malloc(strlen(ifr.ifr_name)+1)))
 	    {
@@ -430,7 +430,7 @@ static int iface_allowed(struct iface_pa
 	    free(lo);
 	}
     }
-  
+
   if (addr->sa.sa_family == AF_INET &&
       !iface_check(AF_INET, (struct all_addr *)&addr->in.sin_addr, label, &auth_dns))
     return 1;
@@ -440,7 +440,7 @@ static int iface_allowed(struct iface_pa
       !iface_check(AF_INET6, (struct all_addr *)&addr->in6.sin6_addr, label, &auth_dns))
     return 1;
 #endif
-    
+
 #ifdef HAVE_DHCP
   /* No DHCP where we're doing auth DNS. */
   if (auth_dns)
@@ -456,8 +456,8 @@ static int iface_allowed(struct iface_pa
 	  dhcp_ok = 0;
 	}
 #endif
- 
-  
+
+
 #ifdef HAVE_TFTP
   if (daemon->tftp_interfaces)
     {
@@ -468,7 +468,7 @@ static int iface_allowed(struct iface_pa
 	  tftp_ok = 1;
     }
 #endif
-  
+
   /* add to list */
   if ((iface = whine_malloc(sizeof(struct irec))))
     {
@@ -492,14 +492,14 @@ static int iface_allowed(struct iface_pa
       free(iface);
 
     }
-  
-  errno = ENOMEM; 
+
+  errno = ENOMEM;
   return 0;
 }
 
 #ifdef HAVE_IPV6
-static int iface_allowed_v6(struct in6_addr *local, int prefix, 
-			    int scope, int if_index, int flags, 
+static int iface_allowed_v6(struct in6_addr *local, int prefix,
+			    int scope, int if_index, int flags,
 			    int preferred, int valid, void *vparam)
 {
   union mysockaddr addr;
@@ -509,7 +509,7 @@ static int iface_allowed_v6(struct in6_a
   (void)scope; /* warning */
   (void)preferred;
   (void)valid;
-  
+
   memset(&addr, 0, sizeof(addr));
 #ifdef HAVE_SOCKADDR_SA_LEN
   addr.in6.sin6_len = sizeof(addr.in6);
@@ -522,7 +522,7 @@ static int iface_allowed_v6(struct in6_a
     addr.in6.sin6_scope_id = if_index;
   else
     addr.in6.sin6_scope_id = 0;
-  
+
   return iface_allowed((struct iface_param *)vparam, if_index, NULL, &addr, netmask, prefix, flags);
 }
 #endif
@@ -547,7 +547,7 @@ static int iface_allowed_v4(struct in_ad
 
   return iface_allowed((struct iface_param *)vparam, if_index, label, &addr, netmask, prefix, 0);
 }
-   
+
 int enumerate_interfaces(int reset)
 {
   static struct addrlist *spare = NULL;
@@ -577,9 +577,9 @@ int enumerate_interfaces(int reset)
 
   if ((param.fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
     return 0;
- 
+
   /* Mark interfaces for garbage collection */
-  for (iface = daemon->interfaces; iface; iface = iface->next) 
+  for (iface = daemon->interfaces; iface; iface = iface->next)
     iface->found = 0;
 
   /* remove addresses stored against interface_names */
@@ -591,7 +591,7 @@ int enumerate_interfaces(int reset)
 	  addr->next = spare;
 	  spare = addr;
 	}
-      
+
       intname->addr = NULL;
     }
 
@@ -603,9 +603,9 @@ int enumerate_interfaces(int reset)
       spare = addr;
     }
   daemon->interface_addrs = NULL;
-  
+
 #ifdef HAVE_AUTH
-  /* remove addresses stored against auth_zone subnets, but not 
+  /* remove addresses stored against auth_zone subnets, but not
    ones configured as address literals */
   for (zone = daemon->auth_zones; zone; zone = zone->next)
     if (zone->interface_names)
@@ -627,55 +627,55 @@ int enumerate_interfaces(int reset)
 #endif
 
   param.spare = spare;
-  
+
 #ifdef HAVE_IPV6
   ret = iface_enumerate(AF_INET6, &param, iface_allowed_v6);
 #endif
 
   if (ret)
-    ret = iface_enumerate(AF_INET, &param, iface_allowed_v4); 
- 
+    ret = iface_enumerate(AF_INET, &param, iface_allowed_v4);
+
   errsave = errno;
   close(param.fd);
-  
+
   if (option_bool(OPT_CLEVERBIND))
-    { 
+    {
       /* Garbage-collect listeners listening on addresses that no longer exist.
-	 Does nothing when not binding interfaces or for listeners on localhost, 
+	 Does nothing when not binding interfaces or for listeners on localhost,
 	 since the ->iface field is NULL. Note that this needs the protections
 	 against re-entrancy, hence it's here.  It also means there's a possibility,
 	 in OPT_CLEVERBIND mode, that at listener will just disappear after
 	 a call to enumerate_interfaces, this is checked OK on all calls. */
       struct listener *l, *tmp, **up;
-      
+
       for (up = &daemon->listeners, l = daemon->listeners; l; l = tmp)
 	{
 	  tmp = l->next;
-	  
+
 	  if (!l->iface || l->iface->found)
 	    up = &l->next;
 	  else
 	    {
 	      *up = l->next;
-	      
+
 	      /* In case it ever returns */
 	      l->iface->done = 0;
-	      
+
 	      if (l->fd != -1)
 		close(l->fd);
 	      if (l->tcpfd != -1)
 		close(l->tcpfd);
 	      if (l->tftpfd != -1)
 		close(l->tftpfd);
-	      
+
 	      free(l);
 	    }
 	}
     }
-  
+
   errno = errsave;
   spare = param.spare;
-    
+
   return ret;
 }
 
@@ -687,7 +687,7 @@ int fix_fd(int fd)
   if ((flags = fcntl(fd, F_GETFL)) == -1 ||
       fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
     return 0;
-  
+
   return 1;
 }
 
@@ -695,7 +695,7 @@ static int make_sock(union mysockaddr *a
 {
   int family = addr->sa.sa_family;
   int fd, rc, opt = 1;
-  
+
   if ((fd = socket(family, type, 0)) == -1)
     {
       int port, errsav;
@@ -706,17 +706,17 @@ static int make_sock(union mysockaddr *a
 	  errno == EAFNOSUPPORT ||
 	  errno == EINVAL)
 	return -1;
-      
+
     err:
       errsav = errno;
       port = prettyprint_addr(addr, daemon->addrbuff);
       if (!option_bool(OPT_NOWILD) && !option_bool(OPT_CLEVERBIND))
 	sprintf(daemon->addrbuff, "port %d", port);
       s = _("failed to create listening socket for %s: %s");
-      
+
       if (fd != -1)
 	close (fd);
-	
+
       errno = errsav;
 
       if (dienow)
@@ -728,21 +728,21 @@ static int make_sock(union mysockaddr *a
 	}
       else
 	my_syslog(LOG_WARNING, s, daemon->addrbuff, strerror(errno));
-      
+
       return -1;
-    }	
-  
+    }
+
   if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 || !fix_fd(fd))
     goto err;
-  
+
 #ifdef HAVE_IPV6
   if (family == AF_INET6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)) == -1)
     goto err;
 #endif
-  
+
   if ((rc = bind(fd, (struct sockaddr *)addr, sa_len(addr))) == -1)
     goto err;
-  
+
   if (type == SOCK_STREAM)
     {
       if (listen(fd, 5) == -1)
@@ -752,7 +752,7 @@ static int make_sock(union mysockaddr *a
     {
       if (!option_bool(OPT_NOWILD))
 	{
-#if defined(HAVE_LINUX_NETWORK) 
+#if defined(HAVE_LINUX_NETWORK)
 	  if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)) == -1)
 	    goto err;
 #elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
@@ -766,11 +766,11 @@ static int make_sock(union mysockaddr *a
   else if (!set_ipv6pktinfo(fd))
     goto err;
 #endif
-  
+
   return fd;
 }
 
-#ifdef HAVE_IPV6  
+#ifdef HAVE_IPV6
 int set_ipv6pktinfo(int fd)
 {
   int opt = 1;
@@ -779,7 +779,7 @@ int set_ipv6pktinfo(int fd)
      handle all combinations of headers and kernel.
      OpenWrt note that this fixes the problem addressed by your very broken patch. */
   daemon->v6pktinfo = IPV6_PKTINFO;
-  
+
 #ifdef IPV6_RECVPKTINFO
   if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &opt, sizeof(opt)) != -1)
     return 1;
@@ -789,7 +789,7 @@ int set_ipv6pktinfo(int fd)
       daemon->v6pktinfo = IPV6_2292PKTINFO;
       return 1;
     }
-# endif 
+# endif
 #else
   if (setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &opt, sizeof(opt)) != -1)
     return 1;
@@ -802,21 +802,21 @@ int set_ipv6pktinfo(int fd)
 
 /* Find the interface on which a TCP connection arrived, if possible, or zero otherwise. */
 int tcp_interface(int fd, int af)
-{ 
+{
   int if_index = 0;
 
 #ifdef HAVE_LINUX_NETWORK
   int opt = 1;
   struct cmsghdr *cmptr;
   struct msghdr msg;
-  
+
   /* use mshdr do that the CMSDG_* macros are available */
   msg.msg_control = daemon->packet;
   msg.msg_controllen = daemon->packet_buff_sz;
-  
+
   /* we overwrote the buffer... */
   daemon->srv_save = NULL;
-  
+
   if (af == AF_INET)
     {
       if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)) != -1 &&
@@ -828,7 +828,7 @@ int tcp_interface(int fd, int af)
                 unsigned char *c;
                 struct in_pktinfo *p;
               } p;
-	      
+
 	      p.c = CMSG_DATA(cmptr);
 	      if_index = p.p->ipi_ifindex;
 	    }
@@ -837,12 +837,12 @@ int tcp_interface(int fd, int af)
   else
     {
       /* Only the RFC-2292 API has the ability to find the interface for TCP connections,
-	 it was removed in RFC-3542 !!!! 
+	 it was removed in RFC-3542 !!!!
 
 	 Fortunately, Linux kept the 2292 ABI when it moved to 3542. The following code always
 	 uses the old ABI, and should work with pre- and post-3542 kernel headers */
 
-#ifdef IPV6_2292PKTOPTIONS   
+#ifdef IPV6_2292PKTOPTIONS
 #  define PKTOPTIONS IPV6_2292PKTOPTIONS
 #else
 #  define PKTOPTIONS IPV6_PKTOPTIONS
@@ -859,17 +859,17 @@ int tcp_interface(int fd, int af)
                   struct in6_pktinfo *p;
                 } p;
                 p.c = CMSG_DATA(cmptr);
-		
+
 		if_index = p.p->ipi6_ifindex;
               }
 	}
     }
 #endif /* IPV6 */
 #endif /* Linux */
- 
+
   return if_index;
 }
-      
+
 static struct listener *create_listeners(union mysockaddr *addr, int do_tftp, int dienow)
 {
   struct listener *l = NULL;
@@ -882,7 +882,7 @@ static struct listener *create_listeners
       fd = make_sock(addr, SOCK_DGRAM, dienow);
       tcpfd = make_sock(addr, SOCK_STREAM, dienow);
     }
-  
+
 #ifdef HAVE_TFTP
   if (do_tftp)
     {
@@ -901,7 +901,7 @@ static struct listener *create_listeners
 	  addr->in6.sin6_port = htons(TFTP_PORT);
 	  tftpfd = make_sock(addr, SOCK_DGRAM, dienow);
 	  addr->in6.sin6_port = save;
-	}  
+	}
 #  endif
     }
 #endif
@@ -913,7 +913,7 @@ static struct listener *create_listeners
       l->family = addr->sa.sa_family;
       l->fd = fd;
       l->tcpfd = tcpfd;
-      l->tftpfd = tftpfd;	
+      l->tftpfd = tftpfd;
       l->iface = NULL;
     }
 
@@ -943,11 +943,11 @@ void create_wildcard_listeners(void)
   addr.in6.sin6_family = AF_INET6;
   addr.in6.sin6_addr = in6addr_any;
   addr.in6.sin6_port = htons(daemon->port);
- 
+
   l6 = create_listeners(&addr, !!option_bool(OPT_TFTP), 1);
-  if (l) 
+  if (l)
     l->next = l6;
-  else 
+  else
     l = l6;
 #endif
 
@@ -974,7 +974,7 @@ void create_bound_listeners(int dienow)
      no interface with a matching address. These may be valid: eg it's possible
      to listen on 127.0.1.1 even if the loopback interface is 127.0.0.1
 
-     If the address isn't valid the bind() will fail and we'll die() 
+     If the address isn't valid the bind() will fail and we'll die()
      (except in bind-dynamic mode, when we'll complain but keep trying.)
 
      The resulting listeners have the ->iface field NULL, and this has to be
@@ -982,7 +982,7 @@ void create_bound_listeners(int dienow)
      (no netmask) and some MTU login the tftp code. */
 
   for (if_tmp = daemon->if_addrs; if_tmp; if_tmp = if_tmp->next)
-    if (!if_tmp->used && 
+    if (!if_tmp->used &&
 	(new = create_listeners(&if_tmp->addr, !!option_bool(OPT_TFTP), dienow)))
       {
 	new->next = daemon->listeners;
@@ -990,10 +990,10 @@ void create_bound_listeners(int dienow)
       }
 }
 
-/* In --bind-interfaces, the only access control is the addresses we're listening on. 
+/* In --bind-interfaces, the only access control is the addresses we're listening on.
    There's nothing to avoid a query to the address of an internal interface arriving via
-   an external interface where we don't want to accept queries, except that in the usual 
-   case the addresses of internal interfaces are RFC1918. When bind-interfaces in use, 
+   an external interface where we don't want to accept queries, except that in the usual
+   case the addresses of internal interfaces are RFC1918. When bind-interfaces in use,
    and we listen on an address that looks like it's probably globally routeable, shout.
 
    The fix is to use --bind-dynamic, which actually checks the arrival interface too.
@@ -1005,7 +1005,7 @@ void create_bound_listeners(int dienow)
 
 void warn_bound_listeners(void)
 {
-  struct irec *iface; 	
+  struct irec *iface;
   int advice = 0;
 
   for (iface = daemon->interfaces; iface; iface = iface->next)
@@ -1017,79 +1017,79 @@ void warn_bound_listeners(void)
 	      {
 		inet_ntop(AF_INET, &iface->addr.in.sin_addr, daemon->addrbuff, ADDRSTRLEN);
 		iface->warned = advice = 1;
-		my_syslog(LOG_WARNING, 
+		my_syslog(LOG_WARNING,
 			  _("LOUD WARNING: listening on %s may accept requests via interfaces other than %s"),
 			  daemon->addrbuff, iface->name);
 	      }
 	  }
       }
-  
+
   if (advice)
-    my_syslog(LOG_WARNING, _("LOUD WARNING: use --bind-dynamic rather than --bind-interfaces to avoid DNS amplification attacks via these interface(s)")); 
+    my_syslog(LOG_WARNING, _("LOUD WARNING: use --bind-dynamic rather than --bind-interfaces to avoid DNS amplification attacks via these interface(s)"));
 }
 
 void warn_int_names(void)
 {
   struct interface_name *intname;
- 
+
   for (intname = daemon->int_names; intname; intname = intname->next)
     if (!intname->addr)
       my_syslog(LOG_WARNING, _("warning: no addresses found for interface %s"), intname->intr);
 }
- 
+
 int is_dad_listeners(void)
 {
   struct irec *iface;
-  
+
   if (option_bool(OPT_NOWILD))
     for (iface = daemon->interfaces; iface; iface = iface->next)
       if (iface->dad && !iface->done)
 	return 1;
-  
+
   return 0;
 }
 
 #ifdef HAVE_DHCP6
-void join_multicast(int dienow)      
+void join_multicast(int dienow)
 {
   struct irec *iface, *tmp;
 
   for (iface = daemon->interfaces; iface; iface = iface->next)
     if (iface->addr.sa.sa_family == AF_INET6 && iface->dhcp_ok && !iface->multicast_done)
       {
-	/* There's an irec per address but we only want to join for multicast 
+	/* There's an irec per address but we only want to join for multicast
 	   once per interface. Weed out duplicates. */
 	for (tmp = daemon->interfaces; tmp; tmp = tmp->next)
 	  if (tmp->multicast_done && tmp->index == iface->index)
 	    break;
-	
+
 	iface->multicast_done = 1;
-	
+
 	if (!tmp)
 	  {
 	    struct ipv6_mreq mreq;
 	    int err = 0;
 
 	    mreq.ipv6mr_interface = iface->index;
-	    
+
 	    inet_pton(AF_INET6, ALL_RELAY_AGENTS_AND_SERVERS, &mreq.ipv6mr_multiaddr);
-	    
+
 	    if ((daemon->doing_dhcp6 || daemon->relay6) &&
 		setsockopt(daemon->dhcp6fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
 	      err = 1;
-	    
+
 	    inet_pton(AF_INET6, ALL_SERVERS, &mreq.ipv6mr_multiaddr);
-	    
-	    if (daemon->doing_dhcp6 && 
+
+	    if (daemon->doing_dhcp6 &&
 		setsockopt(daemon->dhcp6fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
 	      err = 1;
-	    
+
 	    inet_pton(AF_INET6, ALL_ROUTERS, &mreq.ipv6mr_multiaddr);
-	    
+
 	    if (daemon->doing_ra &&
 		setsockopt(daemon->icmp6fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) == -1)
 	      err = 1;
-	    
+
 	    if (err)
 	      {
 		char *s = _("interface %s failed to join DHCPv6 multicast group: %s");
@@ -1124,11 +1124,11 @@ int random_sock(int family)
 	while(tries--)
 	  {
 	    unsigned short port = rand16();
-	    
+
 	    if (daemon->min_port != 0)
 	      port = htons(daemon->min_port + (port % ((unsigned short)ports_avail)));
-	    
-	    if (family == AF_INET) 
+
+	    if (family == AF_INET)
 	      {
 		addr.in.sin_addr.s_addr = INADDR_ANY;
 		addr.in.sin_port = port;
@@ -1139,17 +1139,17 @@ int random_sock(int family)
 #ifdef HAVE_IPV6
 	    else
 	      {
-		addr.in6.sin6_addr = in6addr_any; 
+		addr.in6.sin6_addr = in6addr_any;
 		addr.in6.sin6_port = port;
 #ifdef HAVE_SOCKADDR_SA_LEN
 		addr.in6.sin6_len = sizeof(struct sockaddr_in6);
 #endif
 	      }
 #endif
-	    
+
 	    if (bind(fd, (struct sockaddr *)&addr, sa_len(&addr)) == 0)
 	      return fd;
-	    
+
 	    if (errno != EADDRINUSE && errno != EACCES)
 	      break;
 	  }
@@ -1157,9 +1157,9 @@ int random_sock(int family)
       close(fd);
     }
 
-  return -1; 
+  return -1;
 }
-  
+
 
 int local_bind(int fd, union mysockaddr *addr, char *intname, int is_tcp)
 {
@@ -1175,10 +1175,10 @@ int local_bind(int fd, union mysockaddr
 	addr_copy.in6.sin6_port = 0;
 #endif
     }
-  
+
   if (bind(fd, (struct sockaddr *)&addr_copy, sa_len(&addr_copy)) == -1)
     return 0;
-    
+
 #if defined(SO_BINDTODEVICE)
   if (intname[0] != 0 &&
       setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, intname, IF_NAMESIZE) == -1)
@@ -1198,51 +1198,51 @@ static struct serverfd *allocate_sfd(uni
   if (!daemon->osport && intname[0] == 0)
     {
       errno = 0;
-      
+
       if (addr->sa.sa_family == AF_INET &&
 	  addr->in.sin_addr.s_addr == INADDR_ANY &&
-	  addr->in.sin_port == htons(0)) 
+	  addr->in.sin_port == htons(0))
 	return NULL;
 
 #ifdef HAVE_IPV6
       if (addr->sa.sa_family == AF_INET6 &&
 	  memcmp(&addr->in6.sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0 &&
-	  addr->in6.sin6_port == htons(0)) 
+	  addr->in6.sin6_port == htons(0))
 	return NULL;
 #endif
     }
-      
+
   /* may have a suitable one already */
   for (sfd = daemon->sfds; sfd; sfd = sfd->next )
     if (sockaddr_isequal(&sfd->source_addr, addr) &&
 	strcmp(intname, sfd->interface) == 0)
       return sfd;
-  
+
   /* need to make a new one. */
   errno = ENOMEM; /* in case malloc fails. */
   if (!(sfd = whine_malloc(sizeof(struct serverfd))))
     return NULL;
-  
+
   if ((sfd->fd = socket(addr->sa.sa_family, SOCK_DGRAM, 0)) == -1)
     {
       free(sfd);
       return NULL;
     }
-  
+
   if (!local_bind(sfd->fd, addr, intname, 0) || !fix_fd(sfd->fd))
-    { 
+    {
       errsave = errno; /* save error from bind. */
       close(sfd->fd);
       free(sfd);
       errno = errsave;
       return NULL;
     }
-    
-  strcpy(sfd->interface, intname); 
+
+  strcpy(sfd->interface, intname);
   sfd->source_addr = *addr;
   sfd->next = daemon->sfds;
   daemon->sfds = sfd;
-  return sfd; 
+  return sfd;
 }
 
 /* create upstream sockets during startup, before root is dropped which may be needed
@@ -1250,7 +1250,7 @@ static struct serverfd *allocate_sfd(uni
 void pre_allocate_sfds(void)
 {
   struct server *srv;
-  
+
   if (daemon->query_port != 0)
     {
       union  mysockaddr addr;
@@ -1273,7 +1273,7 @@ void pre_allocate_sfds(void)
       allocate_sfd(&addr, "");
 #endif
     }
-  
+
   for (srv = daemon->servers; srv; srv = srv->next)
     if (!(srv->flags & (SERV_LITERAL_ADDRESS | SERV_NO_ADDR | SERV_USE_RESOLV | SERV_NO_REBIND)) &&
 	!allocate_sfd(&srv->source_addr, srv->interface) &&
@@ -1288,7 +1288,7 @@ void pre_allocate_sfds(void)
 	  }
 	die(_("failed to bind server socket for %s: %s"),
 	    daemon->namebuff, EC_BADNET);
-      }  
+      }
 }
 
 void mark_servers(int flag)
@@ -1312,7 +1312,7 @@ void cleanup_servers(void)
   struct server *serv, *tmp, **up;
 
   /* unlink and free anything still marked. */
-  for (serv = daemon->servers, up = &daemon->servers; serv; serv = tmp) 
+  for (serv = daemon->servers, up = &daemon->servers; serv; serv = tmp)
     {
       tmp = serv->next;
       if (serv->flags & SERV_MARK)
@@ -1323,7 +1323,7 @@ void cleanup_servers(void)
 	   free(serv->domain);
 	 free(serv);
        }
-      else 
+      else
        up = &serv->next;
     }
 
@@ -1341,7 +1341,7 @@ void add_update_server(int flags,
 {
   struct server *serv, *next = NULL;
   char *domain_str = NULL;
-  
+
   /* See if there is a suitable candidate, and unmark */
   for (serv = daemon->servers; serv; serv = serv->next)
     if (serv->flags & SERV_MARK)
@@ -1356,7 +1356,7 @@ void add_update_server(int flags,
 	    if (serv->flags & SERV_HAS_DOMAIN)
 	      continue;
 	  }
-	
+
         break;
       }
 
@@ -1388,7 +1388,7 @@ void add_update_server(int flags,
 	    strcpy(domain_str, domain);
 	}
     }
-  
+
   if (serv)
     {
       memset(serv, 0, sizeof(struct server));
@@ -1399,13 +1399,13 @@ void add_update_server(int flags,
       serv->edns_pktsz = daemon->edns_pktsz;
 #ifdef HAVE_LOOP
       serv->uid = rand32();
-#endif      
+#endif
 
       if (domain)
 	serv->flags |= SERV_HAS_DOMAIN;
-      
+
       if (interface)
-	strcpy(serv->interface, interface);      
+	strcpy(serv->interface, interface);
       if (addr)
 	serv->addr = *addr;
       if (source_addr)
@@ -1422,7 +1422,7 @@ void check_servers(void)
   /* interface may be new since startup */
   if (!option_bool(OPT_NOWILD))
     enumerate_interfaces(0);
-  
+
   for (serv = daemon->servers; serv; serv = serv->next)
     {
        if (!(serv->flags & (SERV_LITERAL_ADDRESS | SERV_NO_ADDR | SERV_USE_RESOLV | SERV_NO_REBIND)))
@@ -1440,26 +1440,26 @@ void check_servers(void)
 	  for (iface = daemon->interfaces; iface; iface = iface->next)
 	    if (sockaddr_isequal(&serv->addr, &iface->addr))
 	      break;
-	  if (iface)
+	  if (iface && iface->found != 0)
 	    {
 	      my_syslog(LOG_WARNING, _("ignoring nameserver %s - local interface"), daemon->namebuff);
 	      serv->flags |= SERV_MARK;
 	      continue;
 	    }
-	  
+
 	  /* Do we need a socket set? */
-	  if (!serv->sfd && 
+	  if (!serv->sfd &&
 	      !(serv->sfd = allocate_sfd(&serv->source_addr, serv->interface)) &&
 	      errno != 0)
 	    {
-	      my_syslog(LOG_WARNING, 
+	      my_syslog(LOG_WARNING,
 			_("ignoring nameserver %s - cannot make/bind socket: %s"),
 			daemon->namebuff, strerror(errno));
 	      serv->flags |= SERV_MARK;
 	      continue;
 	    }
 	}
-      
+
       if (!(serv->flags & SERV_NO_REBIND) && !(serv->flags & SERV_LITERAL_ADDRESS))
 	{
 	  if (serv->flags & (SERV_HAS_DOMAIN | SERV_FOR_NODOTS | SERV_USE_RESOLV))
@@ -1471,22 +1471,22 @@ void check_servers(void)
 		s1 = _("default"), s2 = "";
 	      else
 		s1 = _("domain"), s2 = serv->domain;
-	      
+
 	      if (serv->flags & SERV_NO_ADDR)
 		my_syslog(LOG_INFO, _("using local addresses only for %s %s"), s1, s2);
 	      else if (serv->flags & SERV_USE_RESOLV)
 		my_syslog(LOG_INFO, _("using standard nameservers for %s %s"), s1, s2);
-	      else 
+	      else
 		my_syslog(LOG_INFO, _("using nameserver %s#%d for %s %s"), daemon->namebuff, port, s1, s2);
 	    }
 #ifdef HAVE_LOOP
 	  else if (serv->flags & SERV_LOOP)
-	    my_syslog(LOG_INFO, _("NOT using nameserver %s#%d - query loop detected"), daemon->namebuff, port); 
+	    my_syslog(LOG_INFO, _("NOT using nameserver %s#%d - query loop detected"), daemon->namebuff, port);
 #endif
 	  else if (serv->interface[0] != 0)
-	    my_syslog(LOG_INFO, _("using nameserver %s#%d(via %s)"), daemon->namebuff, port, serv->interface); 
+	    my_syslog(LOG_INFO, _("using nameserver %s#%d(via %s)"), daemon->namebuff, port, serv->interface);
 	  else
-	    my_syslog(LOG_INFO, _("using nameserver %s#%d"), daemon->namebuff, port); 
+	    my_syslog(LOG_INFO, _("using nameserver %s#%d"), daemon->namebuff, port);
 	}
     }
 
@@ -1507,24 +1507,24 @@ int reload_servers(char *fname)
       my_syslog(LOG_ERR, _("failed to read %s: %s"), fname, strerror(errno));
       return 0;
     }
-   
+
   mark_servers(SERV_FROM_RESOLV);
-    
+
   while ((line = fgets(daemon->namebuff, MAXDNAME, f)))
     {
       union mysockaddr addr, source_addr;
       char *token = strtok(line, " \t\n\r");
-      
+
       if (!token)
 	continue;
       if (strcmp(token, "nameserver") != 0 && strcmp(token, "server") != 0)
 	continue;
       if (!(token = strtok(NULL, " \t\n\r")))
 	continue;
-      
+
       memset(&addr, 0, sizeof(addr));
       memset(&source_addr, 0, sizeof(source_addr));
-      
+
       if ((addr.in.sin_addr.s_addr = inet_addr(token)) != (in_addr_t) -1)
 	{
 #ifdef HAVE_SOCKADDR_SA_LEN
@@ -1536,17 +1536,17 @@ int reload_servers(char *fname)
 	  source_addr.in.sin_port = htons(daemon->query_port);
 	}
 #ifdef HAVE_IPV6
-      else 
-	{	
+      else
+	{
 	  int scope_index = 0;
 	  char *scope_id = strchr(token, '%');
-	  
+
 	  if (scope_id)
 	    {
 	      *(scope_id++) = 0;
 	      scope_index = if_nametoindex(scope_id);
 	    }
-	  
+
 	  if (inet_pton(AF_INET6, token, &addr.in6.sin6_addr) > 0)
 	    {
 #ifdef HAVE_SOCKADDR_SA_LEN
@@ -1566,12 +1566,12 @@ int reload_servers(char *fname)
 #else /* IPV6 */
       else
 	continue;
-#endif 
+#endif
 
       add_update_server(SERV_FROM_RESOLV, &addr, &source_addr, NULL, NULL);
       gotone = 1;
     }
-  
+
   fclose(f);
   cleanup_servers();
 
@@ -1582,27 +1582,22 @@ int reload_servers(char *fname)
 void newaddress(time_t now)
 {
   (void)now;
-  
+
   if (option_bool(OPT_CLEVERBIND) || option_bool(OPT_LOCAL_SERVICE) ||
       daemon->doing_dhcp6 || daemon->relay6 || daemon->doing_ra)
     enumerate_interfaces(0);
-  
+
   if (option_bool(OPT_CLEVERBIND))
     create_bound_listeners(0);
-  
+
 #ifdef HAVE_DHCP6
   if (daemon->doing_dhcp6 || daemon->relay6 || daemon->doing_ra)
     join_multicast(0);
-  
+
   if (daemon->doing_dhcp6 || daemon->doing_ra)
     dhcp_construct_contexts(now);
-  
+
   if (daemon->doing_dhcp6)
     lease_find_interfaces(now);
 #endif
 }
-
-
-
-
-
