3

I am working with multicast UDP messages. I need to compare the destination IP address of the received packet with the multicast address of the channel, the receiver is supposed to be listening on to make sure that it is not receiving messages multicasted over a different multicast channel.

I know that I can find out the destination IP address by using UNIX sockets using recvmsg() and then doing all the stuff mentioned here: Get destination address of a received UDP packet .

But I have been using boost library ASIO sockets and although there is receive_from() corresponding to recvfrom() funcn but I can't find any func with a similar functionality as recvmsg(). Can anybody help me out here.. Is there a way to find out the destination IP address of the received packet in the boost library??

Community
  • 1
  • 1
vinsal
  • 31
  • 2

2 Answers2

0

Let's take a step back. Why do you think you need to be looking at the destination address and filtering it in userspace? Shouldn't the operating system be doing that for you? Probably it should!

Are you actually receiving datagrams that you don't want? If so, it's likely because you haven't done sufficiently strict setup of the listener. For example, you should be binding and listening only to a specific multicast group (address), port, and interface. Perhaps you're neglecting to specify some part of that? If that's not it, perhaps you'll explain what's going on that makes you ask this question.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • When a multicast packet is redirected by the router to all the receivers who have subscribed to that multicast channel and if there are multiple receivers running on one machine all of them receive this packet rather than only one particular receiver who had intially subscribed to that multicast channel. This part is true .. it always happens – vinsal Aug 31 '11 at 01:09
  • Are you saying you have multicast receivers that don't want to receive multicast data? This part is not very clear to me. If they don't want to receive the data, why would they be listening for it? – John Zwinck Aug 31 '11 at 02:41
  • Because a receiver can only be bind to a port and not an address .. all the receivers(on the same machine) listening on a port receive the message as they dont check the dest. IP address of the packet. – vinsal Aug 31 '11 at 20:30
  • Aha. The solution to this is to have each multicast group use a different port. Otherwise, well, you've found what the problem is. It's really important to have one group be on one port, and this is what a lot of systems do in the wild. For example, see: http://www.nyxdata.com/page/848 – John Zwinck Sep 01 '11 at 01:05
0

The typical workaround for not having access to destination address is to open one socket per multicast group and match the socket to the address within your application.

Steve-o
  • 12,678
  • 2
  • 41
  • 60