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.
This commit is contained in:
iabdalkader 2022-05-12 13:01:22 +02:00 committed by Damien George
parent 7b4147dd0b
commit 6136c7644a

View File

@ -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]);