1
/* dnsmasq is Copyright (c) 2000-2007 Simon Kelley
1
/* dnsmasq is Copyright (c) 2000-2009 Simon Kelley
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
10
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program. If not, see <http://www.gnu.org/licenses/>.
13
You should have received a copy of the GNU General Public License
14
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
#include "dnsmasq.h"
396
400
die(_("failed to set IPV6 options on listening socket: %s"), NULL, EC_BADNET);
406
if ((rc = bind(new->fd, &iface->addr.sa, sa_len(&iface->addr))) != -1)
410
/* An interface may have an IPv6 address which is still undergoing DAD.
411
If so, the bind will fail until the DAD completes, so we try over 20 seconds
413
if (iface->addr.sa.sa_family == AF_INET6 && (errno == ENODEV || errno == EADDRNOTAVAIL) &&
414
dad_count++ < DAD_WAIT)
400
if (bind(new->tcpfd, &iface->addr.sa, sa_len(&iface->addr)) == -1 ||
401
bind(new->fd, &iface->addr.sa, sa_len(&iface->addr)) == -1)
423
if (rc == -1 || bind(new->tcpfd, &iface->addr.sa, sa_len(&iface->addr)) == -1)
404
if (iface->addr.sa.sa_family == AF_INET6 && (errno == ENODEV || errno == EADDRNOTAVAIL))
414
prettyprint_addr(&iface->addr, daemon->namebuff);
415
die(_("failed to bind listening socket for %s: %s"),
416
daemon->namebuff, EC_BADNET);
425
prettyprint_addr(&iface->addr, daemon->namebuff);
426
die(_("failed to bind listening socket for %s: %s"),
427
daemon->namebuff, EC_BADNET);
419
else if (listen(new->tcpfd, 5) == -1)
430
if (listen(new->tcpfd, 5) == -1)
420
431
die(_("failed to listen on socket: %s"), NULL, EC_BADNET);
441
450
return listeners;
445
/* return a UDP socket bound to a random port, have to coper with straying into
454
/* return a UDP socket bound to a random port, have to cope with straying into
446
455
occupied port nos and reserved ones. */
447
456
int random_sock(int family)
453
462
union mysockaddr addr;
454
463
unsigned int ports_avail = 65536u - (unsigned short)daemon->min_port;
455
int i, tries = 3 * ports_avail;
464
int tries = ports_avail < 30 ? 3 * ports_avail : 100;
460
466
memset(&addr, 0, sizeof(addr));
461
467
addr.sa.sa_family = family;
524
530
#if defined(SO_BINDTODEVICE)
525
if (strlen(intname) != 0 &&
531
if (intname[0] != 0 &&
526
532
setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, intname, sizeof(intname)) == -1)
623
629
(daemon->options & OPT_NOWILD))
625
631
prettyprint_addr(&srv->addr, daemon->namebuff);
626
if (strlen(srv->interface) != 0)
632
if (srv->interface[0] != 0)
628
634
strcat(daemon->namebuff, " ");
629
635
strcat(daemon->namebuff, srv->interface);
698
704
else if (!(new->flags & SERV_LITERAL_ADDRESS))
699
705
my_syslog(LOG_INFO, _("using nameserver %s#%d for %s %s"), daemon->namebuff, port, s1, s2);
701
else if (strlen(new->interface) != 0)
707
else if (new->interface[0] != 0)
702
708
my_syslog(LOG_INFO, _("using nameserver %s#%d(via %s)"), daemon->namebuff, port, new->interface);
704
710
my_syslog(LOG_INFO, _("using nameserver %s#%d"), daemon->namebuff, port);