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

Hans Leidekker hans at codeweavers.com
Mon Dec 5 04:38:15 CST 2016


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.

> +/* required for broadcast tests */
> +static void disable_firewall(void)
> +{
> +    system("netsh firewall set opmode disable"); /* XP */
> +    system("netsh Advfirewall set allprofiles state off"); /* >= Vista*/
> +}
> +
> +static void enable_firewall(void)
> +{
> +    system("netsh firewall set opmode enable"); /* XP */
> +    system("netsh Advfirewall set allprofiles state on"); /* >= Vista*/
> +}

This will not work if the test is run as an unprivileged user. It would be better
to use an API like INetFwMgr and skip the affected tests when you can't modify
the firewall.

I'm working on a fix for a similar problem in the rpcrt4 test. I can share a 
patch if you're interested.





More information about the wine-devel mailing list