mirror of
https://github.com/W3SLAV/micropython.git
synced 2025-06-22 21:45:35 -04:00
extmod/modlwip: Add back support for empty IP addresses.
Prior to commit 628abf8f25
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>
This commit is contained in:
parent
8547a78275
commit
d2bcb8597e
@ -367,9 +367,17 @@ 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);
|
mp_obj_get_array_fixed_n(addr_in, 2, &addr_items);
|
||||||
size_t addr_len;
|
size_t addr_len;
|
||||||
const char *addr_str = mp_obj_str_get_data(addr_items[0], &addr_len);
|
const char *addr_str = mp_obj_str_get_data(addr_items[0], &addr_len);
|
||||||
|
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)) {
|
if (!ipaddr_aton(addr_str, out_ip)) {
|
||||||
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
|
mp_raise_ValueError(MP_ERROR_TEXT("invalid arguments"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return mp_obj_get_int(addr_items[1]);
|
return mp_obj_get_int(addr_items[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user