Skip to content

Commit 5e75f33

Browse files
committed
extmod/modlwip: Implement setsocketopt(SO_REUSEADDR).
1 parent 0cb10b5 commit 5e75f33

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

extmod/modlwip.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
//#include "lwip/raw.h"
4545
#include "lwip/dns.h"
4646

47+
// For compatibilily with older lwIP versions.
48+
#ifndef ip_set_option
49+
#define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt))
50+
#endif
51+
4752
#ifdef MICROPY_PY_LWIP_SLIP
4853
#include "netif/slipif.h"
4954
#include "lwip/sio.h"
@@ -876,7 +881,17 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblo
876881

877882
STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
878883
(void)n_args; // always 4
879-
printf("Warning: lwip.setsockopt() not implemented\n");
884+
lwip_socket_obj_t *socket = args[0];
885+
mp_int_t val = mp_obj_get_int(args[3]);
886+
switch (mp_obj_get_int(args[2])) {
887+
case SOF_REUSEADDR:
888+
// Options are common for UDP and TCP pcb's.
889+
// TODO: handle val
890+
ip_set_option(socket->pcb.tcp, SOF_REUSEADDR);
891+
break;
892+
default:
893+
printf("Warning: lwip.setsockopt() not implemented\n");
894+
}
880895
return mp_const_none;
881896
}
882897
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt);

0 commit comments

Comments
 (0)