[PATCH] ws2_32: Implement automatic broadcast for UDP sockets on sendto() (try 2)

Hans Leidekker hans at codeweavers.com
Mon Dec 5 07:15:01 CST 2016


On Mon, 2016-12-05 at 10:04 -0200, Bruno Jesus wrote:
> On Mon, Dec 5, 2016 at 8:38 AM, Hans Leidekker <hans at codeweavers.com> wrote:
> > On Sat, 2016-12-03 at 00:15 -0200, Bruno Jesus wrote:
> >> @@ -2446,8 +2476,32 @@ static int WS2_send( int fd, struct ws2_async *wsa, int flags )
> >>              return -1;
> >>          }
> >>
> >> +        if (wsa->addr->sa_family == WS_AF_INET)
> >> +        {
> >> +            /* When the target IPv4 address ends in 255 we are going to check if
> >> +             * it matches the broadcast address. Trying to send the packet without
> >> +             * setting SO_BROADCAST results in EACCES, to avoid that we will enable
> >> +             * the flag and send the packet, after that we will restore the flag
> >> +             * This is the most common estimate to reduce the number of UDP packets
> >> +             * that we need to check. */
> >> +            struct sockaddr_in *addr = (struct sockaddr_in*) hdr.msg_name;
> >> +            in_addr_t address = addr->sin_addr.s_addr;
> >> +
> >> +            if (address != INADDR_BROADCAST && (address & 0xFF000000) == 0xFF000000)
> >
> > This doesn't work for a /25 network, for example. You really need to use the network
> > mask here to calculate the broadcast address.
> 
> Hi, thanks for the review. As I wrote in the comments this is the most
> common estimate, it should
> be enough for the majority of home networks everywhere. So far there
> is only one application affected too which is a game. Checking if
> every packet is UDP and if every UDP packet is not in broadcast state
> and then checking if its address is a broadcast would be take too much
> time in a operation that has to be very fast. Unless I'm missing
> something as I said in the first version of the patch.

You are trading correctness for performance, and even with this filter
the getsockopt calls are probably too expensive. I guess this
information should somehow be cached.





More information about the wine-devel mailing list