Hi,
First, as a first time poster I'd just like to state that the arduino hardware, software, libraries, and user communities are fantastic. I'm truly amazed at the quality.
I am planning to use an arduino to monitor power buses for our computer room in a fortune 500 company. I purchased an ethernet shield a while back and ran a couple of the examples and everything ran properly out of the box (the primary test being UdpNtpClient).
I finally brought the hardware into the office and started trying to make it work here. Ethernet.begin(mac) failed (hung) right off the bat. I temporarily bypassed the problem by using static IP addressing, but it troubled me DHCP wasn't working so I came back to figure it out.
I found that the call to DHCPResponse never returned. Digging in deeper I found that this procedure would continue attempting to process DHCP options after the end option ($FF) was hit.
when endoption is parsed, it just drops out of the switch statement:
case endOption :
break;
there should be nothing left in the buffer at this time, so the while loop should exit:
while (_dhcpUdpSocket.available() > 0)
BUT for some reason it doesn't. I examined the packet with a protocol analyzer, and there is nothing in the packet after the FF option.
I don't understand what is happening well enough to figure out why the buffer isn't empty but I am able to make it empty by modifying the endOption case like this:
case endOption :
_dhcpUdpSocket.flush();
break;
This works and DHCP no longer hangs when I use our work DHCP server.
I can only guess the reason the original DHCP.cpp code works at home and not in the office has something to do with the options the office dhcp server transmits. It transmits these options: 53, 1, 58, 59, 51, 54, 3, 16, 14, $FF.
My 'fix' works, but it doesn't address the underlying reason as to why either the buffer isn't empty or the function at least doesn't think it is empty.
Dan