Encontrar la dirección IP de destino del mensaje UDP recibido en la biblioteca boost

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: Obtener la dirección de destino de un paquete UDP recibido .

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??

preguntado el 30 de agosto de 11 a las 22:08

2 Respuestas

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.

Respondido 31 ago 11, 04:08

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

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

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

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: nyxdata.com/page/848 - John Zwinck

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.

Respondido 31 ago 11, 08:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.