extmod/modusocket: Bind unconnected socket to default NIC in setsockopt.

Bind socket to default NIC if setsockopt is called before the socket is
bound, to allow setting SO_REUSEADDR before calling socket_bind().

Fixes issue #8653.
pull/8698/head
iabdalkader 2022-05-12 13:01:22 +02:00 zatwierdzone przez Damien George
rodzic 7b4147dd0b
commit 6136c7644a
1 zmienionych plików z 3 dodań i 2 usunięć

Wyświetl plik

@ -310,8 +310,9 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (self->nic == MP_OBJ_NULL) {
// not connected
return mp_const_none;
// bind to default NIC.
uint8_t ip[4] = {0, 0, 0, 0};
socket_select_nic(self, ip);
}
mp_int_t level = mp_obj_get_int(args[1]);