[OpenWrt-Devel] [PATCH] Support broadcast sockets in usock
javierdo1 at gmail.com
javierdo1 at gmail.com
Fri Oct 2 08:13:46 EDT 2015
From: Javier Domingo Cansino <javierdo1 at gmail.com>
Signed-off-by: Javier Domingo Cansino <javierdo1 at gmail.com>
---
usock.c | 5 ++++-
usock.h | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/usock.c b/usock.c
index 6748ef3..58f16da 100644
--- a/usock.c
+++ b/usock.c
@@ -43,16 +43,19 @@ static void usock_set_flags(int sock, unsigned int type)
static int usock_connect(int type, struct sockaddr *sa, int sa_len, int family, int socktype, bool server)
{
int sock;
+ int flags = SO_REUSEADDR;
sock = socket(family, socktype, 0);
if (sock < 0)
return -1;
usock_set_flags(sock, type);
+ if (flags & USOCK_BROADCAST)
+ flags |= SO_BROADCAST;
if (server) {
const int one = 1;
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+ setsockopt(sock, SOL_SOCKET, flags, &one, sizeof(one));
if (!bind(sock, sa, sa_len) &&
(socktype != SOCK_STREAM || !listen(sock, SOMAXCONN)))
diff --git a/usock.h b/usock.h
index b0b952b..3471f2a 100644
--- a/usock.h
+++ b/usock.h
@@ -26,6 +26,7 @@
#define USOCK_NOCLOEXEC 0x0200
#define USOCK_NONBLOCK 0x0400
#define USOCK_NUMERIC 0x0800
+#define USOCK_BROADCAST 0x1000
#define USOCK_IPV6ONLY 0x2000
#define USOCK_IPV4ONLY 0x4000
#define USOCK_UNIX 0x8000
--
2.6.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list