How DHCP client Works and How to Integrate

I need help regarding DHCP client . I Find it very hard to understand the flow of how to integrated DHCP. I have followed Many Github Repos for DHCP client but i am still not clear could anyone Help about this ?. Many Examples are Confusing.
What i Find difficult to Follow is as Follow,

  1. What Is prerequisite for DHCP_init() ? --I think , only MAC addr and the rest Subnet IP and Getway all set to Zero. Is it Correct ? I think SUbnet Mask will always be 255.255.255.0 is it correct ?
  2. Do i have to pass any functional handlers or create local variables etc. before or after DHCp_init() and before DHCP_run()?
  3. Timer 1 Second Set to DHCP handler that Understood
  4. I have not yet Understood What is PHY LINK …is physical or Software bit…never understood that
  5. In DHCP_run() (while polling) when is the Success? --only When DHCP_LEASED state is reached or with DHCP_CHANGED as well(assuming i have set default ip and that when network finds it conflicting it changes to appropriate one --that is also Success right?)
    how state transition happens?.
  6. When DHCP Leased…do i have to call DHCP_stop(), or just let go? If Successful. Is the Network Configurations automatically Set or do i have to read into temporary Structure variable and the Set them in W5500 forcefully ?.
  7. what if router goes down After i have obtained proper credentials… and after some time power is back …does it re-initiate getting credentials or do i have re-initiate from DHCP_init().
  8. How do i check for is the Router is even Powered on ?
  9. My code Gets stuck at DHCP_DIscover…and stuck forever

I have W5500 integrated with 16bit Controller.
I am awaiting reply… I am Completely rookie in this

In Above case i Have worked with StaticIP Http Client mode and works fine. I have Also Understood PHYLNK . But I have Tried many Ways in DHCP client but its gets Stuck at DHCP_Discover(). in that Sendto() function. As i debugged it and found that Printf() after that statement wont work. The Same module Works fine in Arduino Atmega2560

Refer to your another question.
Thank you.

Thanks it works… But The Issues is now DHCP Succeeds but DNS fails. Can You shade some light on how to go with DHCP acquired Credentials ?. Because When i used STATIC IP and DNS for http Client Application works.but; for DHCP+DNS http client after DHCP succeeds to get ip. and finally proceed to HTTP Get request Socket Initialization fails.

The DHCP authentication procedure may differ for each dhcp server.
In general, NAT does not allow communication for unregistered MACs.
You must register the MAC with NAT, or implement the authentication procedure that NAT requires.

Most of all, You try to run to DHCP client on your PC and capture DHCP packet.
And compare PC DHCP messge to W5500 packet.

Some DHCP server can request special options.
Wiznet dhcp client example did not implement specition optiions, so you have to implement these
options process.

Thank you.

Ok I Absolutely Don’t Understand that, As i am NO strong in TCPIP. So i will study around and get back here . i will need a week or so to understand that. But any way thanks for the fast reply

I did try with Valid MAC address IC 24AA02E48 from Microchip and now it is working. But it would be good if you could enlighten me more on the issue of DHCP options you have mentioned in the response. I have not faced that problem with the router at my place but i may need it in another place. Even the slightest idea about the possible DHCP options about which i should be aware of will help.

Dear Vpan!

As you know, There are many DHCP option from 0 to 255.
I also don’t have some experience such like you.
Through WIZnet DHCP supported options, you can get a new IP from typical DHCP server.
But, some special server requure some option related to athentification & security.
For example, 82 option.
Refer to this.

Sorry I didn’t help much to you.

Thank you.

1 Like

ThanQ