ICMP 协议报头分析与ping相关的疑问
2013-09-28 17:48
399 查看
ICMP协议是网络层中一个非常重要的协议,其全称为Internet Control Message Protocol(因特网控制报文协议),ICMP协议弥补了IP的缺限,它使用IP协议进行信息传递,向数据包中的源端节点提供发生在网络层的错误信息 反馈。ICMP报头为:
ICMP类型如下:
#define ICMP_ECHOREPLY 0 /* Echo Reply */
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
#define ICMP_REDIRECT 5 /* Redirect (change route) */
#define ICMP_ECHO 8 /* Echo Request */
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
#define ICMP_TIMESTAMP 13 /* Timestamp Request */
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
#define ICMP_INFO_REQUEST 15 /* Information Request */
#define ICMP_INFO_REPLY 16 /* Information Reply */
#define ICMP_ADDRESS 17 /* Address Mask Request */
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
#define NR_ICMP_TYPES 18
Code:进一步划分ICMP的类型,是对上面TYPE的补充,下面是相应的定义
/* Codes for UNREACH. */
#define ICMP_NET_UNREACH 0 /* Network Unreachable */
#define ICMP_HOST_UNREACH 1 /* Host Unreachable */
#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */
#define ICMP_PORT_UNREACH 3 /* Port Unreachable */
#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */
#define ICMP_SR_FAILED 5 /* Source Route failed */
#define ICMP_NET_UNKNOWN 6
#define ICMP_HOST_UNKNOWN 7
#define ICMP_HOST_ISOLATED 8
#define ICMP_NET_ANO 9
#define ICMP_HOST_ANO 10
#define ICMP_NET_UNR_TOS 11
#define ICMP_HOST_UNR_TOS 12
#define ICMP_PKT_FILTERED 13 /* Packet filtered */
#define ICMP_PREC_VIOLATION 14 /* Precedence violation */
#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */
#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */
/* Codes for REDIRECT. */
#define ICMP_REDIR_NET 0 /* Redirect Net */
#define ICMP_REDIR_HOST 1 /* Redirect Host */
#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */
#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */
/* Codes for TIME_EXCEEDED. */
#define ICMP_EXC_TTL 0 /* TTL count exceeded */
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
Checksum:校验和,用于检查错误的数据
ID:这个字段包含了ID值,在echo reply类型的消息中需要返回这个值
Sequence:这个字段主要是echo reply类型的消息使用,在echo reply类型的消息中需要返回这个值。
疑问:当同一个终端里有两个ping同一个远程ip的应用时,终端是如何区分接收到的ping回复报文呢?
主要是使用ID、Sequence这两个值来区分,其中ping应用程序的echo request会将ID设置为该ping程序的PID,并将Sequence设为计数器,并递增该值。通过这两个值就可以保证对ping应用的区分。
type(8) | code(8) | checksum(16) |
ID(16) | Sequence(16) |
#define ICMP_ECHOREPLY 0 /* Echo Reply */
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
#define ICMP_REDIRECT 5 /* Redirect (change route) */
#define ICMP_ECHO 8 /* Echo Request */
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
#define ICMP_TIMESTAMP 13 /* Timestamp Request */
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
#define ICMP_INFO_REQUEST 15 /* Information Request */
#define ICMP_INFO_REPLY 16 /* Information Reply */
#define ICMP_ADDRESS 17 /* Address Mask Request */
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
#define NR_ICMP_TYPES 18
Code:进一步划分ICMP的类型,是对上面TYPE的补充,下面是相应的定义
/* Codes for UNREACH. */
#define ICMP_NET_UNREACH 0 /* Network Unreachable */
#define ICMP_HOST_UNREACH 1 /* Host Unreachable */
#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */
#define ICMP_PORT_UNREACH 3 /* Port Unreachable */
#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */
#define ICMP_SR_FAILED 5 /* Source Route failed */
#define ICMP_NET_UNKNOWN 6
#define ICMP_HOST_UNKNOWN 7
#define ICMP_HOST_ISOLATED 8
#define ICMP_NET_ANO 9
#define ICMP_HOST_ANO 10
#define ICMP_NET_UNR_TOS 11
#define ICMP_HOST_UNR_TOS 12
#define ICMP_PKT_FILTERED 13 /* Packet filtered */
#define ICMP_PREC_VIOLATION 14 /* Precedence violation */
#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */
#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */
/* Codes for REDIRECT. */
#define ICMP_REDIR_NET 0 /* Redirect Net */
#define ICMP_REDIR_HOST 1 /* Redirect Host */
#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */
#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */
/* Codes for TIME_EXCEEDED. */
#define ICMP_EXC_TTL 0 /* TTL count exceeded */
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
Checksum:校验和,用于检查错误的数据
ID:这个字段包含了ID值,在echo reply类型的消息中需要返回这个值
Sequence:这个字段主要是echo reply类型的消息使用,在echo reply类型的消息中需要返回这个值。
疑问:当同一个终端里有两个ping同一个远程ip的应用时,终端是如何区分接收到的ping回复报文呢?
主要是使用ID、Sequence这两个值来区分,其中ping应用程序的echo request会将ID设置为该ping程序的PID,并将Sequence设为计数器,并递增该值。通过这两个值就可以保证对ping应用的区分。
相关文章推荐
- Linux icmp 学习笔记 之三 icmp相关疑问分析
- ping 之icmp 协议分析
- 利用WireShark分析由Ping产生的Internet 控制报文协议(ICMP)
- 网络协议分析工具Wireshark的使用、用Wireshark观察ARP协议以及ping命令的工作过程分析以太网报文格式
- ICMP协议之ping实现
- ping 原理与ICMP协议
- ICMP协议Ping命令的应用
- TCP/IP之ICMP(Internet控制报文协议),Ping程序和Traceroute程序
- ping 原理与ICMP协议
- 协议[I2C]_I2C子系统之__I2C_first_dynamic_bus_num变量的相关分析
- spice 协议相关分析总结
- ICMP协议之ping实现
- 蓝牙协议分析(5)_BLE广播通信相关的技术分析
- TCP/IP详解卷1:协议(五)【ICMP:Internet控制报文协议,Ping程序】
- 使用Wireshark简单分析ICMP报文(ping)
- 网络层协议IP/ICMP/DHCP/ARP/TCP数据的捕获与分析
- ICMP协议规范:一种用于网络管理的协议。对照它您可以想一想PING命令实现的机理
- CBCentralManagerDelegate Protocol 委托协议相关分析
- ping 原理与ICMP协议