mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 22:31:23 +01:00
fixed GH #245: MulticastSocket::joinGroup(const IPAddress&) not working
This commit is contained in:
parent
ce3ad64e16
commit
e44df5a583
@ -114,6 +114,10 @@ public:
|
||||
|
||||
void leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interfc);
|
||||
/// Leaves the specified multicast group at the given interface.
|
||||
|
||||
private:
|
||||
static NetworkInterface findFirstInterface(const IPAddress& groupAddress);
|
||||
/// Returns first multicast-eligible network interface.
|
||||
};
|
||||
|
||||
|
||||
|
@ -193,8 +193,7 @@ unsigned MulticastSocket::getTimeToLive() const
|
||||
|
||||
void MulticastSocket::joinGroup(const IPAddress& groupAddress)
|
||||
{
|
||||
NetworkInterface intf;
|
||||
joinGroup(groupAddress, intf);
|
||||
joinGroup(groupAddress, findFirstInterface(groupAddress));
|
||||
}
|
||||
|
||||
|
||||
@ -218,6 +217,42 @@ void MulticastSocket::joinGroup(const IPAddress& groupAddress, const NetworkInte
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NetworkInterface MulticastSocket::findFirstInterface(const IPAddress& groupAddress)
|
||||
{
|
||||
NetworkInterface::Map m = NetworkInterface::map();
|
||||
if (groupAddress.family() == IPAddress::IPv4)
|
||||
{
|
||||
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
|
||||
{
|
||||
if (it->second.supportsIPv4() &&
|
||||
it->second.firstAddress(IPAddress::IPv4).isUnicast() &&
|
||||
!it->second.isLoopback() &&
|
||||
!it->second.isPointToPoint())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
else if (groupAddress.family() == IPAddress::IPv6)
|
||||
{
|
||||
for (NetworkInterface::Map::const_iterator it = m.begin(); it != m.end(); ++it)
|
||||
{
|
||||
if (it->second.supportsIPv6() &&
|
||||
it->second.firstAddress(IPAddress::IPv6).isUnicast() &&
|
||||
!it->second.isLoopback() &&
|
||||
!it->second.isPointToPoint())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
throw NotFoundException("No multicast-eligible network interface found.");
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocket::leaveGroup(const IPAddress& groupAddress)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user