[En-Nut-Discussion] DHCP

Harald Kipp harald.kipp at egnite.de
Fri Dec 2 10:12:08 CET 2011


Hi Michael,

On 02.12.2011 00:26, Michael Hellwig wrote:
> [1.DHCP-BOUND 12]
> [1.DHCP-BOUND 640]
> [1.DHCP-ERROR 1]
> 
> 
> After 640 seconds the dhcpc-thread reaches line 1476 and doesn't
> recover from the idle state anymore.
> 
>              if (dhcpApiTimeout <= tt) {
>                  dhcpError = DHCPERR_TIMEOUT;
>                  dhcpState = DHCPST_IDLE;
>                  continue;
>              }

Confirmed. I used a simple test program with Nut/OS 4.8.9:

#include <dev/board.h>
#include <sys/version.h>
#include <sys/timer.h>
#include <sys/confnet.h>
#include <arpa/inet.h>
#include <pro/dhcp.h>
#include <stdio.h>

int main(void)
{
    NutRegisterDevice(&DEV_DEBUG, 0, 0);
    freopen(DEV_DEBUG_NAME, "w", stdout);
    printf_P("DHCP-Test - Nut/OS %s\n", NutVersionString());

    printf("Register...");
    if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
        puts("failed");
    } else {
        puts("OK");
    }
    /* NutRegister returns too fast on the EIR. */
    NutSleep(3000);
    printf("Configure...");
    if (NutDhcpIfConfig("eth0", 0, 5000)) {
        puts("failed");
    } else {
        puts("OK");
        printf("IP: %s\n", inet_ntoa(confnet.cdn_ip_addr));
    }

    for (;;) {
        NutSleep(5000);
    }
    return 0;
}

Here is the Makefile (note tabs below clean):

PROJ=testdhcp
include ../Makedefs
SRCS=$(PROJ).c dhcpc.c
OBJS=$(SRCS:.c=.o)
LIBS=$(LIBDIR)/nutinit.o -lnutpro -lnutnet -lnutos \
      -lnutcrt -lnutdev -lnutarch
TARG=$(PROJ).hex
PARM=$(PROJ).eep
all: $(OBJS) $(TARG) $(ITARG) $(DTARG)
include ../Makerules
clean:
	-rm -f $(OBJS)
	-rm -f $(TARG) $(ITARG) $(DTARG)
	-rm -f $(PROJ).map
	-rm -f $(SRCS:.c=.lst)

Before running make, copy dhcpc.c into the application directory.

I got

[1.DHCP-INIT]
[1.DHCP-REBOOTING 192.168.192.207][DHCP-Send to
255.255.255.255][DHCP-Recv from 192.168.192.1][DHCP-Opt-
53][DHCP-Opt-1][DHCP-Opt-3][DHCP-Opt-6][DHCP-Opt-12][DHCP-Opt-15][DHCP-Opt-28][DHCP-Opt-38][DHCP-Opt-51]
[DHCP-Opt-54][DHCP-Opt-58][DHCP-Opt-59]
[2.DHCP-BOUND 0][DHCP-Config 192.168.192.207]
[1.DHCP-BOUND 0]OK
IP: 192.168.192.207

and after a while

[1.DHCP-BOUND 125]
[1.DHCP-ERROR 1]

Looks to me, that the dhcpApiTimeout needs to be cleared on DHCP-BOUND.
But I'm not yet sure.

Regards,

Harald



More information about the En-Nut-Discussion mailing list