Skip to content

Commit c9426e7

Browse files
authored
Merge pull request #2440 from geky/nsapi-lwip-reuseaddr
[nsapi] Add support for NSAPI_REUSEADDR to the lwip interface
2 parents 0f2566b + de9e221 commit c9426e7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "lwip/dhcp.h"
2929
#include "lwip/tcpip.h"
3030
#include "lwip/tcp.h"
31+
#include "lwip/ip.h"
3132

3233

3334
/* Static arena of sockets */
@@ -415,6 +416,18 @@ static int lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t handle, int leve
415416
s->conn->pcb.tcp->keep_intvl = *(int*)optval;
416417
return 0;
417418

419+
case NSAPI_REUSEADDR:
420+
if (optlen != sizeof(int)) {
421+
return NSAPI_ERROR_UNSUPPORTED;
422+
}
423+
424+
if (*(int *)optval) {
425+
s->conn->pcb.tcp->so_options |= SOF_REUSEADDR;
426+
} else {
427+
s->conn->pcb.tcp->so_options &= ~SOF_REUSEADDR;
428+
}
429+
return 0;
430+
418431
default:
419432
return NSAPI_ERROR_UNSUPPORTED;
420433
}

features/net/FEATURE_IPV4/lwip-interface/lwipopts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
#define LWIP_DHCP 1
6868
#define LWIP_DNS 1
6969

70+
#define SO_REUSE 1
71+
7072
// Support Multicast
7173
#include "stdlib.h"
7274
#define LWIP_IGMP 1

0 commit comments

Comments
 (0)