Skip to content

Commit d2bcb85

Browse files
felixdoerredpgeorge
authored andcommitted
extmod/modlwip: Add back support for empty IP addresses.
Prior to commit 628abf8 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>
1 parent 8547a78 commit d2bcb85

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎extmod/modlwip.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,16 @@ mp_uint_t lwip_parse_inet_addr(mp_obj_t addr_in, ip_addr_t *out_ip) {
367367
mp_obj_get_array_fixed_n(addr_in, 2, &addr_items);
368368
size_t addr_len;
369369
const char *addr_str = mp_obj_str_get_data(addr_items[0], &addr_len);
370-
if (!ipaddr_aton(addr_str, out_ip)) {
371-
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
370+
if (*addr_str == 0) {
371+
#if LWIP_IPV6
372+
*out_ip = *IP6_ADDR_ANY;
373+
#else
374+
*out_ip = *IP_ADDR_ANY;
375+
#endif
376+
} else {
377+
if (!ipaddr_aton(addr_str, out_ip)) {
378+
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
379+
}
372380
}
373381
return mp_obj_get_int(addr_items[1]);
374382
}

0 commit comments

Comments
 (0)