int
sock_set_ipv4_mcast_loop(int fd)
{
- uint8_t loop = 0;
-
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
- (char *)&loop, sizeof(loop)) < 0) {
- log_warn("%s: error setting IP_MULTICAST_LOOP", __func__);
- return (-1);
- }
-
- return (0);
+ return (setsockopt_ipv4_multicast_loop(fd, 0));
}
int
#error "Unsupported multicast API"
#endif
}
-
+
+int
+setsockopt_ipv4_multicast_loop (int sock, u_char val)
+{
+ int ret;
+
+ ret = setsockopt (sock, IPPROTO_IP, IP_MULTICAST_LOOP, (void *) &val,
+ sizeof (val));
+ if (ret < 0)
+ zlog_warn ("can't setsockopt IP_MULTICAST_LOOP");
+
+ return ret;
+}
+
static int
setsockopt_ipv4_ifindex (int sock, ifindex_t val)
{
struct in_addr if_addr,
unsigned int mcast_addr,
ifindex_t ifindex);
+extern int setsockopt_ipv4_multicast_loop (int sock, u_char val);
+
extern int setsockopt_ipv4_tos(int sock, int tos);
/* Ask for, and get, ifindex, by whatever method is supported. */
{
u_char val;
int ret, len;
-
- val = 0;
- len = sizeof (val);
-
+
/* Prevent receiving self-origined multicast packets. */
- ret = setsockopt (top->fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void *)&val, len);
+ ret = setsockopt_ipv4_multicast_loop (top->fd, 0);
if (ret < 0)
zlog_warn ("can't setsockopt IP_MULTICAST_LOOP(0) for fd %d: %s",
top->fd, safe_strerror(errno));
/* Explicitly set multicast ttl to 1 -- endo. */
val = 1;
+ len = sizeof (val);
ret = setsockopt (top->fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&val, len);
if (ret < 0)
zlog_warn ("can't setsockopt IP_MULTICAST_TTL(1) for fd %d: %s",
#include "privs.h"
#include "if.h"
#include "vrf.h"
+#include "sockopt.h"
#include "pimd.h"
#include "pim_mroute.h"
}
}
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
- (void *) &loop, sizeof(loop))) {
+ if (setsockopt_ipv4_multicast_loop (fd, loop)) {
zlog_warn("Could not %s Multicast Loopback Option on socket fd=%d: errno=%d: %s",
loop ? "enable" : "disable",
fd, errno, safe_strerror(errno));
#include "if.h"
#include "log.h"
#include "memory.h"
+#include "sockopt.h"
#include "pim_ssmpingd.h"
#include "pim_time.h"
return -1;
}
- {
- u_char loop = 0;
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
- (void *) &loop, sizeof(loop))) {
- zlog_warn("%s: could not %s Multicast Loopback Option on socket fd=%d: errno=%d: %s",
- __PRETTY_FUNCTION__,
- loop ? "enable" : "disable",
- fd, errno, safe_strerror(errno));
- close(fd);
- return PIM_SOCK_ERR_LOOP;
- }
+ if (setsockopt_ipv4_multicast_loop (fd, 0)) {
+ zlog_warn("%s: could not disable Multicast Loopback Option on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_LOOP;
}
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
zlog_warn("sendto %s", safe_strerror (errno));
}
- if(dst != INADDR_BROADCAST) {
- on = 0;
- if( setsockopt(irdp_sock,IPPROTO_IP, IP_MULTICAST_LOOP,
- (char *)&on,sizeof(on)) < 0)
- zlog_warn("sendto %s", safe_strerror (errno));
- }
+ if(dst != INADDR_BROADCAST)
+ setsockopt_ipv4_multicast_loop (irdp_sock, 0);
memset(&sockdst,0,sizeof(sockdst));
sockdst.sin_family=AF_INET;