diff options
author | Felix Dörre <felix@dogcraft.de> | 2024-02-22 01:09:05 +0000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-02-26 12:34:59 +1100 |
commit | d2bcb8597e88fccd496b6b0e358347f4bf6a15da (patch) | |
tree | 8b6d2858396600ed87c49a5a95295131ccae5e01 /extmod/modlwip.c | |
parent | 8547a782750c12a163e0cd022fefc2aaaa4b1bb7 (diff) | |
download | micropython-d2bcb8597e88fccd496b6b0e358347f4bf6a15da.tar.gz micropython-d2bcb8597e88fccd496b6b0e358347f4bf6a15da.zip |
extmod/modlwip: Add back support for empty IP addresses.
Prior to commit 628abf8f25a7705a2810fffe2ca6ae652c532896 which added IPv6
support, binding a socket with
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", PORT))
was possible. But, the empty string is not regarded as a valid IP address
by lwip. This commit adds a special case for the empty IP string,
restoring the previous CPython-compatible behaviour.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
Diffstat (limited to 'extmod/modlwip.c')
-rw-r--r-- | extmod/modlwip.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index a6630c693c..f1242b0461 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -367,8 +367,16 @@ mp_uint_t lwip_parse_inet_addr(mp_obj_t addr_in, ip_addr_t *out_ip) { mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); size_t addr_len; const char *addr_str = mp_obj_str_get_data(addr_items[0], &addr_len); - if (!ipaddr_aton(addr_str, out_ip)) { - mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + if (*addr_str == 0) { + #if LWIP_IPV6 + *out_ip = *IP6_ADDR_ANY; + #else + *out_ip = *IP_ADDR_ANY; + #endif + } else { + if (!ipaddr_aton(addr_str, out_ip)) { + mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments")); + } } return mp_obj_get_int(addr_items[1]); } |