cancel
Showing results for 
Search instead for 
Did you mean: 

lwIP can't assign hostname (until I modify STM32CubeIDE generated code...)

Spaghetto
Associate III

Hello folks,
I'm working on a TCP Server implementation on a custom board using Ethernet communication with a STM32F107VCT6 in STM32CubeIDE and I've found a problem in the LWIP generated code (to be sincere the same problem has been verified by me occurring also on a NUCLEO-F439ZI board).

No matter as long I set Device Configuration Tool (.ioc file) in LWIP/Key Options/Network Interfaces Options

LWIP_ENABLE_NETIF_HOSTNAME > Enabled
LWIP_NETIF_HOSTNAME > myhostname

No hostname is provided by the board which I correctly ping via IP (but not via hostname) and run correctly the TCP Server application). The board have been tested in different networks and checked both via "ping -a my_ip" and directly in the router tables).

Diving a little into the generated code in LWIP/Target/lwipopts.h correctly get:

 

 

/*----- Default Value for LWIP_ENABLE_NETIF_HOSTNAME: 0 ---*/
#define LWIP_ENABLE_NETIF_HOSTNAME 1
/*----- Default Value for LWIP_NETIF_HOSTNAME: lwip ---*/
#define LWIP_NETIF_HOSTNAME "myhostname"

 

 

but in LWIP/Target/ethernetif.h I get:

 

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

 

other occurrences in Middlewares/Third_Party/ LwIP/netif.h are similar, just as example:

 

 

#if LWIP_NETIF_HOSTNAME
/** @ingroup netif */
#define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
/** @ingroup netif */
#define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
#endif /* LWIP_NETIF_HOSTNAME */

 

 

Debugging the code all the pragmas "#if LWIP_NETIF_HOSTNAME" appear to be ignored therefore the code is not compiled, hint: before compiling the Macro Expansion on the LWIP_NETIF_HOSTNAME says "0".

But if I deliberately modify manually (after the automatic code generation):

 

 

#define LWIP_NETIF_HOSTNAME 1 //myhostname

 

 

It start working flawlessly (the #if are enabled, the code is compiled, and i can ping the hostname directly). :\

 

Am I doing something wrong in configuring the ioc file or...maybe...all the "#if LWIP_NETIF_HOSTNAME" in the generated code should actually be a more reasoneable "#if LWIP_ENABLE_NETIF_HOSTNAME"?

Thanks

3 REPLIES 3
Spaghetto
Associate III

up

Pavel A.
Evangelist III

#bugreport

When a macro is defined as a string, using it in #if directive is a syntax error.

So instead of #if LWIP_NETIF_HOSTNAME  there must be #if LWIP_ENABLE_NETIF_HOSTNAME

Or use #ifdef LWIP_NETIF_HOSTNAME

Looking to the issue with a cold mind... It makes no sense the LWIP/Target/lwipopts.h   "#define LWIP_NETIF_HOSTNAME "myhostname"" since the string is loaded by the code generator in plain sight in the LWIP/Target/ethernetif.h and never used by the compiler to assign hostname...

Since the lwIP are third-part libraries, LWIP_NETIF_HOSTNAME can't be anything but a binary value (Enabled\Disabled), also used in the same place of LWIP_ENABLE_NETIF_HOSTNAME (they have the same purpose), then the .ioc file should accept an additional variable to fire the string in the code...

I'm actually getting around this (bug?) without manual modifications of the automatic generated code adding in LWIP/Target/lwipopts.h a sort of redefine (it comes after the automatic defines in the user code area, which don't get overwritten when regenerating code):

 

/* USER CODE BEGIN 1 */
 
 #ifdef LWIP_NETIF_HOSTNAME
 	#undef LWIP_NETIF_HOSTNAME
 	#define LWIP_NETIF_HOSTNAME 1
 #endif
 
/* USER CODE END 1 */

 

Thanks