简体   繁体   English

在boost库中查找收到的UDP消息的目标IP地址

[英]Finding the destination IP address of the received UDP message in boost library

I am working with multicast UDP messages. 我正在使用多播UDP消息。 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. 我需要将接收到的数据包的目标IP地址与通道的多播地址进行比较,接收器应该正在监听以确保它没有接收通过不同多播通道进行多播的消息。

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 . 我知道我可以使用带有recvmsg()的UNIX套接字找到目标IP地址,然后执行这里提到的所有内容: 获取收到的UDP数据包的目标地址

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(). 但是我一直在使用boost库ASIO套接字,虽然有对应于recvfrom()funcn的receive_from()但是我找不到任何具有与recvmsg()类似功能的func。 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?? 任何人都可以帮助我..有没有办法找到升级库中收到的数据包的目标IP地址?

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. 如果那不是它,也许你会解释发生了什么让你问这个问题。

无法访问目标地址的典型解决方法是为每个多播组打开一个套接字,并将套接字与应用程序中的地址匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM