diff --git a/docs/c-api/net.h/struct_mg_connection.md b/docs/c-api/net.h/struct_mg_connection.md index 9d1bf333..76f767f8 100644 --- a/docs/c-api/net.h/struct_mg_connection.md +++ b/docs/c-api/net.h/struct_mg_connection.md @@ -59,6 +59,7 @@ signature: | #define MG_F_CLOSE_IMMEDIATELY (1 << 11) /* Disconnect */ #define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */ #define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */ + #define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */ #define MG_F_USER_1 (1 << 20) /* Flags left for application */ #define MG_F_USER_2 (1 << 21) diff --git a/mongoose.c b/mongoose.c index 7811eb80..64f07c3c 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1679,7 +1679,7 @@ const char *c_strnstr(const char *s, const char *find, size_t slen) { /* Which flags can be pre-set by the user at connection creation time. */ #define _MG_ALLOWED_CONNECT_FLAGS_MASK \ (MG_F_USER_1 | MG_F_USER_2 | MG_F_USER_3 | MG_F_USER_4 | MG_F_USER_5 | \ - MG_F_USER_6 | MG_F_WEBSOCKET_NO_DEFRAG) + MG_F_USER_6 | MG_F_WEBSOCKET_NO_DEFRAG | MG_F_ENABLE_BROADCAST) /* Which flags should be modifiable by user's callbacks. */ #define _MG_CALLBACK_MODIFIABLE_FLAGS_MASK \ (MG_F_USER_1 | MG_F_USER_2 | MG_F_USER_3 | MG_F_USER_4 | MG_F_USER_5 | \ @@ -2789,6 +2789,11 @@ void mg_if_connect_udp(struct mg_connection *nc) { nc->err = errno ? errno : 1; return; } + if (nc->flags & MG_F_ENABLE_BROADCAST) { + int optval = 1; + setsockopt(nc->sock, SOL_SOCKET, SO_BROADCAST, (const char *) &optval, + sizeof(optval)); + } nc->err = 0; } diff --git a/mongoose.h b/mongoose.h index 6179d319..c68deae3 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1263,6 +1263,7 @@ struct mg_connection { #define MG_F_CLOSE_IMMEDIATELY (1 << 11) /* Disconnect */ #define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12) /* Websocket specific */ #define MG_F_DELETE_CHUNK (1 << 13) /* HTTP specific */ +#define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */ #define MG_F_USER_1 (1 << 20) /* Flags left for application */ #define MG_F_USER_2 (1 << 21)