Socket bound to 0.0.0.0 never receives broadcasts with non-zero IP source address
Yuri
yuri at rawbw.com
Wed Apr 8 01:50:17 UTC 2015
I noticed that the socket bound to '0.0.0.0' only receives UDP
broadcasts when they are sent from zero IP: 0.0.0.0->255.255.255.255.
When the source IP is not zeros, but some valid IP on that network,
socket never receives such broadcast.
I compared two packets in wireshark as they arrive, and the only
difference on Ether/IP/UDP level is source IP.
Is there any reason why source IP address would influence the reception
of the broadcast packets?
I use this python3 program to create bound socket and listen:
#!/usr/bin/env python3.4
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.bind(('0.0.0.0', 67))
print("Waiting for broadcast")
(data, flags, ancillary, addr) = sock.recvmsg(4096, 256)
print("Received broadcast packet")
I use dhclient to send broadcast packets. It sends with src=0.0.0.0 when
no /var/db/dhclient.leases.* exists, and it always sends with
src=<previous lease> when the previous lease exists.
10.1 STABLE
Yuri
More information about the freebsd-net
mailing list