cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
arvindnr
Voyager
Voyager
4,475 Views
Registered: ‎02-10-2012

Printing the DHCP aquired configuration.

Can any one suggest how to print the newly acquired DHCP configuration after using the dhcp_start(netif) function. ?

Tags (3)
0 Kudos
4 Replies
johnmcd
Xilinx Employee
Xilinx Employee
4,472 Views
Registered: ‎02-01-2008

So in one thread after dhcp_start, manage the counters as follows:

 

    // Start the DHCP "Client Daemon"
    xil_printf("Starting DHCP_CD...\r\n");    
    dhcp_start(netif);
    while (1) {
        sleep(DHCP_FINE_TIMER_MSECS);
        dhcp_fine_tmr();
        millisec_cnt += DHCP_FINE_TIMER_MSECS;
        if (millisec_cnt >= DHCP_COARSE_TIMER_SECS*1000) {
            dhcp_coarse_tmr();
            millisec_cnt = 0;
         }
    }

 

Then in another thread, wait for the network to negotiate, then wait for an IP address to be assigned.

 

    //wait for network link to negotiate
    print("Waiting for network interface to negotiate\n\r");
    while (1) {
            sleep(500);
            if(netif_is_up(netif)) {
                   xil_printf("Network interface up\n\r");
                   break;
            }
    }
    
    // Wait for DHCP IP configuration
    while (1) {
        sleep(DHCP_FINE_TIMER_MSECS);
        if (netif->ip_addr.addr) {
            xil_printf("DHCP request success\r\n");
            break;
        }
        millisec_cnt += DHCP_FINE_TIMER_MSECS;
        if (millisec_cnt >= DHCP_TIMEOUT_MS) {
            xil_printf("ERROR: DHCP request timed out\r\n");
            return;
        }
    }            

    /* print out IP settings of the board */
    print_ip_settings(&netif->ip_addr, &netif->netmask, &netif->gw);

 

 

See attached for full main.c

0 Kudos
arvindnr
Voyager
Voyager
4,469 Views
Registered: ‎02-10-2012

Hey John 

 

i am working with a single threaded system using RAW APIs. So.. i was trying another method using the netif set status callback function . I have attached the main c file in this. Is it the correct way of doing it for a single threaded system?

I am still facing some errors so working on it. But in gereral is it the right concept?

 

0 Kudos
johnmcd
Xilinx Employee
Xilinx Employee
4,461 Views
Registered: ‎02-01-2008

Sorry but I can't help you as I haven't looked at this portion of lwip for a few years. I was hoping my working code snippet would have been enough to get you rolling.

 

One thing I would check is that your timers are working. I'm not sure what errors you've been experiencing. Also, use wireshark to make sure you are receiving dhcp responses.

0 Kudos
arvindnr
Voyager
Voyager
4,457 Views
Registered: ‎02-10-2012

Thank you John.

 

I will try and adapt your code snippet into the single threaded system . 

 

 

0 Kudos