diff options
author | Jared Hancock <jared.hancock@centeredsolutions.com> | 2024-10-14 09:19:10 -0500 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-10-23 16:29:28 +1100 |
commit | 078ead24f392deedaad2f391baac4aaefe96f49b (patch) | |
tree | 0a5aaf204f8fa8d16b3d4eaf5634e6ae82f82a1d /extmod/network_wiznet5k.c | |
parent | 3f54e5dff27a135dff8a53a0483e5bb3a8b9a522 (diff) |
extmod/network_wiznet5k: Reset mDNS when interface is brought up.
The LwIP interface is removed in wiznet5k_deinit() which is called as part
of the init sequence. Therefore, if using mDNS, then the interface will
need to be re-added when bringing the interface up.
Additionally, this allows to set the hostname from MicroPython code prior
to bringing the interface up and mDNS responding to the (new) hostname.
This allows the hostname to be configured and saved on the flash or be
based on dynamic information such as the MAC or unique_id().
Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
Diffstat (limited to 'extmod/network_wiznet5k.c')
-rw-r--r-- | extmod/network_wiznet5k.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/extmod/network_wiznet5k.c b/extmod/network_wiznet5k.c index 96f9b6131..533d39a18 100644 --- a/extmod/network_wiznet5k.c +++ b/extmod/network_wiznet5k.c @@ -58,6 +58,7 @@ #include "shared/netutils/netutils.h" #include "lib/wiznet5k/Ethernet/wizchip_conf.h" #include "lib/wiznet5k/Ethernet/socket.h" +#include "lwip/apps/mdns.h" #include "lwip/err.h" #include "lwip/dns.h" #include "lwip/dhcp.h" @@ -201,6 +202,9 @@ static void wiznet5k_config_interrupt(bool enabled) { void wiznet5k_deinit(void) { for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) { if (netif == &wiznet5k_obj.netif) { + #if LWIP_MDNS_RESPONDER + mdns_resp_remove_netif(&wiznet5k_obj.netif); + #endif netif_remove(netif); netif->flags = 0; break; @@ -334,6 +338,12 @@ static void wiznet5k_lwip_init(wiznet5k_obj_t *self) { self->netif.flags |= NETIF_FLAG_UP; dhcp_start(&self->netif); self->netif.flags &= ~NETIF_FLAG_UP; + + #if LWIP_MDNS_RESPONDER + // NOTE: interface is removed in ::wiznet5k_deinit(), which is called as + // part of the init sequence. + mdns_resp_add_netif(&self->netif, mod_network_hostname_data); + #endif } void wiznet5k_poll(void) { |