[En-Nut-Discussion] Problem with DHCP
Thiago A. Corrêa
thiago.correa at gmail.com
Wed Dec 7 19:29:20 CET 2005
Hi,
In my nut application I let the user select between using a static
IP or dynamic IP address, static IP configuration is working fine, but
I´m unable to get DHCP client working properly.
Since my network has no DHCP server, I´m running the DHCP server
from Tftpd by Ph. Jounin. I can see in the log window that the board
does requests an address ( Rcvd DHCP Rqst Msg for IP 0.0.0.0, MAC
00:50:C2:4B:50:03 (07/12 16:16:44.093) ), but the device doesn´t get
any address from the pool, instead, it uses the last configured
address.
In my routine to write the settings to the EEPROM I do 0 out the
confnet.cdn_cip_addr before calling NutNetSaveConfig(), so that the
dhcp routine won´t skip.
My last test, I shrinked down the DHCP IP pool to 192.168.0.10-20,
and I got a different message on Tftpd, but the device still sticks
with the IP it was configured previously. Now I get:
Rcvd DHCP Discover Msg for IP 0.0.0.0, Mac 00:50:C2:4B:50:03 [07/12
16:26:52.828]
DHCP: proposed address 192.168.0.10 [07/12 16:26:52.828]
Rcvd DHCP Rqst Msg for IP 0.0.0.0, Mac 00:50:C2:4B:50:03 [07/12 16:26:56.906]
Client requested address 192.168.0.100 which was not allocated by
tftpd32 [07/12 16:26:56.906]
My routine is:
void StartNetwork(void)
{
u_long ip_addr = inet_addr("192.168.0.100");
u_long ip_mask = inet_addr("255.255.255.0");
u_char mac[6] = {0x00, 0x50, 0xC2, 0x4B, 0x50, 0x03};
printf("Setting up eth0...\n");
printf("MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0],
mac[1], mac[2], mac[3], mac[4], mac[5]);
if ( settings.useDHCP )
{
printf("Using DHCP...\n");
confnet.cdn_cip_addr = 0;
confnet.cdn_ip_addr = 0;
if( NutDhcpIfConfig("eth0", 0, 60000) && NutDhcpIfConfig("eth0",
mac, 60000) )
{
// Falha em obter IP por DHCP
printf("Failed to obtain address from DHCP server\n");
printf("Using default IP address\n");
goto useFixedIP;
}
else
return;
}
else
{
if (!NutNetLoadConfig("eth0"))
{
ip_addr = confnet.cdn_cip_addr;
ip_mask = confnet.cdn_ip_mask;
memcpy(mac, confnet.cdn_mac, 6);
printf("Loading Network settings from EEPROM\n");
}
else
printf("Loading default network settings\n");
}
useFixedIP:
confnet.cdn_cip_addr = ip_addr;
confnet.cdn_ip_mask = ip_mask;
NutNetIfConfig("eth0", mac, ip_addr, ip_mask);
}
And it outputs:
Setting up eth0...
MAC address: 00:50:C2:4B:50:03
Using DHCP...
IP: 192.168.0.100
Thanks in advance,
Thiago A. Corrêa
More information about the En-Nut-Discussion
mailing list