dhcp-rogue: use raw socket and output on one line.
1. Socket usage
Using a UDP socket sends the packet with a source IP address
of our own IP, like 192.168.1.1. Other GFiber Network Boxes
on the LAN will respond because we set the "dhcp-authoritative"
config option in dnsmasq, but many DHCP servers will ignore
these DHCP Discover frames. Therefore we are not reliably
detecting other nearby DHCP servers.
Fix this by using a PF_PACKET socket, and filling out the
IP and UDP headers ourself. We set the source IP to 0.0.0.0.
PF_PACKET goes straight out on the wire, so the local dnsmasq
(if any) does not see it. So additionally send a DHCP Discover
on a PF_INET socket, to be able to monitor the local dnsmasq.
2. Print on one line
Printing each response as it arrives is really only useful
for humans looking at the result. Gather all responses and
print them on one line, so monitoring can look for cases where
>1 server responded.
3. Increase timeout to 15 seconds
Noticed that Comcast's DHCP servers routinely take about 5
seconds to respond, so a 5 second timeout isn't reliable.
Make the timeout longer.
b/27441248
Change-Id: Iaa690ec21ce6069b3b5d37e6b455845e9b00e37b
1 file changed