esp_netif_set_hostname() doc host name max length should be 31. Incorrect doc

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

esp_netif_set_hostname() doc host name max length should be 31. Incorrect doc

Postby zliudr » Sun Mar 07, 2021 11:25 pm

Here is the doc:

https://docs.espressif.com/projects/esp ... tif_tPKc Says max host name is 32. Triggered assertion from lwip about host name too long:
assertion "DHCP: hostname is too long!" failed: file "C:/Users/user/.espressif/esp-idf-v4.3-beta1/components/lwip/lwip/src/core/ipv4/dhcp.c", line 1655, function: dhcp_option_hostname
Through trial and error is was 31 bytes plus \0.

ESP_Jan
Posts: 42
Joined: Tue Dec 01, 2020 10:56 am

Re: esp_netif_set_hostname() doc host name max length should be 31. Incorrect doc

Postby ESP_Jan » Thu Mar 11, 2021 12:23 pm

Hi zliudr,

I believe the documentation is correct. In the C language, "strings" are null byte terminated. So the hostname parameter is 32 bytes including the null byte.

Feel free to post any follow-up questions.

Jan

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

Re: esp_netif_set_hostname() doc host name max length should be 31. Incorrect doc

Postby zliudr » Thu Mar 11, 2021 1:56 pm

I was able to use a 32-byte long string with IDF V3.3 A C-string's length is strlen(str), which doesn't report the termination byte. A C-string's memory usage is length+1. This point should be emphasized. Host name is not about memory usage, but length of a C-string.

Who is online

Users browsing this forum: No registered users and 127 guests