From 347b42b7d57f1e4903a30be867d8bf1b4c41867e Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 7 Jan 2012 07:56:57 +0100 Subject: [PATCH] udp: Use the bind to device socket option. Without this Linux specific option, multicast packets arrive on one interface are delivered by the kernel to all others. Signed-off-by: Richard Cochran --- udp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/udp.c b/udp.c index d1042ca..0d92222 100644 --- a/udp.c +++ b/udp.c @@ -195,6 +195,10 @@ static int open_socket(char *name, struct in_addr *mc_addr, short port) pr_err("bind failed: %m"); goto no_option; } + if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name))) { + pr_err("setsockopt SO_BINDTODEVICE failed: %m"); + goto no_option; + } addr.sin_addr = *mc_addr; if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) { pr_err("mcast_join failed");