C++ Understanding boost asio multicast receiver - network-interface

I have recently started trying to learn the boost multicast receiver example and what it is doing [code]. I understand basic multicast receivers/sends but I have been struggling to understand a few things:
Within the code they have a listener address and a multicast address. Is the multicast address the address on the local machine that the packet is being sent to, while the listener address is the address of the machine?
Followup to the first question - In the default code they have the listener address as 0.0.0.0 . In older network code I never explicitly came into contact with this. What is the purpose of the listen address and is there any good reference for what its uses are?
When I set the listener address to 0.0.0.0 and my multicast address to 224.0.0.10 and run a netstat I cannot find the multicast address. I would expect to see the address that I am listening on unless I am not understanding something correctly.

Related

Force gateway for IP connection

I have two NICs in my Windows PC, one for Internet and the other for outbound UDP streams. Both NICs have gateways and I tweak the metrics so that Internet bound traffic goes to the first. I would rather disable the gateway on the second NIC and specify the gateway when I create the UDP socket. Is this possible? Can I force the destination MAC address on a socket?
You have to bind() the socket to the local IP address of the NIC you want to use. If you don't know the IP, use GetAdaptersInfo() or GetAdaptersAddresses() to enumerate the NICs until you find the one you want, and then you will know its current IP to bind to.

Cannot bind to multicast address (Windows)

I am trying to write an application that listens to a number of multicast groups using Windows sockets.
The problem I'm running in to is that when I go to bind the socket, if I try to bind to the multicast group address and port this fails with WSAEADDRNOTAVAIL. If I instead bind to INADDR_ANY and the port, then I can still receive other unrelated traffic destined for the same port.
When I implemented the same thing in Linux, I didn't have any issues binding to the multicast address (in fact, I saw it recommended several places to avoid getting unrelated traffic for the port).
Is this just not available with Windows sockets? I assume I could filter traffic myself by using WSARecvFrom and peeking at the headers, but I'd rather a simple solution if one exists.
Also, this is running on Windows Server 2008.
While the doc for bind() does not say that this unsupported, it does say in the remarks:
For multicast operations, the
preferred method is to call the bind
function to associate a socket with a
local IP address and then join the
multicast group....
Maybe this scheme will yield better results?

Simulating multicasting on loopback interface

I'm writing a network application in ruby which should use UDP multicasting.
My problem is that I want to run multiple instances for testing purposes on localhost, but multicasting only works if I bind the socket to the real network interface.
Is there some way to enable multicasting for the loopback interface, so that all the 127.0.0.x get the message I send?
Currently I enable multicasting with:
ip = IPAddr.new('234.56.78.9').hton + IPAddr.new('0.0.0.0').hton
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP,ip)
#socket.bind '127.0.0.1',1234 ##does not receive multicast :(
socket.bind '0.0.0.0',1234
Also, I noticed that if I e.g. bind the socket to 127.0.0.4 and send a message, in the packet the source ip is 127.0.0.1 anyway... is there a way to set the source IP so it shows the same IP I bound the socket to?
Solaris allows you to use multicast on the loopback device. For other operating systems you can enable IP_MULTICAST_LOOP on the sender (Unix) or the receiver (Windows) for similar effect.

bind () to an IPv6 address in windows 7 is Failing with Error code :: WSAEADDRNOTAVAIL (10049)

I am trying to set-up a private ipv6 network with two windows-7 machines for tesing my application. I have written a sample code to test the socket apis. I have created an IPv6 socket. When I try to bind with the link-local address (which I get from ipconfig command), the error code is 10049.
Please inform, why the bind with Ipv6 address is failing in windows-7 machine ?
If you're using a link-local IPv6 address, you probably need to set the sin6_scope_id field in your sockaddr_in6 structure to indicate which interface you want to listen on. A link-local address is ambiguous, since every interface must have a link-local address assigned, and they all use the same prefix. (fe80::/64)
You should probably bind() your listen socket to the unspecified address (all-zeroes or ::) so this isn't an issue, but it will still be a problem for the sending side. If you don't specify the sin6_scope_id, the system won't know which interface to send the packet on.
To avoid the issue, it would be best to set up an IPv6 router that does router advertisements, so you can get global unicast (or, at a minimum, unique local) addresses.

No ping to a multicast address from Windows

On my computer, when I try to ping to a multicast address, none of them return a response.
On the other hand, there is a Unix server I know that does have ping to these addresses.
Is there a way to add a route from my computer to this one, so that I can use these addresses?
No, ICMP is not typically used with multicast because it is a prime source for DoS amplification. Similarly multicast doesn't tend to be that useful as you need multicast enabled and configured routers to cross LAN segments.
See this answer if you are wanting to use multicast pings for discovery of local machines:
Multicast Ping (Windows)

Resources