mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 16:48:06 +02:00
fixed GH #245: MulticastSocket::joinGroup(const IPAddress&) not working
This commit is contained in:
@@ -114,6 +114,10 @@ public:
|
|||||||
|
|
||||||
void leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interfc);
|
void leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interfc);
|
||||||
/// Leaves the specified multicast group at the given interface.
|
/// 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)
|
void MulticastSocket::joinGroup(const IPAddress& groupAddress)
|
||||||
{
|
{
|
||||||
NetworkInterface intf;
|
joinGroup(groupAddress, findFirstInterface(groupAddress));
|
||||||
joinGroup(groupAddress, intf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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)
|
void MulticastSocket::leaveGroup(const IPAddress& groupAddress)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user