[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] fixed IP and DCHP on the same net interface?

From: Oliver Schindler
Subject: Re: [lwip-users] fixed IP and DCHP on the same net interface?
Date: Wed, 17 Dec 2008 01:05:22 +0100
User-agent: Thunderbird (Windows/20081105)

Hi all,
i'm facing the same problem, but my solution was, to put the fallback into the dhcp-timeout. Means: Startup the dhcp with , if it is getting an
ip , everything is o.k. , if not the static IP is used . ( see below ..)
The disadvantage of this is, that it takes 20 seconds, before the static IP is used. For me this is o.k., because the static IP is only used with
laptop and crossover-cable to configure the target.


static void
dhcp_timeout(struct netif *netif)
struct dhcp *dhcp = netif->dhcp;

LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_timeout()\n"));
/* back-off period has passed, or server selection timed out */
if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout(): No DHCP , giving up\n"));
// dhcp_release(netif);
dhcp_set_default(netif); /* Giving up */
/* receiving the requested lease timed out */
} else if (dhcp->state == DHCP_REQUESTING) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out\n"));
if (dhcp->tries <= 5) {
} else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
dhcp_set_default(netif); /* Giving up */
// dhcp_discover(netif);
--- snip ---

void dhcp_set_default(struct netif *netif){

struct ip_addr xIpAddr, xNetMast, xGateway;
struct dhcp *dhcp = netif->dhcp;

/* Timeout on first try, so set up static ip */

IP4_ADDR( &xIpAddr, cur_ip[0], cur_ip[1], cur_ip[2], cur_ip[3] );
IP4_ADDR( &xNetMast, cur_netmask[0], cur_netmask[1], cur_netmask[2], cur_netmask[3] ); IP4_ADDR( &xGateway, cur_gateway[0], cur_gateway[1], cur_gateway[2], cur_gateway[3] );
/* set the default IP address for the interface */
netif_set_ipaddr(netif, &xIpAddr);
netif_set_gw(netif, &xGateway);
netif_set_netmask(netif, &xNetMast);
/* bring the interface up */
/* netif is now bound to DHCP leased address */
dhcp_set_state(dhcp, DHCP_BOUND);



bill schrieb:


In my Ethernet driver, I’ve done the following to allow an attempt at DHCP with a fallback to a static IP.

int dhcpFallbackTimer = GetmSTimer() + 5000; // 5 seconds

while( ! netif_is_up( netif_default ) )


// Waiting for fallback

if( (int) GetmSTimer() - dhcpFallbackTimer > 0 )


struct ip_addr sn_mask, gw_addr;

netif_set_down( netif_default );

netif_set_addr( netif_default, &ip, &netmask, &gateway ); // Fallback address

netif_set_up( netif_default );




The fallback address is something the user can configure, but it starts out as a 169.254 address with the last 2 bytes formed from the MAC address (so the installer knows what the fallback address is).

Hope this helps,


*From:* address@hidden [mailto:address@hidden *On Behalf Of *Piero 74
*Sent:* Tuesday, December 16, 2008 11:09 AM
*To:* Mailing list for lwIP users
*Subject:* Re: [lwip-users] fixed IP and DCHP on the same net interface?

i found a solution... but i "forced" stack implementation guidelines...

I did a post to lwip_dev with this idea... because i need a feedback... here a copy.


Hi all.

I found a solution for my problem, but i need community feedback.

The problem is:

I have my ip board, and i need to simplify the installer work.

So, in a business LAN with a DHCP server, the idea is to have FW which starts, as default, with DHCP client enabled, get an IP to himself, and the installer can read the IP using

'ping <nomeHOST>' (i used code found in forum for NBNS.. very good code!!! Thanks Alain!)

After this, a professional installer could decide tho disable DHCP client and use a fixed IP, through our SW which changes IP board setting.

Ok... but the problem happens if the installer put the board in a small LAN without DHCP or try to connect it directly to his pc using eth cable.

In this case i need a fixed IP.

I tried to use a net interface with fixed IP, and after start DHCP client... in my company LAN DHCP server doesn't answer (or routers block broadcast packet with src IP different than

So, my solution, is:

- create TWO interfaces on the same HW, one with fixed IP and one with DHCP on and ip =

- i changed code in ethernetif scheleton, in function ethernetif_input() in this way:


switch (htons(ethhdr->type)) {


/* PPPoE packet? */


// not implemented additional code


// not implemented additional code

#endif /* PPPOE_SUPPORT */

/* IP or ARP packet? */


/* test*/

// create a copy of pbuf for each netif. ONLY for ARP packet

for( netifCurr = netifLocal; netifCurr != NULL; netifCurr = netifCurr->next )


ptemp = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_POOL);

if (ptemp != NULL)



pbuf_header(ptemp, -ETH_PAD_SIZE); // drop the padding word


pbuf_copy(ptemp, p);

// full packet send to tcpip_thread to process

if (netifCurr->input(ptemp, netifCurr)!=ERR_OK)


LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: ARP input error\n"));


ptemp = NULL;




pbuf_free(p); // free original pbuf




/* full packet send to tcpip_thread to process */

// if there are multiple interface on the same emac hw, send to first interface

// ip layer will route packets to correct netif

if (netifLocal->input(p, netifLocal)!=ERR_OK)


LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));


p = NULL;


ret = TRUE;




p = NULL;





so.. now i duplicate ARP packets and send a copy of each interface, and use always the first interface for IP packet, because IP layer route packet between interfaces

In this way, until board gets IP from DHCP, it answers using fixed IP, after it answers using dynamic IP

Any comment??


2008/12/16 Alain M. <address@hidden <mailto:address@hidden>>

The real question is: do you really want to do that? what if you connect 2 cameras, what happens? plus the problem on another message...

IMHO, this would work better:
try DHCP for some time, withou any ip, then use autoip...


Piero 74 escreveu:

    Hi all

    I tested a network camera, which seems work in this way:

    it has a DHCP client inside, which starts on power on. But until
    an IP from DHCP server is available, it answers on fixed ip (i.e.

    Can i do the same using lwip?

    I tried to bring up an interface with fixed IP and after start
    DHCP, but it doesn't work: i didn't receive a new ip address from
    DHCP server.

    I saw DHCP traffic using wireshark: in normal situation, DHCP
    client sends packet from to broadcast, and the server
    answers, in my situation i have DHCP request from to
    i suppose this could be the problem

    Any idea??


lwip-users mailing list
address@hidden <mailto:address@hidden>


lwip-users mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]