如何确定传入消息的来源(uincast / multicast / broadcast) [英] How to determine origin of incoming message (uincast/multicast/broadcast)

查看:115
本文介绍了如何确定传入消息的来源(uincast / multicast / broadcast)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(对不起标题,我不知道如何解释这个)


我想知道是否有可能告诉套接字,传入的数据是如何发送的。

现在,我的意思是,我有一个UDP套接字,只是在一个端口上读取消息,然后输出一个msg,例如来自[IP Addy]的数据到了。

但如果我发送数据,我想知道它是来自单播,广播还是多播。

这可能吗?它似乎应该是,但也许我需要处于RAW模式并检查各种标题中的字节?

有什么想法吗?

(Sorry about the title, i''m not sure how to explain this)

I am wondering if it is possible to tell on socket, HOW the incoming data was sent.
Now, what I mean by that is, I have a UDP socket just reading messages in a loop that come in on a port and pumping out a msg such like "Data from [IP Addy] arrived".
But if I "send" data to it, I want to know if it came from unicast, broadcast, or multicast.
Is that possible? It seems like it should be, but maybe I need to be in RAW mode and examine the bytes in the various headers?
Any thoughts?

推荐答案

你的意思是你想知道它是发送到单播,广播还是多播地址,还是从这样的地址发送过来的?


我认为答案是您需要检查地址以确定其状态。


以下是 IP多播寻址的维基百科。


以下是文章中的相关内容:

单播:最常见的IP概念地址是单播寻址,可在IPv4和IPv6中使用。它通常指单个发送方或单个接收方,可用于发送和接收。通常,单播地址与单个设备或主机相关联,但它不是一对一的对应关系。有些PC有几个不同的单播地址,每个地址都有其独特的用途。将相同数据发送到多个单播地址需要发送方多次发送所有数据,每个接收方一次。

广播:在IPv4中,可以发送数据到所有可能的目的地(所有主机广播),它允许发送者仅发送一次数据,并且所有接收者都接收它的副本。在IPv4协议中,地址255.255.255.255用于本地广播。另外,可以通过将网络前缀与完全由二进制1组成的主机后缀组合来进行定向(有限)广播。例如,用于192.0.2.0/24网络上设备的定向广播的目标地址是192.0.2.255。 IPv6不实现广播寻址,并将其替换为多播到特定定义的所有节点多播地址。

多播:多播地址与一组感兴趣的接收者相关联。在IPv4中,地址224.0.0.0到239.255.255.255(以前的D类地址)被指定为多播地址。[2]发送方从其单播地址向组播组地址发送单个数据报,中间路由器负责制作副本并将其发送到已加入相应组播组的所有接收方。 IPv6使用带有前缀ff00 :: / 8的地址块用于多播应用程序。

Anycast(此处为完整性):与广播和多播一样,任播是一个一对一 - 多种路由拓扑。然而,数据流不被发送到所有接收器,只是路由器决定的是最接近的接收器。在网络中。[注1] Anycast对于全局负载平衡非常有用,通常用于DNS通信。


我不记得是否有可用于检查地址的宏或不过,不是。


祝你好运!
Do you mean you want to know if it was sent to a unicast, broadcast, or multicast address, or it was sent from such an address?

I think the answer is that you need to inspect the address to determine its status.

Here is the wikipedia on IP Multicast addressing.

Here are the pertinent bits from the article:

Unicast: The most common concept of an IP address is in unicast addressing, available in both IPv4 and IPv6. It normally refers to a single sender or a single receiver, and can be used for both sending and receiving. Usually, a unicast address is associated with a single device or host, but it is not a one-to-one correspondence. Some individual PCs have several distinct unicast addresses, each for its own distinct purpose. Sending the same data to multiple unicast addresses requires the sender to send all the data many times over, once for each recipient.

Broadcast: In IPv4 it is possible to send data to all possible destinations ("all-hosts broadcast"), which permits the sender to send the data only once, and all receivers receive a copy of it. In the IPv4 protocol, the address 255.255.255.255 is used for local broadcast. In addition, a directed (limited) broadcast can be made by combining the network prefix with a host suffix composed entirely of binary 1s. For example, the destination address used for a directed broadcast to devices on the 192.0.2.0/24 network is 192.0.2.255. IPv6 does not implement broadcast addressing and replaces it with multicast to the specially-defined all-nodes multicast address.

Multicast: A multicast address is associated with a group of interested receivers. In IPv4, addresses 224.0.0.0 through 239.255.255.255 (the former Class D addresses) are designated as multicast addresses.[2] The sender sends a single datagram from its unicast address to the multicast group address and the intermediary routers take care of making copies and sending them to all receivers that have joined the corresponding multicast group. IPv6 uses the address block with the prefix ff00::/8 for multicast applications.

Anycast (here for completeness): Like broadcast and multicast, anycast is a one-to-many routing topology. However, the data stream is not transmitted to all receivers, just the one which the router decides is the "closest" in the network.[Note 1] Anycast is useful for global load balancing and is commonly used in DNS communications.

I don''t remember if there are macros available to check addresses or not, though.

Good luck!


我想我的问题是我的问题。


例如,当UDP套接字吐出它看到的数据包(称之为服务器)时,我做了以下事情:

*如果同一系统上的客户端软件发送UDP消息到端口上的255.255.255.255(广播)和我的服务器看到该消息并说来自127.0.0.1的消息

*如果同一系统上的客户端软件发送到多播ip而我的服务器是看到消息并说出来自192.168.1.7的消息。 (这是代码运行的机器的IP)


我想知道是否在服务器上我可以分辨出这两条消息之间的区别(以及单播到192.168.1.7) )。

我是否可以更改服务器以将套接字绑定到特定地址(一个到192.168.1.7,一个到多播地址),这样我可以将它们区分开来吗?


虽然我知道我的服务器收到消息的设计并不重要,但它会让我的事情变得更容易。


(对于它的价值,我正在玩UPNP并在1900年监听流量。来自多播地址的消息将是一般发现/宣布有效载荷,发送给ME(单播)的消息是定向响应)
I guess who it was going TO is my question.

For instance with that UDP socket spitting out packets it sees (call it the "server"), I did the following:
*Had a client software on the same system send a UDP message to 255.255.255.255 (broadcast) on the port and my "server" saw the message and said "message from 127.0.0.1"
*Had a client software on the same system send to a multicast ip and my "server" saw the message and said "message from 192.168.1.7" (which is the IP of the machine the code was running on)

I was wondering if on the server I could tell the difference between those two messages (and a unicast to 192.168.1.7).
Would I change my server to have sockets be bound to a specific address (one to 192.168.1.7 and one to the multicast address) would that allow me to tell them apart?

While it is not crucial to the design that i know how the messages were received by my server, it would make things a bit easier on me.

(For what it is worth, I am playing with UPNP and listening for traffic on 1900. Messages from the multicast address are going to be general discover/announce payloads, messages sent to ME(unicast) are directed responses)


看起来你正在进行本地环回测试,从我读到的,正确的?


如果我没记错的话,套接字可以绑定到系统上的多个地址。这对于侦听套接字尤其重要,因为它们将在127.0.0.1(环回)以及系统正常时监听。地址。如果你想屏蔽测试中的localhost-loopback消息,你需要注意这一点。当然,您添加到系统中的每个IP地址都会加剧这个问题。


或者,您可以排除所有收到的消息,期望收到倍数。我碰巧认为这是更好的选择。


请记住,收件人的IP地址决定了邮件在网络中的移动方式。这意味着您可以从单播地址发送到多播地址,对吗?也就是说,我可以从我的本地(单播)IP 10.1.2.3发送一条消息到多播IP 224.1.2.3,对吗?


所以,你收到消息的地址是确定邮件的发送方式。


邮件发送的地址决定了邮件的处理方式。 [另外,这就是使用原始套接字制作SMURF和其他攻击的方式]。


因为我不知道你的应用程序是什么,我不知道是什么否则告诉你哪些会有所帮助。希望我在这里不要让你困惑。


干杯!
It looks like you''re doing local loop-back for your testing, from what I read, correct?

If I recall correctly, sockets can bind to multiple addresses on a system. This is especially important for listening sockets, as they''ll listen on 127.0.0.1 (loopback) as well the systems "normal" addresses. If you want to mask out localhost-loopback messages from your testing, you''ll need to be careful about that. The problem is exacerbated with each IP address you add to your system, of course.

Alternately, you can drain off all recieved messages, expecting to recieve multiples. I happen to think that this is the better option.

Remember that it''s the recipient''s IP address that determines how a message is moved around the network. Which means that you can sent to a multi-cast address from a unicast address, right? That is, I can send a message from my local (unicast) IP of 10.1.2.3 to the multicast IP 224.1.2.3, right?

So, the address you recieved the message at determines how the message was sent.

The address the message was sent from determines how the reply will be handled. [as an aside, this is how SMURF and other attacks are crafted using raw sockets].

Since I don''t know what your application is, I''m not sure what else to tell you which will help. Hopefully I''m not confusing you here.

Cheers!


这篇关于如何确定传入消息的来源(uincast / multicast / broadcast)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆