コード例 #1
0
/*!
	Scans an interface and enumerates all baos devices.
	It sends a search request as outlined in the BAOS 1.2 protocol
	documentation and waits for the responses. There are lots of
	magic numbers here and hard-coded offsets... See the spec
	for more information on what is happening here...

	We implement a receive timeout, and keep receiving until this
	timeout elapses. If this timeout is too fast, increase it to 500
	or 1000 for example.
*/
void BaosIpEnumerator::scanInterface(const NetworkInterface& networkInterface)
{
	poco_information(LOGGER(),
	                 format("Search devices on interface: %s (%s)",
	                        networkInterface.displayName(),
	                        networkInterface.address().toString()));

	try
	{
		// initialize socket
		MulticastSocket socket;
		socket.bind(SocketAddress(networkInterface.address(), 0));
		socket.setTimeToLive(DefaultMulticastTTL);

		// builds and sends a SEARCH_REQUEST to the socket
		sendSearchRequestFrame(socket);

		// wait for SEARCH_RESPONSES and collect it
		waitForSearchResponseFrames(socket);
	}
	catch (Poco::Exception& e)
	{
		poco_warning(LOGGER(), format("... search failed with error: %s", e.displayText()));
	}
}
コード例 #2
0
void MulticastSocket::leaveGroup(const IPAddress& groupAddress, const NetworkInterface& interface)
{
	if (groupAddress.af() == AF_INET)
	{
		struct ip_mreq mr;
		std::memcpy(&mr.imr_multiaddr, groupAddress.addr(), groupAddress.length());
		std::memcpy(&mr.imr_interface, interface.address().addr(), interface.address().length());
		impl()->setRawOption(IPPROTO_IP, IP_DROP_MEMBERSHIP, &mr, sizeof(mr));
	}
	else
	{
#if defined(POCO_HAVE_IPv6)
		struct ipv6_mreq mr;
		std::memcpy(&mr.ipv6mr_multiaddr, groupAddress.addr(), groupAddress.length());
		mr.ipv6mr_interface = interface.index();
		impl()->setRawOption(IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mr, sizeof(mr));
#endif
	}
}
コード例 #3
0
void MulticastSocket::setInterface(const NetworkInterface& interface)
{
	if (!interface.supportsIPv6())
	{
		impl()->setOption(IPPROTO_IP, IP_MULTICAST_IF, interface.address());
	}
	else
	{
#if defined(POCO_HAVE_IPv6)
		impl()->setOption(IPPROTO_IPV6, IPV6_MULTICAST_IF, interface.index());
#endif
	}
}