Skip to content

Commit 6f8a424

Browse files
committed
Merge branch 'master' of git.exmachina.fr:mbed-os
2 parents e7361eb + c44b3ec commit 6f8a424

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

features/FEATURE_LWIP/lwip-interface/lwip_stack.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,18 @@ static nsapi_error_t mbed_lwip_setsockopt(nsapi_stack_t *stack, nsapi_socket_t h
858858
}
859859
return 0;
860860

861+
case NSAPI_BROADCAST:
862+
if (optlen != sizeof(int) || (s->conn->type != NETCONN_UDP && s->conn->type != NETCONN_RAW)) {
863+
return NSAPI_ERROR_UNSUPPORTED;
864+
}
865+
866+
if (*(int *)optval) {
867+
s->conn->pcb.udp->so_options |= SOF_BROADCAST;
868+
} else {
869+
s->conn->pcb.udp->so_options &= SOF_BROADCAST;
870+
}
871+
return 0;
872+
861873
default:
862874
return NSAPI_ERROR_UNSUPPORTED;
863875
}

features/netsocket/UDPSocket.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ nsapi_size_or_error_t UDPSocket::recvfrom(SocketAddress *address, void *buffer,
121121
return ret;
122122
}
123123

124+
nsapi_error_t UDPSocket::set_broadcast(bool broadcast)
125+
{
126+
int _broadcast = broadcast ? 1 : 0;
127+
return setsockopt(NSAPI_SOCKET, NSAPI_BROADCAST, &_broadcast, sizeof(int));
128+
}
129+
124130
void UDPSocket::event()
125131
{
126132
int32_t wcount = _write_sem.wait(0);

features/netsocket/UDPSocket.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ class UDPSocket : public Socket {
112112
nsapi_size_or_error_t recvfrom(SocketAddress *address,
113113
void *data, nsapi_size_t size);
114114

115+
/** Set broadcast packet behaviour
116+
*
117+
* Initially all sockets ignore broadcast packets.
118+
* Setting broadcast to true enable the reception of broadcast packets.
119+
*
120+
* @param broadcast true to enable or false to disable broadcast
121+
* packets reception
122+
* @return nsapi_error_t on error or 0 if sucessfull
123+
*/
124+
nsapi_error_t set_broadcast(bool broadcast);
125+
115126
protected:
116127
virtual nsapi_protocol_t get_proto();
117128
virtual void event();

features/netsocket/nsapi_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ typedef enum nsapi_socket_option {
210210
NSAPI_LINGER, /*!< Keeps close from returning until queues empty */
211211
NSAPI_SNDBUF, /*!< Sets send buffer size */
212212
NSAPI_RCVBUF, /*!< Sets recv buffer size */
213+
NSAPI_BROADCAST, /*!< Receive broadcast packets */
213214
} nsapi_socket_option_t;
214215

215216
/* Backwards compatibility - previously didn't distinguish stack and socket options */

0 commit comments

Comments
 (0)