DHCP Client/Server

In this program, the server is listening to the requests from clients using UDP for the transport layer. The clients initially have no IP address. A new client follows the 4 steps of DHCP protocol to discover the DHCP server and get an IP address from the server. The range of IP addresses available to the server is 192.168.1.0/24, a block of 256 IP addresses including Net ID and Broadcast IP address. Note that you cannot assign the Net ID or Broadcast IP addresses to any computer. The server maintains a list of IP addresses and whether they have been assigned, and to which client each IP address has been assigned. Clients are identified by its MAC address. On the server, a list of clients’ MAC addresses and the associated IP address are stored.

The DHCP protocol contains 4 steps: DISCOVER, OFFER, REQUEST, ACKNOWLEDGE.
The client sends a DISCOVER message. Then the server replies an OFFER message. Then the client replies a REQUEST message. Then the server assigns an IP address and replies an ACKNOWLEDGE message.

Git Repository