~cyphermox/ubuntu/precise/dnsmasq/dbus

« back to all changes in this revision

Viewing changes to src/network.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2011-02-18 09:54:13 UTC
  • mfrom: (0.3.10 upstream) (12.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110218095413-ih2zl300bks56d78
Tags: 2.57-1
 * New upstream.
 * Fix typos in example config file. (closes: #606615)
 * Bump standards-version to 3.9.1
 * Add noidn DEB_BUILD_OPTIONS flag.
 * Don't complain about extra command line arguments if
   they are empty, as this breaks libvirt. (closes: #613915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dnsmasq is Copyright (c) 2000-2010 Simon Kelley
 
1
/* dnsmasq is Copyright (c) 2000-2011 Simon Kelley
2
2
 
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
34
34
  return 1;
35
35
}
36
36
 
 
37
 
 
38
#elif defined(HAVE_SOLARIS_NETWORK)
 
39
 
 
40
#include <zone.h>
 
41
#include <alloca.h>
 
42
#ifndef LIFC_UNDER_IPMP
 
43
#  define LIFC_UNDER_IPMP 0
 
44
#endif
 
45
 
 
46
int indextoname(int fd, int index, char *name)
 
47
{
 
48
  int64_t lifc_flags;
 
49
  struct lifnum lifn;
 
50
  int numifs, bufsize, i;
 
51
  struct lifconf lifc;
 
52
  struct lifreq *lifrp;
 
53
  
 
54
  if (index == 0)
 
55
    return 0;
 
56
  
 
57
  if (getzoneid() == GLOBAL_ZONEID) 
 
58
    {
 
59
      if (!if_indextoname(index, name))
 
60
        return 0;
 
61
      return 1;
 
62
    }
 
63
  
 
64
  lifc_flags = LIFC_NOXMIT | LIFC_TEMPORARY | LIFC_ALLZONES | LIFC_UNDER_IPMP;
 
65
  lifn.lifn_family = AF_UNSPEC;
 
66
  lifn.lifn_flags = lifc_flags;
 
67
  if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0) 
 
68
    return 0;
 
69
  
 
70
  numifs = lifn.lifn_count;
 
71
  bufsize = numifs * sizeof(struct lifreq);
 
72
  
 
73
  lifc.lifc_family = AF_UNSPEC;
 
74
  lifc.lifc_flags = lifc_flags;
 
75
  lifc.lifc_len = bufsize;
 
76
  lifc.lifc_buf = alloca(bufsize);
 
77
  
 
78
  if (ioctl(fd, SIOCGLIFCONF, &lifc) < 0)  
 
79
    return 0;
 
80
  
 
81
  lifrp = lifc.lifc_req;
 
82
  for (i = lifc.lifc_len / sizeof(struct lifreq); i; i--, lifrp++) 
 
83
    {
 
84
      struct lifreq lifr;
 
85
      strncpy(lifr.lifr_name, lifrp->lifr_name, IF_NAMESIZE);
 
86
      if (ioctl(fd, SIOCGLIFINDEX, &lifr) < 0) 
 
87
        return 0;
 
88
      
 
89
      if (lifr.lifr_index == index) {
 
90
        strncpy(name, lifr.lifr_name, IF_NAMESIZE);
 
91
        return 1;
 
92
      }
 
93
    }
 
94
  return 0;
 
95
}
 
96
 
 
97
 
37
98
#else
38
99
 
39
100
int indextoname(int fd, int index, char *name)
188
249
  
189
250
#ifdef HAVE_TFTP
190
251
  /* implement wierd TFTP service rules */
191
 
  if (addr->sa.sa_family == AF_INET)
192
 
    for (ir = daemon->tftp_interfaces; ir; ir = ir->next)
193
 
      if (strcmp(ir->interface, ifr.ifr_name) == 0)
194
 
        {
195
 
          tftp_ok = 1;
196
 
          break;
197
 
        }
 
252
  for (ir = daemon->tftp_interfaces; ir; ir = ir->next)
 
253
    if (strcmp(ir->interface, ifr.ifr_name) == 0)
 
254
      {
 
255
        tftp_ok = 1;
 
256
        break;
 
257
      }
198
258
#endif
199
 
 
 
259
  
200
260
  if (!ir)
201
261
    {
202
262
      if (addr->sa.sa_family == AF_INET &&
276
336
int enumerate_interfaces(void)
277
337
{
278
338
#ifdef HAVE_IPV6
279
 
  return iface_enumerate(&daemon->interfaces, iface_allowed_v4, iface_allowed_v6);
280
 
#else
281
 
  return iface_enumerate(&daemon->interfaces, iface_allowed_v4, NULL);
 
339
  if (!iface_enumerate(AF_INET6, &daemon->interfaces, iface_allowed_v6))
 
340
    return 0; 
282
341
#endif
 
342
 
 
343
  return iface_enumerate(AF_INET, &daemon->interfaces, iface_allowed_v4); 
283
344
}
284
345
 
285
346
/* set NONBLOCK bit on fd: See Stevens 16.6 */
294
355
  return 1;
295
356
}
296
357
 
297
 
#if defined(HAVE_IPV6)
298
 
static int create_ipv6_listener(struct listener **link, int port)
 
358
static int make_sock(union mysockaddr *addr, int type)
299
359
{
300
 
  union mysockaddr addr;
301
 
  int tcpfd, fd;
302
 
  struct listener *l;
303
 
  int opt = 1;
304
 
 
305
 
  memset(&addr, 0, sizeof(addr));
306
 
  addr.in6.sin6_family = AF_INET6;
307
 
  addr.in6.sin6_addr = in6addr_any;
308
 
  addr.in6.sin6_port = htons(port);
309
 
#ifdef HAVE_SOCKADDR_SA_LEN
310
 
  addr.in6.sin6_len = sizeof(addr.in6);
311
 
#endif
312
 
 
313
 
  /* No error of the kernel doesn't support IPv6 */
314
 
  if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) == -1)
315
 
    return (errno == EPROTONOSUPPORT ||
316
 
            errno == EAFNOSUPPORT ||
317
 
            errno == EINVAL);
318
 
  
319
 
  if ((tcpfd = socket(AF_INET6, SOCK_STREAM, 0)) == -1)
320
 
    return 0;
321
 
      
322
 
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
323
 
      setsockopt(tcpfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
324
 
      setsockopt(fd, IPV6_LEVEL, IPV6_V6ONLY, &opt, sizeof(opt)) == -1 ||
325
 
      setsockopt(tcpfd, IPV6_LEVEL, IPV6_V6ONLY, &opt, sizeof(opt)) == -1 ||
326
 
      !fix_fd(fd) ||
327
 
      !fix_fd(tcpfd) ||
328
 
      bind(tcpfd, (struct sockaddr *)&addr, sa_len(&addr)) == -1 ||
329
 
      listen(tcpfd, 5) == -1 ||
330
 
      bind(fd, (struct sockaddr *)&addr, sa_len(&addr)) == -1) 
331
 
    return 0;
332
 
 
333
 
  /* The API changed around Linux 2.6.14 but the old ABI is still supported:
334
 
     handle all combinations of headers and kernel.
335
 
     OpenWrt note that this fixes the problem addressed by your very broken patch. */
336
 
 
337
 
  daemon->v6pktinfo = IPV6_PKTINFO;
338
 
 
339
 
#ifdef IPV6_RECVPKTINFO
340
 
#  ifdef IPV6_2292PKTINFO
341
 
  if (setsockopt(fd, IPV6_LEVEL, IPV6_RECVPKTINFO, &opt, sizeof(opt)) == -1)
342
 
    {
343
 
      if (errno == ENOPROTOOPT && setsockopt(fd, IPV6_LEVEL, IPV6_2292PKTINFO, &opt, sizeof(opt)) != -1)
344
 
        daemon->v6pktinfo = IPV6_2292PKTINFO;
 
360
  int family = addr->sa.sa_family;
 
361
  int fd, rc, opt = 1;
 
362
#ifdef HAVE_IPV6
 
363
  static int dad_count = 0;
 
364
#endif
 
365
  
 
366
  if ((fd = socket(family, type, 0)) == -1)
 
367
    {
 
368
      int port;
 
369
 
 
370
      /* No error if the kernel just doesn't support this IP flavour */
 
371
      if (errno == EPROTONOSUPPORT ||
 
372
          errno == EAFNOSUPPORT ||
 
373
          errno == EINVAL)
 
374
        return -1;
 
375
      
 
376
    err:
 
377
      port = prettyprint_addr(addr, daemon->namebuff);
 
378
      if (!option_bool(OPT_NOWILD))
 
379
        sprintf(daemon->namebuff, "port %d", port);
 
380
      die(_("failed to create listening socket for %s: %s"), 
 
381
          daemon->namebuff, EC_BADNET);
 
382
    }   
 
383
 
 
384
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 || !fix_fd(fd))
 
385
    goto err;
 
386
  
 
387
#ifdef HAVE_IPV6
 
388
  if (family == AF_INET6 && setsockopt(fd, IPV6_LEVEL, IPV6_V6ONLY, &opt, sizeof(opt)) == -1)
 
389
    goto err;
 
390
#endif
 
391
  
 
392
  while (1)
 
393
    {
 
394
      if ((rc = bind(fd, (struct sockaddr *)addr, sa_len(addr))) != -1)
 
395
        break;
 
396
      
 
397
#ifdef HAVE_IPV6
 
398
      /* An interface may have an IPv6 address which is still undergoing DAD. 
 
399
         If so, the bind will fail until the DAD completes, so we try over 20 seconds
 
400
         before failing. */
 
401
      if (family == AF_INET6 && 
 
402
          (errno == ENODEV || errno == EADDRNOTAVAIL) && 
 
403
          dad_count++ < DAD_WAIT)
 
404
        {
 
405
          sleep(1);
 
406
          continue;
 
407
        }
 
408
#endif
 
409
      break;
 
410
    }
 
411
  
 
412
  if (rc == -1)
 
413
    goto err;
 
414
  
 
415
  if (type == SOCK_STREAM)
 
416
    {
 
417
      if (listen(fd, 5) == -1)
 
418
        goto err;
 
419
    }
 
420
  else if (!option_bool(OPT_NOWILD))
 
421
    {
 
422
      if (family == AF_INET)
 
423
        {
 
424
#if defined(HAVE_LINUX_NETWORK) 
 
425
          if (setsockopt(fd, SOL_IP, IP_PKTINFO, &opt, sizeof(opt)) == -1)
 
426
            goto err;
 
427
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
 
428
          if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof(opt)) == -1 ||
 
429
              setsockopt(fd, IPPROTO_IP, IP_RECVIF, &opt, sizeof(opt)) == -1)
 
430
            goto err;
 
431
#endif
 
432
        }
 
433
#ifdef HAVE_IPV6
345
434
      else
346
 
        return 0;
347
 
    }
 
435
        {
 
436
          /* The API changed around Linux 2.6.14 but the old ABI is still supported:
 
437
             handle all combinations of headers and kernel.
 
438
             OpenWrt note that this fixes the problem addressed by your very broken patch. */
 
439
          daemon->v6pktinfo = IPV6_PKTINFO;
 
440
          
 
441
#  ifdef IPV6_RECVPKTINFO
 
442
#    ifdef IPV6_2292PKTINFO
 
443
          if (setsockopt(fd, IPV6_LEVEL, IPV6_RECVPKTINFO, &opt, sizeof(opt)) == -1)
 
444
            {
 
445
              if (errno == ENOPROTOOPT && setsockopt(fd, IPV6_LEVEL, IPV6_2292PKTINFO, &opt, sizeof(opt)) != -1)
 
446
                daemon->v6pktinfo = IPV6_2292PKTINFO;
 
447
              else
 
448
                goto err;
 
449
            }
 
450
#    else
 
451
          if (setsockopt(fd, IPV6_LEVEL, IPV6_RECVPKTINFO, &opt, sizeof(opt)) == -1)
 
452
            goto err;
 
453
#    endif 
348
454
#  else
349
 
  if (setsockopt(fd, IPV6_LEVEL, IPV6_RECVPKTINFO, &opt, sizeof(opt)) == -1)
350
 
    return 0;
351
 
#  endif 
352
 
#else
353
 
  if (setsockopt(fd, IPV6_LEVEL, IPV6_PKTINFO, &opt, sizeof(opt)) == -1)
354
 
    return 0;
355
 
#endif
356
 
  
357
 
  l = safe_malloc(sizeof(struct listener));
358
 
  l->fd = fd;
359
 
  l->tcpfd = tcpfd;
360
 
  l->tftpfd = -1;
361
 
  l->family = AF_INET6;
362
 
  l->next = NULL;
363
 
  *link = l;
364
 
  
365
 
  return 1;
366
 
}
367
 
#endif
 
455
          if (setsockopt(fd, IPV6_LEVEL, IPV6_PKTINFO, &opt, sizeof(opt)) == -1)
 
456
            goto err;
 
457
#  endif
 
458
        }
 
459
#endif
 
460
    }
 
461
 
 
462
  return fd;
 
463
}
 
464
      
 
465
static struct listener *create_listeners(union mysockaddr *addr, int do_tftp)
 
466
{
 
467
  struct listener *l = NULL;
 
468
  int fd = -1, tcpfd = -1, tftpfd = -1;
 
469
 
 
470
  if (daemon->port != 0)
 
471
    {
 
472
      fd = make_sock(addr, SOCK_DGRAM);
 
473
      tcpfd = make_sock(addr, SOCK_STREAM);
 
474
    }
 
475
  
 
476
#ifdef HAVE_TFTP
 
477
  if (do_tftp)
 
478
    {
 
479
      if (addr->sa.sa_family == AF_INET)
 
480
        {
 
481
          /* port must be restored to DNS port for TCP code */
 
482
          short save = addr->in.sin_port;
 
483
          addr->in.sin_port = htons(TFTP_PORT);
 
484
          tftpfd = make_sock(addr, SOCK_DGRAM);
 
485
          addr->in.sin_port = save;
 
486
        }
 
487
#  ifdef HAVE_IPV6
 
488
      else
 
489
        {
 
490
          short save = addr->in6.sin6_port;
 
491
          addr->in6.sin6_port = htons(TFTP_PORT);
 
492
          tftpfd = make_sock(addr, SOCK_DGRAM);
 
493
          addr->in6.sin6_port = save;
 
494
        }  
 
495
#  endif
 
496
    }
 
497
#endif
 
498
 
 
499
  if (fd != -1 || tcpfd != -1 || tftpfd != -1)
 
500
    {
 
501
      l = safe_malloc(sizeof(struct listener));
 
502
      l->next = NULL;
 
503
      l->family = addr->sa.sa_family;
 
504
      l->fd = fd;
 
505
      l->tcpfd = tcpfd;
 
506
      l->tftpfd = tftpfd;
 
507
    }
 
508
 
 
509
  return l;
 
510
}
368
511
 
369
512
struct listener *create_wildcard_listeners(void)
370
513
{
371
514
  union mysockaddr addr;
372
 
  int opt = 1;
373
 
  struct listener *l, *l6 = NULL;
374
 
  int tcpfd = -1, fd = -1, tftpfd = -1;
 
515
  struct listener *l;
 
516
  int tftp_enabled = daemon->tftp_unlimited || daemon->tftp_interfaces; 
375
517
 
376
518
  memset(&addr, 0, sizeof(addr));
 
519
#ifdef HAVE_SOCKADDR_SA_LEN
 
520
  addr.in.sin_len = sizeof(addr.in);
 
521
#endif
377
522
  addr.in.sin_family = AF_INET;
378
523
  addr.in.sin_addr.s_addr = INADDR_ANY;
379
524
  addr.in.sin_port = htons(daemon->port);
380
 
#ifdef HAVE_SOCKADDR_SA_LEN
381
 
  addr.in.sin_len = sizeof(struct sockaddr_in);
382
 
#endif
383
 
 
384
 
  if (daemon->port != 0)
385
 
    {
386
 
      
387
 
      if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1 ||
388
 
          (tcpfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
389
 
        return NULL;
390
 
      
391
 
      if (setsockopt(tcpfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
392
 
          bind(tcpfd, (struct sockaddr *)&addr, sa_len(&addr)) == -1 ||
393
 
          listen(tcpfd, 5) == -1 ||
394
 
          !fix_fd(tcpfd) ||
 
525
 
 
526
  l = create_listeners(&addr, tftp_enabled);
 
527
 
395
528
#ifdef HAVE_IPV6
396
 
          !create_ipv6_listener(&l6, daemon->port) ||
397
 
#endif
398
 
          setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
399
 
          !fix_fd(fd) ||
400
 
#if defined(HAVE_LINUX_NETWORK) 
401
 
          setsockopt(fd, SOL_IP, IP_PKTINFO, &opt, sizeof(opt)) == -1 ||
402
 
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
403
 
          setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof(opt)) == -1 ||
404
 
          setsockopt(fd, IPPROTO_IP, IP_RECVIF, &opt, sizeof(opt)) == -1 ||
405
 
#endif 
406
 
          bind(fd, (struct sockaddr *)&addr, sa_len(&addr)) == -1)
407
 
        return NULL;
408
 
    }
409
 
  
410
 
#ifdef HAVE_TFTP
411
 
  if (daemon->tftp_unlimited || daemon->tftp_interfaces)
412
 
    {
413
 
      addr.in.sin_port = htons(TFTP_PORT);
414
 
      if ((tftpfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
415
 
        return NULL;
416
 
      
417
 
      if (!fix_fd(tftpfd) ||
418
 
#if defined(HAVE_LINUX_NETWORK) 
419
 
          setsockopt(tftpfd, SOL_IP, IP_PKTINFO, &opt, sizeof(opt)) == -1 ||
420
 
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
421
 
          setsockopt(tftpfd, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof(opt)) == -1 ||
422
 
          setsockopt(tftpfd, IPPROTO_IP, IP_RECVIF, &opt, sizeof(opt)) == -1 ||
423
 
#endif 
424
 
          bind(tftpfd, (struct sockaddr *)&addr, sa_len(&addr)) == -1)
425
 
        return NULL;
426
 
    }
427
 
#endif
428
 
  
429
 
  l = safe_malloc(sizeof(struct listener));
430
 
  l->family = AF_INET;
431
 
  l->fd = fd;
432
 
  l->tcpfd = tcpfd;
433
 
  l->tftpfd = tftpfd;
434
 
  l->next = l6;
 
529
  memset(&addr, 0, sizeof(addr));
 
530
#  ifdef HAVE_SOCKADDR_SA_LEN
 
531
  addr.in6.sin6_len = sizeof(addr.in6);
 
532
#  endif
 
533
  addr.in6.sin6_family = AF_INET6;
 
534
  addr.in6.sin6_addr = in6addr_any;
 
535
  addr.in6.sin6_port = htons(daemon->port);
 
536
  
 
537
  if (l) 
 
538
    l->next = create_listeners(&addr, tftp_enabled);
 
539
  else 
 
540
    l = create_listeners(&addr, tftp_enabled);
 
541
#endif
435
542
 
436
543
  return l;
437
544
}
438
545
 
439
546
struct listener *create_bound_listeners(void)
440
547
{
441
 
  struct listener *listeners = NULL;
 
548
  struct listener *new, *listeners = NULL;
442
549
  struct irec *iface;
443
 
  int rc, opt = 1;
444
 
#ifdef HAVE_IPV6
445
 
  static int dad_count = 0;
446
 
#endif
447
550
 
448
551
  for (iface = daemon->interfaces; iface; iface = iface->next)
449
 
    {
450
 
      struct listener *new = safe_malloc(sizeof(struct listener));
451
 
      new->family = iface->addr.sa.sa_family;
452
 
      new->iface = iface;
453
 
      new->next = listeners;
454
 
      new->tftpfd = -1;
455
 
      new->tcpfd = -1;
456
 
      new->fd = -1;
457
 
      listeners = new;
458
 
 
459
 
      if (daemon->port != 0)
460
 
        {
461
 
          if ((new->tcpfd = socket(iface->addr.sa.sa_family, SOCK_STREAM, 0)) == -1 ||
462
 
              (new->fd = socket(iface->addr.sa.sa_family, SOCK_DGRAM, 0)) == -1 ||
463
 
              setsockopt(new->fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
464
 
              setsockopt(new->tcpfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
465
 
              !fix_fd(new->tcpfd) ||
466
 
              !fix_fd(new->fd))
467
 
            die(_("failed to create listening socket: %s"), NULL, EC_BADNET);
468
 
          
469
 
#ifdef HAVE_IPV6
470
 
          if (iface->addr.sa.sa_family == AF_INET6)
471
 
            {
472
 
              if (setsockopt(new->fd, IPV6_LEVEL, IPV6_V6ONLY, &opt, sizeof(opt)) == -1 ||
473
 
                  setsockopt(new->tcpfd, IPV6_LEVEL, IPV6_V6ONLY, &opt, sizeof(opt)) == -1)
474
 
                die(_("failed to set IPV6 options on listening socket: %s"), NULL, EC_BADNET);
475
 
            }
476
 
#endif
477
 
 
478
 
          while(1)
479
 
            {
480
 
              if ((rc = bind(new->fd, &iface->addr.sa, sa_len(&iface->addr))) != -1)
481
 
                break;
482
 
              
483
 
#ifdef HAVE_IPV6
484
 
              /* An interface may have an IPv6 address which is still undergoing DAD. 
485
 
                 If so, the bind will fail until the DAD completes, so we try over 20 seconds
486
 
                 before failing. */
487
 
              if (iface->addr.sa.sa_family == AF_INET6 && (errno == ENODEV || errno == EADDRNOTAVAIL) && 
488
 
                  dad_count++ < DAD_WAIT)
489
 
                {
490
 
                  sleep(1);
491
 
                  continue;
492
 
                }
493
 
#endif
494
 
              break;
495
 
            }
496
 
          
497
 
          if (rc == -1 || bind(new->tcpfd, &iface->addr.sa, sa_len(&iface->addr)) == -1)
498
 
            {
499
 
              prettyprint_addr(&iface->addr, daemon->namebuff);
500
 
              die(_("failed to bind listening socket for %s: %s"), 
501
 
                  daemon->namebuff, EC_BADNET);
502
 
            }
503
 
            
504
 
          if (listen(new->tcpfd, 5) == -1)
505
 
            die(_("failed to listen on socket: %s"), NULL, EC_BADNET);
506
 
        }
507
 
 
508
 
#ifdef HAVE_TFTP
509
 
      if (iface->addr.sa.sa_family == AF_INET && iface->tftp_ok)
510
 
        {
511
 
          short save = iface->addr.in.sin_port;
512
 
          iface->addr.in.sin_port = htons(TFTP_PORT);
513
 
          if ((new->tftpfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1 ||
514
 
              setsockopt(new->tftpfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1 ||
515
 
              !fix_fd(new->tftpfd) ||
516
 
              bind(new->tftpfd, &iface->addr.sa, sa_len(&iface->addr)) == -1)
517
 
            die(_("failed to create TFTP socket: %s"), NULL, EC_BADNET);
518
 
          iface->addr.in.sin_port = save;
519
 
        }
520
 
#endif
521
 
 
522
 
    }
523
 
 
 
552
    if ((new = create_listeners(&iface->addr, iface->tftp_ok)))
 
553
      {
 
554
        new->iface = iface;
 
555
        new->next = listeners;
 
556
        listeners = new;
 
557
      }
 
558
  
524
559
  return listeners;
525
560
}
526
561
 
700
735
    if (!(srv->flags & (SERV_LITERAL_ADDRESS | SERV_NO_ADDR | SERV_USE_RESOLV | SERV_NO_REBIND)) &&
701
736
        !allocate_sfd(&srv->source_addr, srv->interface) &&
702
737
        errno != 0 &&
703
 
        (daemon->options & OPT_NOWILD))
 
738
        option_bool(OPT_NOWILD))
704
739
      {
705
740
        prettyprint_addr(&srv->source_addr, daemon->namebuff);
706
741
        if (srv->interface[0] != 0)
721
756
  int port = 0;
722
757
 
723
758
  /* interface may be new since startup */
724
 
  if (!(daemon->options & OPT_NOWILD))
 
759
  if (!option_bool(OPT_NOWILD))
725
760
    enumerate_interfaces();
726
761
  
727
762
  for (new = daemon->servers; new; new = tmp)
921
956
  
922
957
  ret.sin_addr.s_addr = -1;
923
958
 
924
 
  for (l = daemon->listeners; l && l->family != AF_INET; l = l->next);
 
959
  for (l = daemon->listeners; 
 
960
       l && (l->family != AF_INET || l->fd == -1);
 
961
       l = l->next);
925
962
  
926
963
  strncpy(ifr.ifr_name, intr, IF_NAMESIZE);
927
964
  ifr.ifr_addr.sa_family = AF_INET;