Revision b1a1faba sysdep/unix/io.c

View differences:

sysdep/unix/io.c
2 2
 *	BIRD Internet Routing Daemon -- Unix I/O
3 3
 *
4 4
 *	(c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *      (c) 2004       Ondrej Filip <feela@network.cz>
5 6
 *
6 7
 *	Can be freely distributed and used under the terms of the GNU GPL.
7 8
 */
......
29 30
#include "lib/unix.h"
30 31
#include "lib/sysio.h"
31 32

  
33
#define LOCAL_DEBUG
32 34
/*
33 35
 *	Tracked Files
34 36
 */
......
399 401
#define SOL_IP IPPROTO_IP
400 402
#endif
401 403

  
404
#ifndef SOL_IPV6
405
#define SOL_IPV6 IPPROTO_IPV6
406
#endif
407

  
408
#ifndef IPV6_ADD_MEMBERSHIP
409
#define IPV6_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
410
#endif
411

  
402 412
static list sock_list;
403 413

  
404 414
static void
......
476 486
void
477 487
fill_in_sockaddr(sockaddr *sa, ip_addr a, unsigned port)
478 488
{
489
  memset (sa, 0, sizeof (struct sockaddr_in6));
479 490
  sa->sin6_family = AF_INET6;
480 491
  sa->sin6_port = htons(port);
481 492
  sa->sin6_flowinfo = 0;
493
#ifdef HAVE_SIN_LEN
494
  sa->sin6_len = sizeof(struct sockaddr_in6);
495
#endif
482 496
  set_inaddr(&sa->sin6_addr, a);
483 497
}
484 498

  
485 499
void
486
get_sockaddr(sockaddr *sa, ip_addr *a, unsigned *port)
500
get_sockaddr(struct sockaddr_in6 *sa, ip_addr *a, unsigned *port, int check)
487 501
{
488
  if (sa->sin6_family != AF_INET6)
489
    bug("get_sockaddr called for wrong address family");
502
  if (check && sa->sin6_family != AF_INET6)
503
    bug("get_sockaddr called for wrong address family (%d)", sa->sin6_family);
490 504
  if (port)
491 505
    *port = ntohs(sa->sin6_port);
492 506
  memcpy(a, &sa->sin6_addr, sizeof(*a));
......
498 512
void
499 513
fill_in_sockaddr(sockaddr *sa, ip_addr a, unsigned port)
500 514
{
515
  memset (sa, 0, sizeof (struct sockaddr_in));
501 516
  sa->sin_family = AF_INET;
502 517
  sa->sin_port = htons(port);
518
#ifdef HAVE_SIN_LEN
519
  sa->sin_len = sizeof(struct sockaddr_in);
520
#endif
503 521
  set_inaddr(&sa->sin_addr, a);
504 522
}
505 523

  
506 524
void
507
get_sockaddr(sockaddr *sa, ip_addr *a, unsigned *port)
525
get_sockaddr(struct sockaddr_in *sa, ip_addr *a, unsigned *port, int check)
508 526
{
509
  if (sa->sin_family != AF_INET)
510
    bug("get_sockaddr called for wrong address family");
527
  if (check && sa->sin_family != AF_INET)
528
    bug("get_sockaddr called for wrong address family (%d)", sa->sin_family);
511 529
  if (port)
512 530
    *port = ntohs(sa->sin_port);
513 531
  memcpy(a, &sa->sin_addr.s_addr, sizeof(*a));
......
536 554
    WARN("IP_TOS");
537 555
  if (s->ttl >= 0 && setsockopt(fd, SOL_IP, IP_TTL, &s->ttl, sizeof(s->ttl)) < 0)
538 556
    ERR("IP_TTL");
539
  if (s->ttl == 1 && setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &one, sizeof(one)) < 0)
540
    ERR("SO_DONTROUTE");
557
  //if (s->ttl == 1 && setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &one, sizeof(one)) < 0)
558
  //  ERR("SO_DONTROUTE");
541 559
#endif
542 560
  err = NULL;
543 561
bad:
......
578 596
      t->rbsize = s->rbsize;
579 597
      t->tbsize = s->tbsize;
580 598
      if (type == SK_TCP)
581
	get_sockaddr((sockaddr *) sa, &t->daddr, &t->dport);
599
	get_sockaddr((sockaddr *) sa, &t->daddr, &t->dport, 1);
582 600
      add_tail(&sock_list, &t->n);
583 601
      if (err = sk_setup(t))
584 602
	{
......
645 663
  s->fd = fd;
646 664

  
647 665
  if (err = sk_setup(s))
666
  {
648 667
    goto bad;
668
  }
649 669
  switch (type)
650 670
    {
651 671
    case SK_UDP:
......
683 703
	    mreq.ipv6mr_ifindex = s->iface->index;
684 704
#else
685 705
	    mreq.ipv6mr_interface = s->iface->index;
686
#endif
706
#endif /* CONFIG_IPV6_GLIBC_20 */
687 707
	    if (setsockopt(fd, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
688 708
	      ERR("IPV6_ADD_MEMBERSHIP");
689 709
	  }
......
692 712
	ASSERT(s->iface && s->iface->addr);
693 713
	if (err = sysio_mcast_join(s))
694 714
	  goto bad;
695
#endif
715
#endif /* IPV6 */
696 716
      break;
697 717
      }
698 718
    }
......
842 862
	if (s->tbuf == s->tpos)
843 863
	  return 1;
844 864
	fill_in_sockaddr(&sa, s->faddr, s->fport);
865

  
845 866
	e = sendto(s->fd, s->tbuf, s->tpos - s->tbuf, 0, (struct sockaddr *) &sa, sizeof(sa));
846 867
	if (e < 0)
847 868
	  {
......
955 976
	    return 0;
956 977
	  }
957 978
	s->rpos = s->rbuf + e;
958
	get_sockaddr(&sa, &s->faddr, &s->fport);
979
	get_sockaddr(&sa, &s->faddr, &s->fport, 1);
959 980
	s->rx_hook(s, e);
960 981
	return 1;
961 982
      }

Also available in: Unified diff