Page 1 of 1

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

Posted: Sun Mar 07, 2021 11:25 pm
by zliudr
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.

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

Posted: Thu Mar 11, 2021 12:23 pm
by ESP_Jan
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

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

Posted: Thu Mar 11, 2021 1:56 pm
by zliudr
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.