Freeze while renewing DHCP license

Hi,

I’m having a bit of a problem with registering ChipworkX to LAN. The code I’m using is:


NetworkInterface[] netif = NetworkInterface.GetAllNetworkInterfaces();
if (netif[0].IsDhcpEnabled)
 netif[0].RenewDhcpLease();
else
 netif[0].EnableDhcp();

This works fine when there is a DHCP server on the network. The device gets an IP address and everything runs ok. When there is no DHCP server, however, everything freezes upon RenewDhcpLease call. The method is called from a separate thread (set to lowest priority). This doesn’t seem to make any difference, however, the device is unresponsive for 1-2 minutes before throwing an exception. Can you give me a tip how to detect if there is a DHCP server running on the network, or how to prevent that RenewDhcpLease method from blocking the whole device. Thanks!

Yes you are right, that it expected. NETMF DHCP function is a blocking function. and the time out is couple minutes.

We added a way to detect if the Ethernet cable is connected or not. So in your application you don’t run the Dhcp processes if it is not connected.

If you want to detect if there is a DHCP server. you can develop a little DHCP client using netmf sockets that send DHCP_Discover message. if you got DHCP_OFFER message. then you have a dhcp server on the network.

Thanks for the reply, Joe. I am actually using the cable connection check :slight_smile:
What I need, I think, is a check if there is DHCP server on the network. Can you give me some more information about those DHCP_Discover and DHCP_OFFER messages? Are they some kind of UDP messages? Something already implemented?

Yes, DHCP is using UDP as its transport protocol.

The protocol message format is in RFC:

I find this package from Wiznet is very informative about DHCP.
[url]http://www.wiznet.co.kr/UpLoad_Files/ReferenceFiles/W5100_Appnote_DHCP.zip[/url]

Thanks for the help :slight_smile:
I got it working

8)That wasn’t hard, was it?

Not as hard as I’d expected :slight_smile: