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

Bruno Jesus 00cpxxx at gmail.com
Mon Dec 5 06:04:27 CST 2016


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.

>> +/* 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.

Ok, no problem. Please share the patch with me.



More information about the wine-devel mailing list