Skip to content

Commit 580fd2c

Browse files
Add LWIP Broadcast option for UDP socket.
1 parent 7c17693 commit 580fd2c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

connectivity/lwipstack/source/LWIPStack.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,22 @@ nsapi_error_t LWIP::setsockopt(nsapi_socket_t handle, int level, int optname, co
567567
}
568568
return 0;
569569

570+
case NSAPI_BROADCAST:
571+
if (NETCONNTYPE_GROUP(s->conn->type) != NETCONN_UDP) {
572+
return NSAPI_ERROR_UNSUPPORTED;
573+
}
574+
575+
if (optlen != sizeof(int)) {
576+
return NSAPI_ERROR_UNSUPPORTED;
577+
}
578+
579+
if (*(const int *)optval) {
580+
ip_set_option(s->conn->pcb.ip, SOF_BROADCAST);
581+
} else {
582+
ip_reset_option(s->conn->pcb.ip, SOF_BROADCAST);
583+
}
584+
return 0;
585+
570586
case NSAPI_ADD_MEMBERSHIP:
571587
case NSAPI_DROP_MEMBERSHIP: {
572588
if (optlen != sizeof(nsapi_ip_mreq_t)) {

connectivity/netsocket/include/netsocket/nsapi_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ typedef enum nsapi_socket_option {
318318
NSAPI_LATENCY, /*!< Read estimated latency to destination */
319319
NSAPI_STAGGER, /*!< Read estimated stagger value to destination */
320320
NSAPI_IPTOS, /*!< Set IP type of service to set specific precedence */
321+
NSAPI_BROADCAST /*!< Set broadcast flag for UDP socket */
321322
} nsapi_socket_option_t;
322323

323324
typedef enum nsapi_tlssocket_level {

0 commit comments

Comments
 (0)