I'm looking at some DHCP packets through wireshark. I notice that in the bootp section, there is a broadcast flag.
However, the dest IP is 255.255.255.255. Isn't it enough to indicate that it's broadcasted? Why is the flag needed?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
DHCP flag serves a completely different purpose. It is set by a client to indicate to a server how the reply should be sent to back to the client. DHCP client sends its request by broadcast, initially, since it doesn't know the server's IP address. However, since the server knows the client's IP (it just provided it with one), server can send the reply back by unicast even if the request was sent by broadcast. Per RFC2131:
A client that cannot receive unicast IP datagrams until its protocol software has been configured with an IP address SHOULD set the BROADCAST bit in the 'flags' field to 1 in any DHCPDISCOVER or DHCPREQUEST messages that client sends. The BROADCAST bit will provide a hint to the DHCP server and BOOTP relay agent to broadcast any messages to the client on the client's subnet. A client that can receive unicast IP datagrams before its protocol software has been configured SHOULD clear the BROADCAST bit to 0.
These are at different layers in the ISO stack. A destination IP of 255.255.255.255 makes the packet a broadcast IP packet at the IP level. Setting the broadcast flag inside the DHCP packet would not do this.
The flag itself can be considered information to the DHCP server - it is telling the server that it should reply by broadcast. This is most often the case where the client does not yet have an IP address and so requires a broadcast reply as there no IP yet to unicast to. The DHCP server shouldn't need to inspect the packet headers to figure out how to respond, it is up to the dhcp protocol to make this clear.
You could conceivably have a DHCP request sent as a unicast packet, sent directly to the DHCP server - but the broadcast flag could still be set inside the DHCP flags to let the dhcp server know that it needs to reply by broadcast no matter what the headers looked like.
In summary, the IP and UDP headers tell the IP and UDP layers of the stack know what is going on, whereas the DHCP content is application layer, and let the DHCP application know what is going on.