Why can't I sendto() to 127.255.255.255
Bruce M. Simpson
bms at incunabulum.net
Mon Apr 30 13:09:38 UTC 2007
Abraham K. Mathen wrote:
>
> Is it possible to successfully sendto() on a UDP socket
> with 127.255.255.255 as the destination address? If yes,
> how can that be done.
No, because in FreeBSD, lo(4) is not implemented as a broadcast
interface. It is a multicast capable software loopback interface. It has
no concept of a broadcast domain. Unicast traffic, as well as multicast
traffic, is looped back on this interface.
You can see that in the output of 'ifconfig lo0', the BROADCAST flag is
not set.
RFC 3330 says:
"A datagram sent by a higher level protocol to an address anywhere
within this block should loop back inside the host."
A few quick tests suggests this does not happen by default on FreeBSD. I
suspect that this is because although lo0 is configured with 127.0.0.1/8
by default, a cloning interface route is not added as ARP does not run
on such an interface. Therefore only a host route for 127.0.0.1 appears
in the table.
To tell the stack to transmit datagrams destined for 127/8 via lo0 you'd
do the following:
route -n add 127.0.0.0/8 -net -iface lo0
Nothing will reply as nothing is listening on that address
(127.255.255.255).
You can configure multiple lo interfaces, they just don't participate in
a broadcast domain, as they are not broadcast interfaces. However, how
lo(4) is implemented has the peculiar side-effect that all loopback
interfaces are in the same 'transmission domain'... tcpdumping on lo0
will show you traffic on lo1. All loopback ifnet instances see each
other's traffic, it's just up to the stack to reject it if it's not
destined for a configured address on that instance.
To try that, you'd 'ifconfig lo1 create' and 'ifconfig lo1 127.0.0.2/32'
as FreeBSD's network stack does not really allow you to have more than
one interface configured on the same subnet.
Regards,
BMS
More information about the freebsd-net
mailing list