[OpenWrt-Devel] [PATCH] Support broadcast sockets in usock

John Crispin blogic at openwrt.org
Fri Oct 2 08:43:22 EDT 2015


Hi,

comments inline

On 02/10/2015 14:13, javierdo1 at gmail.com wrote:
> 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;
>  

people tend to sort these by alphabetic order or line width. your patch
does neither of the 2.

>  	sock = socket(family, socktype, 0);
>  	if (sock < 0)
>  		return -1;
>  
>  	usock_set_flags(sock, type);
> +	if (flags & USOCK_BROADCAST)
> +		flags |= SO_BROADCAST;
>  

this should be guarded by "socktype != SOCK_STREAM" or similar. check
what the rest of the code does and change the patch accordingly please.

	John



>  	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
> 
_______________________________________________
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