arp学习笔记(linux高性能服务编程)

先看看arp的定义吧

image

现在linux运行这条命令

tcpdump -i eth0:1 -ent '(dst 192.168.5.190 and src 192.168.5.109)or( dst 192.168.5.109 and src 192.168.5.190)' -x

bc:ee:7b:9d:ee:02 > Broadcast, ethertype ARP (0x0806), length 60: Request who-has 192.168.5.190 tell 192.168.5.109, length 46
    0x0000:  0001 0800 0604 0001 bcee 7b9d ee02 c0a8
    0x0010:  056d 0000 0000 0000 c0a8 05be 0000 0000
    0x0020:  0000 0000 0000 0000 0000 0000 0000
40:16:7e:79:c7:36 > bc:ee:7b:9d:ee:02, ethertype ARP (0x0806), length 42: Reply 192.168.5.190 is-at 40:16:7e:79:c7:36, length 28
    0x0000:  0001 0800 0604 0002 4016 7e79 c736 c0a8
    0x0010:  05be bcee 7b9d ee02 c0a8 056d

我们同时把 数据16进制打印出来了

先 分析 请求arp的包

0001 ---表示硬件类型为mac地址

0800 ---表示要映射的协议类型,这里为ip地址

06    ---表示mac地址长度

04    ---表示ip地址长度

0001 ---表示 arp请求

bcee 7b9d ee02  ---发送方mac地址啦 也就是本机啦

c0a8 056d ---发送方ip 192.168.5.109

0000 0000 0000 --- 目标mac,这里是全网啦,未知

c0a8 05be --- 目标端ip地址,也就是 192.168.5.190

再分析 arp响应的包

0001 ---表示硬件类型为mac地址

0800 ---表示要映射的协议类型,这里为ip地址

06    ---表示mac地址长度

04    ---表示ip地址长度

0002 ---表示 arp响应

4016 7e79 c736 --- 发送方mac地址

c0a8 05be ---发送方ip地址

bcee 7b9d ee02 ---接收mac地址

c0a8 056d ---接收方ip地址

 

image 

image

arp的数据长度不足46,所以要补0啦 啦,这是一个规定

为什么能看到回应是42字节而请求是60字节。因为回应这层数据还没通过太网设备驱动程序,如果是2台PC通讯的话,再另外一台上看,一定是60字节的哦!刚开始我也很迷惘
谢谢这位大哥 http://blog.163.com/cailing_07@126/blog/static/339150872011112693647977/ 解惑
 
posted @ 2015-03-10 19:08  见吻戏哦  阅读(1263)  评论(0编辑  收藏  举报