sk = sk_new(p->pool);
sk->type = SK_IP;
sk->dport = OSPF_PROTO;
-
-#ifdef OSPFv2
- /*
- * In Linux IPv4, binding a raw socket to an IP address of an iface causes
- * that the socket does not receive multicast packets, as they have
- * different (multicast) destination IP address.
- */
sk->saddr = IPA_NONE;
-#else /* OSPFv3 */
- sk->saddr = ifa->addr->ip; /* link-local addr */
-#endif
sk->tos = IP_PREC_INTERNET_CONTROL;
sk->rx_hook = ospf_rx_hook;
ipa_ntoh(*a);
}
+static inline char *
+sysio_bind_to_iface(sock *s)
+{
+ /* Unfortunately not available */
+ return NULL;
+}
+
+
#else
#include <net/if.h>
* Can be freely distributed and used under the terms of the GNU GPL.
*/
+#include <net/if.h>
+
#ifdef IPV6
#ifndef IPV6_UNICAST_HOPS
ipa_ntoh(*a);
}
-#else
+static inline char *
+sysio_bind_to_iface(sock *s)
+{
+ struct ifreq ifr;
+ strcpy(ifr.ifr_name, s->iface->name);
+ if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
+ return "SO_BINDTODEVICE";
-#include <net/if.h>
+ return NULL;
+}
+
+#else
static inline void
set_inaddr(struct in_addr *ia, ip_addr a)
if (setsockopt(s->fd, SOL_IPV6, IPV6_MULTICAST_IF, &index, sizeof(index)) < 0)
ERR("IPV6_MULTICAST_IF");
+ if (err = sysio_bind_to_iface(s))
+ goto bad;
+
return 0;
bad: