network.hostname: max length of hostname
Checks
-
I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.
-
I've searched for existing issues regarding this feature, and didn't find any.
Description
Form the docs: the max length depends on the port (and its tcp/ip stack).
So, without spelunking into each network low-level libraries or make tests on each specific board, we don't know the limit.
Proposal: calling hostname(None) returns the accepted max length of hostname.
Code Size
No response
Implementation
- I intend to implement this feature and would submit a Pull Request if desirable.
extmod/modnetwork.c: Increase max hostname length to 32.
See also earlier PRs #12403 and #12404.
This changes from the previous limit of 15 characters. Although DHCP and mDNS allow for up to 63, ESP32 and ESP8266 only allow 32, so this seems like a reasonable limit to enforce across all ports (and avoids wasting the additional memory).
Also clarifies that MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN does not include the null terminator (which was unclear before).
This work was funded through GitHub Sponsors.