Main Site Documentation

Freeze while renewing DHCP license


#1

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!


#2

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.


#3

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?


#4

Yes, DHCP is using UDP as its transport protocol.

The protocol message format is in RFC:

http://datatracker.ietf.org/doc/rfc2131/


#5

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


#6

Thanks for the help :slight_smile:
I got it working


#7

8)That wasn’t hard, was it?


#8

Not as hard as I’d expected :slight_smile: