Customizing lwip hostname

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

Customizing lwip hostname

Postby ulikoehler » Tue Sep 01, 2015 4:42 pm

Hi,
currently the DHCP hostname for lwIP is always set to "lwip". I'd like to suggest making it configurable via a preprocessor definition:

Current code in lwipthread.c:

Code: Select all

#if LWIP_NETIF_HOSTNAME
  /* Initialize interface hostname */
  netif->hostname = "lwip";
#endif /* LWIP_NETIF_HOSTNAME */


I'd suggest using an optional preprocessor definition like this:


Code: Select all

#if LWIP_NETIF_HOSTNAME
  /* Initialize interface hostname */
#ifdef CHIBIOS_NETIF_HOSTNAME
  netif->hostname = CHIBIOS_NETIF_HOSTNAME;
#else
  netif->hostname = "lwip";
#endif
#endif /* LWIP_NETIF_HOSTNAME */


CHIBIOS_NETIF_HOSTNAME could then be defined in chconf.h. Another option would be to name the preprocessor definition LWIP_NETIF_HOSTNAME, but as far as I understand it, this would mean changing the standard lwipopts.h.

Please feel free to comment on this.

Best regards, Uli

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Customizing lwip hostname

Postby steved » Tue Sep 01, 2015 9:08 pm

Good point - host name is frequently going to need to be configurable, and usually different for each unit.

So I propose an approach which builds on your suggestion.

If you look in this thread, you'll see that I've proposed an extension to the initialisation structure to pass DHCP/static address status.

I suggest that we further extend this structure to include a pointer to the host name. If a NULL pointer is passed, then the name defaults to a fixed string, as per your suggestion.

On a quick look this would be quite straightforward code to include in lwipthread.c - two extra lines over your proposal, I think:
a) In THD_FUNCTION(lwip_thread, p) where the IP address is set, add

Code: Select all

netif->hostname = opts->ourHostName


b) In ethernetif_init() change to something like:


Code: Select all

#ifndef LWIP_NETIF_HOSTNAME
#define LWIP_NETIF_HOSTNAME "lwip"
#endif
if (!netif->hostname)
{
#ifdef CHIBIOS_NETIF_HOSTNAME
netif->hostname = CHIBIOS_NETIF_HOSTNAME;
#else
netif->hostname = LWIP_NETIF_HOSTNAME;
#endif
}


(I am of the opinion that the hostname should always be set to something).

I'll make a note to look further into this, unless you beat me to it!

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Customizing lwip hostname

Postby steved » Fri Sep 04, 2015 11:14 am

I've added this here


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 16 guests