您的位置:首页 > 其它

ICMP 协议报头分析与ping相关的疑问

2013-09-28 17:48 399 查看
ICMP协议是网络层中一个非常重要的协议,其全称为Internet Control Message Protocol(因特网控制报文协议),ICMP协议弥补了IP的缺限,它使用IP协议进行信息传递,向数据包中的源端节点提供发生在网络层的错误信息 反馈。ICMP报头为:

type(8)

code(8)

checksum(16)

ID(16)

Sequence(16)

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应用的区分。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: