Re: [OpenWrt-Devel] [PATCH libubox v2] Support broadcast sockets in usock

2015-10-26 Thread Javier Domingo Cansino
On Mon, Oct 26, 2015 at 2:16 PM John Crispin  wrote:

> Hi,
>
> was about to merge this but then ... see inline
>
> On 02/10/2015 15:53, Javier Domingo Cansino wrote:
> > Signed-off-by: Javier Domingo Cansino 
> > ---
> >  usock.c | 4 +++-
> >  usock.h | 1 +
> >  2 files changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/usock.c b/usock.c
> > index 6748ef3..3dd9957 100644
> > --- a/usock.c
> > +++ b/usock.c
> > @@ -42,6 +42,7 @@ 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)
> >  {
> > + const int one = 1;
> >   int sock;
> >
> >   sock = socket(family, socktype, 0);
> > @@ -49,9 +50,10 @@ static int usock_connect(int type, struct sockaddr
> *sa, int sa_len, int family,
> >   return -1;
> >
> >   usock_set_flags(sock, type);
> > + if (socktype != SOCK_STREAM && type & USOCK_BROADCAST)
>
> should it not be
>
> if (socktype == SOCK_DGRAM  ?
>
> John
>

It is more clear with your expression, they have the same effect anyway.

>
> > + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, ,
> sizeof(one));
> >
> >   if (server) {
> > - const int one = 1;
> >   setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, ,
> sizeof(one));
> >
> >   if (!bind(sock, sa, sa_len) &&
> > 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_NUMERIC0x0800
> > +#define USOCK_BROADCAST  0x1000
> >  #define USOCK_IPV6ONLY   0x2000
> >  #define USOCK_IPV4ONLY   0x4000
> >  #define USOCK_UNIX   0x8000
> >
>
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH libubox v2] Support broadcast sockets in usock

2015-10-26 Thread John Crispin
Hi,

was about to merge this but then ... see inline

On 02/10/2015 15:53, Javier Domingo Cansino wrote:
> Signed-off-by: Javier Domingo Cansino 
> ---
>  usock.c | 4 +++-
>  usock.h | 1 +
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/usock.c b/usock.c
> index 6748ef3..3dd9957 100644
> --- a/usock.c
> +++ b/usock.c
> @@ -42,6 +42,7 @@ 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)
>  {
> + const int one = 1;
>   int sock;
>  
>   sock = socket(family, socktype, 0);
> @@ -49,9 +50,10 @@ static int usock_connect(int type, struct sockaddr *sa, 
> int sa_len, int family,
>   return -1;
>  
>   usock_set_flags(sock, type);
> + if (socktype != SOCK_STREAM && type & USOCK_BROADCAST)

should it not be

if (socktype == SOCK_DGRAM  ?

John

> + setsockopt(sock, SOL_SOCKET, SO_BROADCAST, , sizeof(one));
>  
>   if (server) {
> - const int one = 1;
>   setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, , sizeof(one));
>  
>   if (!bind(sock, sa, sa_len) &&
> 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_NUMERIC0x0800
> +#define USOCK_BROADCAST  0x1000
>  #define USOCK_IPV6ONLY   0x2000
>  #define USOCK_IPV4ONLY   0x4000
>  #define USOCK_UNIX   0x8000
> 
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel