diff --git a/docs/library/network.rst b/docs/library/network.rst index d05d17132dc67..2d856ab0fa4a5 100644 --- a/docs/library/network.rst +++ b/docs/library/network.rst @@ -124,6 +124,11 @@ parameter should be `id`. server via DHCP. This method does not block and wait for an address to be obtained. To check if an address was obtained, use the read-only property ``has_dhcp4``. + * ``autoconf4`` (``True/False``) obtain an IPv4 address randomly in the + 169.254.0.0/16 address space. This method does not block and wait for + an address to be selected and confirmed to be unused on the network. To + check if an address has been selected, use the read-only property + ``has_autoconf4``. * ``gw4`` Get/set the IPv4 default-gateway. * ``dhcp6`` (``True/False``) obtain a DNS server via stateless DHCPv6. Obtaining IP Addresses via DHCPv6 is currently not implemented. diff --git a/extmod/network_lwip.c b/extmod/network_lwip.c index 9cfab6ef4cb53..bb349f9e8379c 100644 --- a/extmod/network_lwip.c +++ b/extmod/network_lwip.c @@ -39,6 +39,7 @@ #include "lwip/netif.h" #include "lwip/timeouts.h" +#include "lwip/autoip.h" #include "lwip/dns.h" #include "lwip/dhcp.h" #include "lwip/nd6.h" @@ -191,6 +192,11 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o case MP_QSTR_has_dhcp4: { return mp_obj_new_bool(dhcp_supplied_address(netif)); } + #if LWIP_AUTOIP + case MP_QSTR_has_autoconf4: { + return mp_obj_new_bool(autoip_supplied_address(netif)); + } + #endif #if LWIP_IPV6_DHCP6 case MP_QSTR_dhcp6: { struct dhcp6 *dhcp = netif_dhcp6_data(netif); @@ -268,6 +274,11 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o dhcp_renew(netif); } else { dhcp_release_and_stop(netif); + #if LWIP_AUTOIP + if (autoip_supplied_address(netif)) { + autoip_stop(netif); + } + #endif dhcp_start(netif); } } else { @@ -275,6 +286,12 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o } break; } + #if LWIP_AUTOIP + case MP_QSTR_autoconf4: { + dhcp_release_and_stop(netif); + autoip_start(netif); + } + #endif #if LWIP_IPV6_DHCP6 case MP_QSTR_dhcp6: { dhcp6_disable(netif); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy