From 9ebab013053cae0821bb8441da55f84ee1c37479 Mon Sep 17 00:00:00 2001 From: Forest Johnson Date: Sat, 14 Oct 2023 19:26:07 -0500 Subject: [PATCH] fix misleading listen address in documentation A DHCP server should probably always listen on `0.0.0.0` when we're working on it in development and testing. Why? I believe normal DHCP requests are sent as broadcasts to `255.255.255.255`... I believe when its broadcasted, every single UDP packet regardless of where it ends up, will have `255.255.255.255` as the destination address. And since `255.255.255.255` != `127.0.0.1`, the UDP listener will ignore it. We can tell our UDP listener to listen on `255.255.255.255` but then it will ONLY receive these "normal" DHCP broadcast packets. If someone tries to send a datagram to it directly (on a specific IP like `127.0.0.1`, `192.168.69.1` etc) it wont be received. So i think `0.0.0.0` is appropriate here, considering that it's already being told to listen on a specific interface. --- dhcpv4/server4/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhcpv4/server4/server.go b/dhcpv4/server4/server.go index 4e6796f7..b7b55962 100644 --- a/dhcpv4/server4/server.go +++ b/dhcpv4/server4/server.go @@ -37,7 +37,7 @@ // // func main() { // laddr := net.UDPAddr{ -// IP: net.ParseIP("127.0.0.1"), +// IP: net.ParseIP("0.0.0.0"), // Port: 67, // } // server, err := server4.NewServer("eth0", &laddr, handler)