Best practice for DHCP/Static IP config

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Best practice for DHCP/Static IP config

Bob Scheffler

Could I get a recommendation for run-time configurable DHCP/Static IP address. Sorry if this has been asked 100 times before. Just wondering what the people who actually use lwip do…

 

From monitoring the mailing list, I understand no graceful shutdown… So I am ok with a startup variable and reset the hardware to make the setting take effect. #define is not really what I am looking for.

 

Is this the right way?

  1. Start the stack
  2. Check my config for desired static IP, or DHCP requested (dip switch, config bit, etc)

netif_set_default()

if (dhcp)

        dhcp_start();

else

        netif_set_up();

 

A pointer to an example that does this, or 5 lines of pseudo code would be great!

(SAME54, lwip 2.0.3, free RTOS 10.0.0)

 

Thanks Simon, Sylvain,  Steve, Patrick, and others who are providing such great help to this list! Most of my questions are answered by just watching the emails on this list.

 

Bob

 


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for DHCP/Static IP config

goldsimon@gmx.de
Am 22.01.2019 um 09:58 schrieb [hidden email]:

> Could I get a recommendation for run-time configurable DHCP/Static IP
> address. Sorry if this has been asked 100 times before. Just wondering
> what the people who actually use lwip do…
>
>  From monitoring the mailing list, I understand no graceful shutdown… So
> I am ok with a startup variable and reset the hardware to make the
> setting take effect. #define is not really what I am looking for.
>
> Is this the right way?
>
>  1. Start the stack
>  2. Check my config for desired static IP, or DHCP requested (dip
>     switch, config bit, etc)
>
> netif_set_default()
>
> if (dhcp)
>
>          dhcp_start();
>
> else
>
>          netif_set_up();

No, that was old usage. It has been changed with 2.0.0: you now *always*
need to set the netif up. Then call dhcp_start() or net_set_addr().

> A pointer to an example that does this, or 5 lines of pseudo code would
> be great!

There is 'contrib\examples\example_app\test.c', but this file is
somewhat of a bad example since it tries to include all possible code
with ifdefs...

So:
netif_add() // either with satic IP address or call netif_set_addr() later
netif_set_default()
netif_set_up()
if (dhcp)
        dhcp_start();
else
        netif_set_addr(); // if not set with netif_add()

And remember that the netif has to set the link flag up
('netif_set_link_up()') for things to work.

> (SAME54, lwip 2.0.3, free RTOS 10.0.0)
>
> Thanks Simon, Sylvain,  Steve, Patrick, and others who are providing
> such great help to this list! Most of my questions are answered by just
> watching the emails on this list.

Good to know!

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for DHCP/Static IP config

Bob Scheffler
Thanks for your help Simon!

Bob

-----Original Message-----
Subject: Re: [lwip-users] Best practice for DHCP/Static IP config

There is 'contrib\examples\example_app\test.c', but this file is somewhat of
a bad example since it tries to include all possible code with ifdefs...

So:
netif_add() // either with satic IP address or call netif_set_addr() later
netif_set_default()
netif_set_up()
if (dhcp)
        dhcp_start();
else
        netif_set_addr(); // if not set with netif_add()

And remember that the netif has to set the link flag up
('netif_set_link_up()') for things to work.

> Thanks Simon, Sylvain,  Steve, Patrick, and others who are providing
> such great help to this list! Most of my questions are answered by
> just watching the emails on this list.

Good to know!

Regards,
Simon


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users