数据据包的发送流程(Packet Deilvery)

2017-06-10  本文已影响0人  水雨田

数据据包的发送流程(Packet Deilvery)

我们都知道两都主机通信时会相互发送数据包给对方,但是具体是如何发送的呢?这就需要分两种情况来看:两台主机在同一个网段两台主机在不同的网段

两台主机在同一个网段

比如,我们有如下两台主机PC1和PC2:


 -----                                                                  -----
| PC1 |                                                                | PC2 | 
 -----                                                                  -----
   |  IP  address: 10.1.1.1            IP  address: 192.168.1.2           |   
   |  MAC address: 0800:1111.1111      MAC address:0800:2222:2222         |                         
   |                                                                      |
   |                                                                      | 
  --------------------------------------------------------------------------

现在PC1要给PC2发送数据,流程如下:

此时数据包如下:

Source IP address Target IP address
192.168.1.1 192.168.1.2
$ arp -a
? (192.168.1.10) at e4:8d:8c:35:19:68 on en0 ifscope [ethernet]
? (192.168.1.11) at cc:29:f5:ae:6c:4 on en0 ifscope [ethernet]
? (192.168.1.33) at e4:e4:ab:6a:ae:f2 on en0 ifscope [ethernet]

发现没有目标主机的MAC地址记录,则通过ARP协议查询主机的MAC地址。

此时数据包如下:

Source IP address Target IP address Source MAC address Target MAc address
192.168.1.1 192.168.1.2 0800:1111:1111 0800:2222:2222

两台主机不在同一个网段

比如,我们有如下两台主机PC1和PC2:


 -----                                                                  -----
| PC1 |                                                                | PC2 | 
 -----                                                                  -----
   |  IP  address: 10.1.1.1            IP  address: 192.168.1.1           |   
   |  MAC address: 0800:1111.1111      MAC address:0800:2222:2222         |                         
   |                                                                      |
   |                               ------                                 | 
  -------------------------------| Router |  -------------------------------
                                   ------    
                                /          \
           IP  address: 10.1.1.254         IP  address: 192.168.1.254
           MAC address: 0800:aaaa:aaaa     MAC address: 0800:bbbb:bbbb

"两台主机不在同一网段"和"两台主机在同一网段"大部分流程是一样的,不同之处在于:

此时数据包如下:

Source IP address Target IP address Source MAC address Target MAc address
10.1.1.1 192.168.1.1 0800:1111:1111 0800:aaaa:aaaa

此时数据包如下:

Source IP address Target IP address Source MAC address Target MAc address
10.1.1.1 192.168.1.1 0800:aaaa:aaaa 0800:2222:2222
上一篇下一篇

猜你喜欢

热点阅读