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 <richardcochran@gmail.com>
master
Richard Cochran 2012-01-07 07:56:57 +01:00
parent 95d5c36c0f
commit 347b42b7d5
1 changed files with 4 additions and 0 deletions

4
udp.c
View File

@ -195,6 +195,10 @@ static int open_socket(char *name, struct in_addr *mc_addr, short port)
pr_err("bind failed: %m"); pr_err("bind failed: %m");
goto no_option; 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; addr.sin_addr = *mc_addr;
if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) { if (mcast_join(fd, index, (struct sockaddr *) &addr, sizeof(addr))) {
pr_err("mcast_join failed"); pr_err("mcast_join failed");