extmod/modnetwork.h: Increase hostname limit to 64 bytes #12403
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #10635 introduced this limit which seems rather arbirtrary and wildly insufficient to me.
A 16 bytes length limits means a 15 character string limit, which even
ubinascii.hexlify(machine.unique_id())
on most ports will break. And then assuming you just supply a random 15 byte hex string, most people won't be able to identify the hosts function in a list on their wifi routers.I wanted to set my hostname to
rpi-fan-controller-{hex_uid}
and just got a ValueError without explanation. It took me 2 hours to figure what went wrong. Because of this I added a note about the exception and limitation to the documentation.Since I didn't really understand the reason for 16 bytes I set the new limit to the size used in all involved protocols: DHCP 64 bytes, DNS 63 "octets" (characters) plus length byte, and mDNS which points to the DNS RFC. I can imagine that some ports for small boards might want to decrease the size of this statically allocated buffer, and from what I gathered from the C code it would be a simple as defining
MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN
, so I mentioned this possibility for end users in the documentation as well.