MK66 LWIP hostname

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MK66 LWIP hostname

3,458 Views
ryan_pearson
Contributor III

I'm using a combination of lwip_dhcp and lwip_udpecho examples. I want to be able to use the hostname for utilities such as ping, and functions such as gethostbyname from winsock.h.

In opt.h line 1585, I made this change to enable a hostname (changed the zero to a 1)

#if !defined LWIP_NETIF_HOSTNAME || defined __DOXYGEN__
#define LWIP_NETIF_HOSTNAME 1
#endif

 

In the main function of lwip_udpecho_bm.c, I added netif_set_hostname and dhcp_start:

 netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, &fsl_enet_config0, ethernetif0_init,
ethernet_input);
netif_set_default(&fsl_netif0);
netif_set_up(&fsl_netif0);

netif_set_hostname(&fsl_netif0, "ryanhost");

dhcp_start(&fsl_netif0);

 

DHCP happens successfully, and the MK66 is assigned an IP address. I can see the IP and and "ryanhost" name in the router's device list. However, using the hostname in ping ("ping ryanhost") or the gethostbyname does not work. I can use ping and gethostbyname with other devices connected to the router. I tried placing netif_set_hostname at various spots in the code, and it did not make a difference.

Can anyone help with getting hostname usable?

0 Kudos
Reply
15 Replies

3,431 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Ryan:

 

Could you please let me know the SDK version you are using?

 

Regards

Daniel

0 Kudos
Reply

3,406 Views
ryan_pearson
Contributor III

I took a look at the latest SDK and it does seem like there are quite a bit of differences. I am willing to update my SDK.

0 Kudos
Reply

3,386 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @ryan_pearson 

 

Please refer to below for how to use hostname.

 I am using SDK 2.9,   demo lwip_dhcp_bm.

add one line 

netif_set_hostname(&netif, "daniel");   to lwip_dhcp_bm.c

danielchen_0-1615190295310.png

Enabled LWIP_NETIF_HOSTNAME   1  in lwipopts.h

danielchen_1-1615190397927.png

 

My test result is OK.

 

danielchen_3-1615190505027.png

 

Regards

Daniel

 

 

0 Kudos
Reply

3,345 Views
ryan_pearson
Contributor III

I moved to the FRDM-K66F board, and still am not able to use the hostname. I'm running the frdmk66f_lwip_dhcp_bm example with the 2 lines added.

netif_set_hostname(&netif, "daniel");   to lwip_dhcp_bm.c

Enabled LWIP_NETIF_HOSTNAME   1  in lwipopts.

 

Could you let me know if you're using a dev board, and which one. And could you give me your source code, in case we have more differences?

 

0 Kudos
Reply

3,332 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @ryan_pearson 

 

Please see the attached code, I am using Frdm-k66.

 

Regards

Daniel

0 Kudos
Reply

3,319 Views
ryan_pearson
Contributor III

Hi @danielchen, I built and ran your code on my frdm-k66 board. "ping daniel" did not work.

1. Can you give me a link to the SDK that you used? I used this one that I built: https://mcuxpresso.nxp.com/download/e4cfb7473a33493f615d24994776f8d4

2. What OS are you using? I'm on windows 10.

3. Can you send the .axf binary that works for you?

Thanks

0 Kudos
Reply

3,292 Views
danielchen
NXP TechSupport
NXP TechSupport

 

Hi @ryan_pearson 

We are using the same SDK.  I am using Win10. The difference is the DHCP server.

API netif_set_hostname only adds a member to the netif structure for a name.

It needs DNS server to translate from a name to an address.  Maybe my server done all for me.

 

I would suggest you take a look at below link, it seems very similar issue as yours.

http://lwip.100.n7.nabble.com/DHCP-LWIP-NETIF-HOSTNAME-1-for-IP-retrieving-td6423.html

 

Regards

Daniel

0 Kudos
Reply

3,288 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @ryan_pearson :

My pc get an ip address through DHCP, you can see there is an DNS suffix, also  a domain name.

danielchen_0-1615793984707.png

when you ping hostname, system will search the name in DNS.  if there is no record in DNS , ping will fail.

But ping ip address will be ok.  

 

Regards

Daniel

0 Kudos
Reply

3,376 Views
ryan_pearson
Contributor III

Ok, thanks. I had changed my project to use SDK 2.9, but DHCP stopped working after that. I'll try to figure out why DHCP no longer works.

0 Kudos
Reply

3,368 Views
ryan_pearson
Contributor III

I built my project with 2.9. I'm still having the same problem with host name. I have my mk66 hardware connected to a router, and my PC connected to the same router. Nothing else is connected to the router. My mk66 is assigned an IP address of 192.168.1.3. It's interesting that your IP is not a subnet address. How is your hardware connected to your PC?

0 Kudos
Reply

3,294 Views
danielchen
NXP TechSupport
NXP TechSupport

 

Hi @ryan_pearson 

We are using the same SDK. The difference is the DHCP server.

API netif_set_hostname only adds a member to the netif structure for a name.

It needs DNS server to translate from a name to an address.  Maybe my server done all for me.

 

I would suggest you take a look at below link, it seems very similar issue as yours.

http://lwip.100.n7.nabble.com/DHCP-LWIP-NETIF-HOSTNAME-1-for-IP-retrieving-td6423.html

 

Regards

Daniel

0 Kudos
Reply

3,272 Views
ryan_pearson
Contributor III

Thanks @danielchen , this helped! The link to the source files in the thread is broken, so I found them elsewhere. I had to change a few lines to have it work with a newer SDK. I've attached them.

3,358 Views
danielchen
NXP TechSupport
NXP TechSupport

My PC connects to my office DHCP server through WIFI.

My board connects to my office DHCP server  through Cable.

 

Regards

Daniel

0 Kudos
Reply

3,354 Views
ryan_pearson
Contributor III

My hardware is assigned an IP address of 192.168.1.3 by the router. Please let me know if you have any other suggestions. I'm experiencing the same issue of not being able to use the host name on a DHCP server at the office, and a DHCP router at home.

0 Kudos
Reply

3,424 Views
ryan_pearson
Contributor III

Version 2.6.0.

0 Kudos
Reply