kopia lustrzana https://github.com/micropython/micropython
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>
pull/13725/head
rodzic
8547a78275
commit
d2bcb8597e
|
@ -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]);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue