EthernetNetIF crashing on second or third DHCP request

23 Nov 2011

I seem to have problems with the MBED hanging, when I instantiate a EthernetNetIF.

The behavior I need is that I request a new IP if a link is detected. If that times out I set a static IP.

if(hasLink)
{
	printf("Got link!\r\n");
	link.set_link(Ethernet::FullDuplex100);
	wait(0.1f);
	if(eth)
	{
		delete eth;
		wait(0.1f);
	}
	printf("Request DHCP address\r\n");
	eth = new EthernetNetIf();
	wait(0.1f);
	if(eth->setup() != ETH_OK) //USE static IP if timeout
	{
		delete eth;
		wait(0.1f);
		printf("DHCP timeout set static IP\r\n");
		eth = new EthernetNetIf(
		  IpAddr(192,168,MAC[4],MAC[5]), //IP Address
		  IpAddr(255,255,0,0), //Network Mask
		  IpAddr(192,168,1,1), //Gateway
		  IpAddr(192,168,1,1)  //DNS
		);
		wait(0.1f);
		eth->setup();
	}

	IpAddr ip = eth->getIp();
	printf("IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
	stateGoto(STATE_ONLINE);
}

It seems to me that the EthernetNetIF crashes on second or third allocation, making me suspect a memory leak. What am I doing wrong?

23 Nov 2011

I've also observed serious problems with the dhcp service in EthernetNetIf. I have extensively analyzed the packets with WireShark and even modified the code to correctly format the discover requests. I've even set up my own DHCP server and watched other systems successfully talk to it except for the mBed running EthernetNetIf, it just doesn't seem to accept any "DHCP Inform" messages, etc. I finally just gave up on it and i am doing static addressing in my project exclusively. It's a shame because EthernetNetIf has so much to offer that I am using without a problem. Also beware of malformed IGMP messages for doing multicast... I posted a fix for this one, just do a forum search on "IGMP".

- Errol