summaryrefslogtreecommitdiff
path: root/sysdep/bsd
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-09-04 11:06:51 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2009-09-04 11:06:51 +0200
commitf9c799a00e705b1420b214628c2bb2a30bf491d9 (patch)
tree23386935f0128d31acab5f86da41774cac0a4de5 /sysdep/bsd
parentd2ceaf4ec82837239a35ace00399ce3aa845849e (diff)
Temporary OSPFv3 development commit (changing multicast support).
Diffstat (limited to 'sysdep/bsd')
-rw-r--r--sysdep/bsd/sysio.h51
1 files changed, 29 insertions, 22 deletions
diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h
index b0ec456e..80f8f942 100644
--- a/sysdep/bsd/sysio.h
+++ b/sysdep/bsd/sysio.h
@@ -27,48 +27,55 @@ set_inaddr(struct in_addr * ia, ip_addr a)
}
static inline char *
-sysio_mcast_setup(sock * s)
+sysio_setup_multicast(sock *s)
{
- u8 zero = 0;
- u8 one = 1;
+ struct in_addr m;
+ u8 zero = 0;
+ u8 ttl = s->ttl;
- if (ipa_nonzero(s->daddr)) {
+ if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &zero, sizeof(zero)) < 0)
+ return "IP_MULTICAST_LOOP";
- if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &zero, sizeof(zero)) < 0)
- return "IP_MULTICAST_LOOP";
+ if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
+ return "IP_MULTICAST_TTL";
+
+ /* This defines where should we send _outgoing_ multicasts */
+ set_inaddr(&m, s->iface->addr->ip);
+ if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0)
+ return "IP_MULTICAST_IF";
- if (setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_TTL, &one, sizeof(one)) < 0)
- return "IP_MULTICAST_TTL";
- }
return NULL;
}
static inline char *
-sysio_mcast_join(sock * s)
+sysio_join_group(sock *s, ip_addr maddr)
{
- struct in_addr m;
struct ip_mreq mreq;
- char *err;
-
- set_inaddr(&m, s->iface->addr->ip );
bzero(&mreq, sizeof(mreq));
set_inaddr(&mreq.imr_interface, s->iface->addr->ip);
- set_inaddr(&mreq.imr_multiaddr, s->daddr);
+ set_inaddr(&mreq.imr_multiaddr, maddr);
/* And this one sets interface for _receiving_ multicasts from */
- if (ipa_nonzero(s->daddr) &&
- setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
+ if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
return "IP_ADD_MEMBERSHIP";
+ return NULL;
+}
- /* This defines where should we send _outgoing_ multicasts */
- if (ipa_nonzero(s->daddr) && setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0)
- return "IP_MULTICAST_IF";
+static inline char *
+sysio_leave_group(sock *s, ip_addr maddr)
+{
+ struct ip_mreq mreq;
- if (err = sysio_mcast_setup(s))
- return err;
+ bzero(&mreq, sizeof(mreq));
+ set_inaddr(&mreq.imr_interface, s->iface->addr->ip);
+ set_inaddr(&mreq.imr_multiaddr, maddr);
+
+ /* And this one sets interface for _receiving_ multicasts from */
+ if (setsockopt(s->fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
+ return "IP_DROP_MEMBERSHIP";
return NULL;
}