bind() & how to receive broadcast packets?
dcornejo at gmail.com
Sat Jan 29 20:56:19 PST 2005
I have a setup where an interface seems to lose broadcast packets
somewhere and I'm hoping some kind soul couls lend a hand.
This is on 6-CURRENT from within the last few days.
One of my interfaces, sis1, is configured with an IP address of 10.0.2.1/24
I'm debugging some code, and in it's original form it binds a socket
to 0.0.0.0 and it seems to get the broadcast packets fine.
However, if I bind the socket to the actual address of the interface,
i no longer receive broadcast packets. This makes some sense I guess,
but is there a way to get one socket to receive only packets for its
bound address *and* the broadcast address?
A more in-depth explanation:
A piece of code I am trying to port from Linux has several interfaces
on the same box all in the same subnet, though not necessarily
connected to each other in any fashion. The code creates a socket per
interface and then bind()s them to 0.0.0.0. It then uses
SO_BINDTODEVICE to sort out which socket serves which interface. In
FreeBSD creating these sockets fail after the first one. My solution
was to bind each socket to the IP address of the interface it serves.
To direct the output broadcast packets I'm using libnet and this works
ok. So I can get the packets out the correct interface, but a select
fails to ever fire on broadcast packets received on the interface.
I've checked that tcpdump (in non-promiscuous mode) sees them coming
If anyone has any ideas, I'd appreciate it greatly.
More information about the freebsd-net