我正试图通过以太网网络协议熟悉自己。但是,在查看标准时,以太网帧需要目标MAC地址,并且源地址MAC通常被编程到设备上。我的问题是设备如何获得初始目标地址。例如,当您第一次将计算机插入网络时,它如何发现它的邻居MAC地址。就像您需要与默认网关通信以获取IP地址以在网络外发送数据一样。我试过看标准,但我不确定要搜索。
我发现了这篇wiki文章Link Layer Discovery Protocol,但它看起来在2005年被标准化,以太网比这更早。那之前做了什么?它似乎不仅仅是提供MAC地址。
答案 0 :(得分:2)
首先,在IP中,当节点想要发现具有特定IP地址的设备的以太网地址时,它使用地址解析协议(ARP)。它将ARP消息发送到以太网广播地址FF:FF:FF:FF:FF:FF,询问"谁具有地址x.x.x.x?"。 LAN中的每个节点都接收广播并将其传递给ARP实现。如果接收节点没有该IP地址,则只丢弃ARP消息。如果有,它会响应告知它是该IP地址的所有者。如果这是您正在寻找的内容,请阅读http://en.wikipedia.org/wiki/Address_Resolution_Protocol。通过这种方式,源节点可以学习目标节点的硬件地址(具有预期的IP地址)并将映射IP以太网存储在其ARP缓存中。目标节点和所有其他节点学习源节点的映射。您也可以通过Comer预订"使用TCP / IP"进行网络互联。
这是使用Wireshark读取的ARP消息的示例:
No. Time Source Destination Protocol Length Info
11 0.620140000 CameoCom_e9:0b:a5 Broadcast ARP 42 Who has 192.168.2.104? Tell 192.168.2.1
Frame 11: 42 bytes on wire (336 bits), 42 bytes captured (336 bits) on interface 0
Interface id: 0 (\Device\NPF_{7E4440AD-DCD2-4498-BC69-E8DF0CEB48AB})
Encapsulation type: Ethernet (1)
Arrival Time: Dec 20, 2012 01:10:07.389971000 Argentina Standard Time
[Time shift for this packet: 0.000000000 seconds]
Epoch Time: 1355976607.389971000 seconds
[Time delta from previous captured frame: 0.117128000 seconds]
[Time delta from previous displayed frame: 0.117128000 seconds]
[Time since reference or first frame: 0.620140000 seconds]
Frame Number: 11
Frame Length: 42 bytes (336 bits)
Capture Length: 42 bytes (336 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: eth:ethertype:arp]
[Coloring Rule Name: ARP]
[Coloring Rule String: arp]
Ethernet II, Src: CameoCom_e9:0b:a5 (00:18:e7:e9:0b:a5), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Destination: Broadcast (ff:ff:ff:ff:ff:ff)
Address: Broadcast (ff:ff:ff:ff:ff:ff)
.... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
.... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
Source: CameoCom_e9:0b:a5 (00:18:e7:e9:0b:a5)
Address: CameoCom_e9:0b:a5 (00:18:e7:e9:0b:a5)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
Type: ARP (0x0806)
Address Resolution Protocol (request)
Hardware type: Ethernet (1)
Protocol type: IP (0x0800)
Hardware size: 6
Protocol size: 4
Opcode: request (1)
Sender MAC address: CameoCom_e9:0b:a5 (00:18:e7:e9:0b:a5)
Sender IP address: 192.168.2.1 (192.168.2.1)
Target MAC address: 00:00:00_00:00:00 (00:00:00:00:00:00)
Target IP address: 192.168.2.104 (192.168.2.104)
如果您不使用IP,您仍然可以使用此技术。如果您实现自己的第2层或第3层协议,则节点可以向以太网广播发送消息以了解邻居的地址(您可以使用ARP或您自己的实现)。
节点还可以嗅探LAN流量,了解发送消息的所有邻居的HW地址。
我认为根据您的需要,您可以了解如何做到这一点。