← index #15118PR #9086
Related · high · value 1.047
QUERY · ISSUE

network.hostname: max length of hostname

openby massimosalaopened 2024-05-25updated 2024-06-18
enhancement

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.
CANDIDATE · PULL REQUEST

extmod/mod_network: Define network hostname globally for all nic boards.

closedby omogenotopened 2022-08-23updated 2022-10-05
extmod

This PR proposes to globally move hostname definition to the network module, so that it will be defined for all nic boards by using the network.hostname() method. The default host name is set to mp-host and the hostname length is controlled by the MICROPY_PY_HOSTNAME_LENGTH constant which is defaulted to 32 if not defined.

>>> import network
>>> network.hostname("my-host")
>>> network.hostname()
'my-host'
>>>

Note: This PR would replace some of the modifications done specifically for the cyw43 board only (PR #8918), but keeps the ioctl functions up and running using this global hostname definition.

If the nic board uses the LWIP library, we take advantage of the integrated mDNS server (if the LWIP_MDNS_RESPONDER constant is defined) to declare hostname for that nic board.

>>> import network
>>> network.hostname("my-host")
>>> nic = network.WIZNET5K()
>>> nic.active(True)
>>> nic.ifconfig("dhcp")  
>>> # nic.ifconfig(("192.168.1.100", "255.255.255.0", "0.0.0.0", "0.0.0.0"))  # for fixed IP

From now on, on the network, you can perform a ping my-host.local to get a response from your micropython board.
I could not test these modifications for all nic boards, I have only WIZNET5K boards available.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied