Skip to content

Commit 6ed07ee

Browse files
committed
extmod/network: Implement IPv6 API to set and get nic configuration.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
1 parent d712feb commit 6ed07ee

File tree

7 files changed

+350
-1
lines changed

7 files changed

+350
-1
lines changed

extmod/modlwip.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#if MICROPY_PY_LWIP
3939

4040
#include "shared/netutils/netutils.h"
41+
#include "modnetwork.h"
4142

4243
#include "lwip/init.h"
4344
#include "lwip/tcp.h"
@@ -353,8 +354,12 @@ static void lwip_socket_free_incoming(lwip_socket_obj_t *socket) {
353354
}
354355
}
355356

357+
#if LWIP_VERSION_MAJOR < 2
358+
#define IPADDR_STRLEN_MAX 46
359+
#endif
356360
mp_obj_t lwip_format_inet_addr(const ip_addr_t *ip, mp_uint_t port) {
357-
char *ipstr = ipaddr_ntoa(ip);
361+
char ipstr[IPADDR_STRLEN_MAX];
362+
ipaddr_ntoa_r(ip, ipstr, sizeof(ipstr));
358363
mp_obj_t tuple[2] = {
359364
tuple[0] = mp_obj_new_str(ipstr, strlen(ipstr)),
360365
tuple[1] = mp_obj_new_int(port),
@@ -1750,7 +1755,11 @@ static mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
17501755
state.status = 0;
17511756

17521757
MICROPY_PY_LWIP_ENTER
1758+
#if LWIP_VERSION_MAJOR < 2
17531759
err_t ret = dns_gethostbyname(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state);
1760+
#else
1761+
err_t ret = dns_gethostbyname_addrtype(host, (ip_addr_t *)&state.ipaddr, lwip_getaddrinfo_cb, &state, mp_mod_network_prefer_dns_use_ip_version == 4 ? LWIP_DNS_ADDRTYPE_IPV4_IPV6 : LWIP_DNS_ADDRTYPE_IPV6_IPV4);
1762+
#endif
17541763
MICROPY_PY_LWIP_EXIT
17551764

17561765
switch (ret) {

extmod/modnetwork.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,18 @@ mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args) {
141141
}
142142
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_hostname_obj, 0, 1, mod_network_hostname);
143143

144+
#if LWIP_VERSION_MAJOR >= 2
145+
MP_DEFINE_CONST_FUN_OBJ_KW(mod_network_ipconfig_obj, 0, mod_network_ipconfig);
146+
#endif
147+
148+
144149
static const mp_rom_map_elem_t mp_module_network_globals_table[] = {
145150
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) },
146151
{ MP_ROM_QSTR(MP_QSTR_country), MP_ROM_PTR(&mod_network_country_obj) },
147152
{ MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&mod_network_hostname_obj) },
153+
#if LWIP_VERSION_MAJOR >= 2
154+
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&mod_network_ipconfig_obj) },
155+
#endif
148156

149157
// Defined per port in mpconfigport.h
150158
#ifdef MICROPY_PORT_NETWORK_INTERFACES

extmod/modnetwork.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,18 @@ extern char mod_network_hostname_data[MICROPY_PY_NETWORK_HOSTNAME_MAX_LEN + 1];
6969
mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args);
7070

7171
#if MICROPY_PY_LWIP
72+
73+
#include "lwip/init.h"
74+
7275
struct netif;
7376
void mod_network_lwip_init(void);
7477
void mod_network_lwip_poll_wrapper(uint32_t ticks_ms);
7578
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args);
79+
#if LWIP_VERSION_MAJOR >= 2
80+
mp_obj_t mod_network_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
81+
mp_obj_t network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
82+
extern int mp_mod_network_prefer_dns_use_ip_version;
83+
#endif
7684
#elif defined(MICROPY_PORT_NETWORK_INTERFACES)
7785

7886
struct _mod_network_socket_obj_t;

extmod/network_cyw43.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ static mp_obj_t network_cyw43_ifconfig(size_t n_args, const mp_obj_t *args) {
321321
}
322322
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_ifconfig_obj, 1, 2, network_cyw43_ifconfig);
323323

324+
static mp_obj_t network_cyw43_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
325+
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]);
326+
return network_nic_ipconfig(&self->cyw->netif[self->itf], n_args - 1, args + 1, kwargs);
327+
}
328+
MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_ipconfig_obj, 1, network_cyw43_ipconfig);
329+
324330
static mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) {
325331
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]);
326332
(void)self;
@@ -535,6 +541,8 @@ static const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = {
535541
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_cyw43_status_obj) },
536542
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_cyw43_config_obj) },
537543

544+
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&network_cyw43_ipconfig_obj) },
545+
538546
// Class constants.
539547
{ MP_ROM_QSTR(MP_QSTR_PM_NONE), MP_ROM_INT(PM_NONE) },
540548
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) },

extmod/network_esp_hosted.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ static mp_obj_t network_esp_hosted_ifconfig(size_t n_args, const mp_obj_t *args)
204204
}
205205
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_esp_hosted_ifconfig_obj, 1, 2, network_esp_hosted_ifconfig);
206206

207+
static mp_obj_t network_esp_hosted_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
208+
esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]);
209+
void *netif = esp_hosted_wifi_get_netif(self->itf);
210+
return network_nic_ipconfig(netif, n_args - 1, args + 1, kwargs);
211+
}
212+
MP_DEFINE_CONST_FUN_OBJ_KW(network_esp_hosted_ipconfig_obj, 1, network_esp_hosted_ipconfig);
213+
214+
207215
static mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
208216
esp_hosted_obj_t *self = MP_OBJ_TO_PTR(args[0]);
209217

@@ -299,6 +307,7 @@ static const mp_rom_map_elem_t network_esp_hosted_locals_dict_table[] = {
299307
{ MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&network_esp_hosted_disconnect_obj) },
300308
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_esp_hosted_isconnected_obj) },
301309
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_esp_hosted_ifconfig_obj) },
310+
{ MP_ROM_QSTR(MP_QSTR_ipconfig), MP_ROM_PTR(&network_esp_hosted_ipconfig_obj) },
302311
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_esp_hosted_config_obj) },
303312
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_esp_hosted_status_obj) },
304313
{ MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(ESP_HOSTED_SEC_OPEN) },

0 commit comments

Comments
 (0)
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