Statistics
| Branch: | Revision:

iof-bird-daemon / sysdep / bsd / sysio.h @ b1a1faba

History | View | Annotate | Download (1.69 KB)

1
/*
2
 *        BIRD Internet Routing Daemon -- NetBSD Multicasting and Network Includes
3
 *
4
 *        (c) 2004       Ondrej Filip <feela@network.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#ifdef IPV6
10

    
11
static inline void
12
set_inaddr(struct in6_addr * ia, ip_addr a)
13
{
14
        ipa_hton(a);
15
        memcpy(ia, &a, sizeof(a));
16
}
17

    
18
#else
19

    
20
#include <net/if.h>
21

    
22
static inline void
23
set_inaddr(struct in_addr * ia, ip_addr a)
24
{
25
        ipa_hton(a);
26
        memcpy(&ia->s_addr, &a, sizeof(a));
27
}
28

    
29
static inline char *
30
sysio_mcast_setup(sock * s)
31
{
32
        u8              zero = 0;
33
        u8                one = 1;
34

    
35
        if (ipa_nonzero(s->daddr)) {
36

    
37
                if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &zero, sizeof(zero)) < 0) {
38
                        log("IP_MULTICAST_LOOP");
39
                        return "IP_MULTICAST_LOOP";
40
                }
41

    
42
                if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_TTL, &one, sizeof(one)) < 0) {
43
                        log("IP_MULTICAST_TTL");
44
                        return "IP_MULTICAST_TTL";
45
                }
46
        }
47
        return NULL;
48
}
49

    
50

    
51
static inline char *
52
sysio_mcast_join(sock * s)
53
{
54
        struct in_addr  m;
55
        struct ip_mreq  mreq;
56
        char   *err;
57

    
58
        set_inaddr(&m, s->iface->addr->ip );
59

    
60
        memset(&mreq, 0, sizeof(mreq));
61
        set_inaddr(&mreq.imr_interface, s->iface->addr->ip);
62
        set_inaddr(&mreq.imr_multiaddr, s->daddr);
63

    
64
        /* And this one sets interface for _receiving_ multicasts from */
65
        if (ipa_nonzero(s->daddr) && setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
66
                log("IP_ADD_MEMBERSHIP");
67
                return "IP_ADD_MEMBERSHIP";
68
        }
69

    
70

    
71
        /* This defines where should we send _outgoing_ multicasts */
72
        if (ipa_nonzero(s->daddr) && setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0) {
73
                log("IP_MULTICAST_IF");
74
                return "IP_MULTICAST_IF";
75
        }
76

    
77
        if (err = sysio_mcast_setup(s))
78
                return err;
79

    
80
        return NULL;
81
}
82

    
83
#endif