IP broadcast problem Windows 7


#1


Hi Jules, because of a bug in Windows 7, there is a problem using IP broadcasts (http://social.technet.microsoft.com/Forums/windows/en-US/72e7387a-9f2c-4bf4-a004-c89ddde1c8aa/how-to-fix-the-global-broadcast-address-255255255255-behavior-on-windows?forum=w7itpronetworking).


It can be worked around by extracting the broadcast address for each network connection, and thus manually send the broadcast on all adapters. However, this requires an extension to IPAddress to get hold of the netmask when querying for IP addresses.


IPAddress::getBroadcastAddress() is the added method to get hold of the network adapter broadcast address. If the netmask is 0.0.0.0 (default), the returned address is 255.255.255.255 (i.e. same as IPAddress::broadcast() ), so for non Windows OSs (which don't exhibit this problem) the behaviour of using getBroadcastAddress() should be the same as using broadcast().


Attached is the modification to juce_IPAddress.h/cpp and below is the change to IPAddress::findAllAddresses  (juce_win32_Network.cpp):


void IPAddress::findAllAddresses (Array<IPAddress>& result)
{
    result.addIfNotAlreadyThere (IPAddress::local());
    GetAdaptersInfoHelper gah;
    if (gah.callGetAdaptersInfo())
    {
        for (PIP_ADAPTER_INFO adapter = gah.adapterInfo; adapter != nullptr; adapter = adapter->Next)
        {
            IPAddress ip (adapter->IpAddressList.IpAddress.String, adapter->IpAddressList.IpMask.String);
            if (ip != IPAddress::any())
                result.addIfNotAlreadyThere (ip);
        }
    }
}

#2

I'm not the world's greatest expert on networking (to say the least!) but can you explain why it would make sense for the IPAddress class to also hold the net mask? I'd have thought that the IP address and the mask are two separate concepts?


#3

No specific reason, it was a convenient place to put it for minimal interference with other stuff. Maybe some other abstraction works better, however, then end result is needed, i.e. to get hold of the netmask of the connection to be able to create the broadcast address.


#4

Ok, well in that case I'm pretty sure it doesn't belong in the IPAddress class itself. Although an IPAddress could be used as a mask - perhaps findAllAddresses should return two arrays, or an array of a struct that contains an address + mask?


#5

Sounds like a good idea, would work fine for me anyway :)