Skip to content

Commit

Permalink
docs: arp doc
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Feb 18, 2024
1 parent a40404d commit 502c9a4
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 2 deletions.
85 changes: 84 additions & 1 deletion src/en/guide/concepts/network/5-arp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,87 @@ order: 5
title: ARP
---

##
## Introduction

The **Address Resolution Protocol (ARP)** is an important protocol in IPv4 that is used to determine the MAC address of a target device based on its IP address, ensuring the correct delivery of data.

::: tip MAC Address
The Media Access Control Address (MAC) is also known as the hardware address, which uniquely identifies network devices such as network cards and routers. The MAC address is 48 bits long, with the first 24 bits managed by IEEE and the last 24 bits managed by hardware vendors. Unlike the dynamic allocation of IP addresses, MAC addresses are generally written into firmware or hardware and cannot be modified.

> MAC: `FF-FF-FF-FF-FF-FF` is the reserved broadcast address.
::: details Structure of MAC Address

| Bits | Meaning |
| -------------- | ---------------------------------------------- |
| 1st bit | Unicast address (0)/Multicast address (1) |
| 2nd bit | Global address (0)/Local address (1) |
| 3rd-24th bits | Managed by IEEE and guaranteed to be unique |
| 25th-48th bits | Managed by vendors and guaranteed to be unique |

:::

## ARP Packet

### Packet Format

<table style="text-align:center;">
<tbody>
<tr>
<th>Length (bits)</th>
<th>48</th>
<th>48</th>
<th>16</th>
<th>16</th>
<th>16</th>
<th>8</th>
<th>8</th>
<th>16</th>
<th>48</th>
<th>32</th>
<th>48</th>
<th>32</th></tr>
<tr>
<td>
<b>Data Type</b>
</td>
<td>Destination Ethernet Address</td>
<td>Source Ethernet Address</td>
<td>Frame Type</td>
<td>Hardware Type</td>
<td>Protocol Type</td>
<td>Hardware Address Length</td>
<td>Protocol Address Length</td>
<td>Operation Code</td>
<td>Source Hardware Address</td>
<td>Source Protocol Address</td>
<td>Destination Hardware Address</td>
<td>Destination Protocol Address</td></tr>
<tr>
<td>
<b>Composition</b>
</td>
<td colspan="3">14 bytes Ethernet header</td>
<td colspan="9">28 bytes ARP request/response</td></tr>
</tbody>
</table>

::: tip


| Field | Length | Description |
| ------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------ |
| Ethernet destination MAC | 48 bits | Ethernet destination MAC address. This field in an ARP Request packet is the broadcast address `0xffff-ffff-ffff` |
| Ethernet source MAC | 48 bits | Ethernet source MAC address. |
| Frame type | 16 bits | Data type. The value of this field is `0x0806` for an ARP Request or Reply packet |
| Hardware type | 16 bits | Type of the hardware address. The value of this field is 1 for an Ethernet. |
| Protocol type | 16 bits | Type of the protocol address to be mapped on the sender. The value of this field is `0x0800` for an IP address. |
| Hardware address length | 8 bits | Hardware address length. The value of this field is `6` for an ARP Request or Reply packet. |
| Protocol address length | 8 bits | Protocol address length. The value of this field is `4` for an ARP Request or Reply packet. |
| OP | 16 bits | Operation type. The values are as follows: 1: ARP Request packet 2: ARP Reply packet |
| Source MAC | 48 bits | Source MAC address. The value of this field is the same as the Ethernet source MAC address in the Ethernet frame header. |
| Source IP | 32 bits | Source IP address |
| Destination MAC | 48 bits | Destination MAC address. The value of this field in an ARP Request packet is `0x0000-0000-0000` |
| Destination IP | 32 bits | Destination IP address |

:::
84 changes: 83 additions & 1 deletion src/guide/concepts/network/5-arp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,86 @@ order: 5
title: ARP
---

##
## 介绍

**地址解析协议(Address Resolution Protocol, ARP)** 是 IPV4 中重要的协议,主要用于通过 IP 地址确定目标设备的 MAC 地址,以保证数据的正确送达。

::: tip MAC 地址
媒体访问控制地址 (Media Access Control Address, MAC) 又称为硬件地址,用来**唯一**标识网络设备,如网卡、路由器等。MAC 地址长度为 48 位,3 - 24 位由 IEEE 管理,后 24 位由硬件厂商管理。和 IP 的动态分配不同, MAC 地址一般会写入固件或硬件中,是不可修改的。

> MAC: `FF-FF-FF-FF-FF-FF` 是预留的广播地址
::: details MAC 地址的构成

| 位数 | 含义 |
| --------- | ------------------------ |
| 第1位 | 单播地址(0)/多播地址(1) |
| 第2位 | 全局地址(0)/本地地址(1) |
| 第3-24位 | 由 IEEE 管理并保证不重复 |
| 第25-48位 | 由厂商管理并保证不重复 |

:::

## ARP 报文

### 报文格式

<table style="text-align:center;">
<tbody>
<tr>
<th>长度(位)</th>
<th>48</th>
<th>48</th>
<th>16</th>
<th>16</th>
<th>16</th>
<th>8</th>
<th>8</th>
<th>16</th>
<th>48</th>
<th>32</th>
<th>48</th>
<th>32</th></tr>
<tr>
<td>
<b>数据类型</b>
</td>
<td>目标以太网地址</td>
<td>源以太网地址</td>
<td>帧类型</td>
<td>硬件类型</td>
<td>协议类型</td>
<td>硬件地址长度</td>
<td>协议地址长度</td>
<td>操作码</td>
<td>源硬件地址</td>
<td>源协议地址</td>
<td>目标硬件地址</td>
<td>目标协议地址</td></tr>
<tr>
<td>
<b>组成</b>
</td>
<td colspan="3">14字节 以太网首部</td>
<td colspan="9">28字节 ARP请求/应答</td></tr>
</tbody>
</table>

::: tip

| 字段 | 长度 | 描述 |
| ------------------- | ----- | --------------------------------------------------------------------------- |
| 以太网目标 MAC 地址 | 48 位 | 以太网目标 MAC 地址。在 ARP 请求报文中,该字段为广播地址 `0xffff-ffff-ffff` |
| 以太网源 MAC 地址 | 48 位 | 以太网源 MAC 地址 |
| 帧类型 | 16 位 | 数据类型。该字段的值在 ARP 请求或应答报文中为 `0x0806` |
| 硬件类型 | 16 位 | 硬件地址类型。该字段的值在以太网中为 1 |
| 协议类型 | 16 位 | 要映射到发送方的协议地址类型。该字段的值为 IP 地址时为 `0x0800` |
| 硬件地址长度 | 8 位 | 硬件地址长度。该字段的值在 ARP 请求或应答报文中为 `6` |
| 协议地址长度 | 8 位 | 协议地址长度。该字段的值在 ARP 请求或应答报文中为 `4` |
| 操作码 | 16 位 | 操作类型。值如下:1: ARP 请求报文 2: ARP 应答报文 |
| 源 MAC 地址 | 48 位 | 源 MAC 地址。该字段的值与以太网帧头中的以太网源 MAC 地址相同 |
| 源 IP 地址 | 32 位 | 源 IP 地址 |
| 目标 MAC 地址 | 48 位 | 目标 MAC 地址。在 ARP 请求报文中,该字段为 `0x0000-0000-0000` |
| 目标 IP 地址 | 32 位 | 目标 IP 地址 |

:::

0 comments on commit 502c9a4

Please sign in to comment.