* source address for UDP broadcasts with aliased interfaces?
@ 2004-11-12 21:49 Daniel Risacher
2004-11-15 14:13 ` Alan Cox
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Risacher @ 2004-11-12 21:49 UTC (permalink / raw)
To: linux-kernel
I'm not sure if this is a bug or a feature.
There seems to be no way to get the kernel to send a UDP broadcast
packet to INADDR_BROADCAST from a specific address, short of using
iptables.
I would think that bind()ing a socket to a local address would
determine the source address, but the kernel seems to ignore the bound
address.
I'm trying to write a program that communicates with multiple hosts on
a local net, several of which have firewall rules that drop packets
from external addresses. The source computer has multiple aliased
addresses on the eth0 interface. I therefore want to broadcast from a
specific non-routable internal address. I've experimented with bind()
and setsockopt(,SO_BINDTODEVICE,) to determine the source address
and/or interface but the kernel seems to pick whatever it wants.
Is there a correct way to specify the sender address/interface?
Dan Risacher
(reference code follows; testing was done on Linux 2.6.9)
struct sockaddr_in to_addr;
struct sockaddr_in my_addr;
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(0);
my_addr.sin_addr.s_addr = find_if_addr(interface);
to_addr.sin_family = AF_INET;
to_addr.sin_port = htons(11415);
to_addr.sin_addr.s_addr = INADDR_BROADCAST;
fd = socket(PF_INET, SOCK_DGRAM, 0);
res = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
if (res) perror ("setsockopt (SO_BROADCAST)");
res = bind(fd, (struct sockaddr*) &my_addr, sizeof(struct sockaddr_in));
if (res) perror ("bind");
res = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, interface, 1+strlen(interface));
if (res) perror ("setsockopt (SO_BINDTODEVICE)");
res = sendto(fd, mesg, strlen(mesg), MSG_DONTROUTE,
(struct sockaddr *)&to_addr,
sizeof(struct sockaddr_in));
if (res == -1) perror ("sendto");
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: source address for UDP broadcasts with aliased interfaces?
2004-11-12 21:49 source address for UDP broadcasts with aliased interfaces? Daniel Risacher
@ 2004-11-15 14:13 ` Alan Cox
0 siblings, 0 replies; 2+ messages in thread
From: Alan Cox @ 2004-11-15 14:13 UTC (permalink / raw)
To: Daniel Risacher; +Cc: Linux Kernel Mailing List
On Gwe, 2004-11-12 at 21:49, Daniel Risacher wrote:
> I'm not sure if this is a bug or a feature.
Assuming the address provided is valid I would say bug. You should
however post that query to netdev@oss.sgi.com - that is the networking
list and has a lot more people on it who deal with the network layer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-11-15 15:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-12 21:49 source address for UDP broadcasts with aliased interfaces? Daniel Risacher
2004-11-15 14:13 ` Alan Cox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome