• ICMP报文的各种格式和种类


    ICMP格式和种类

    各种ICMP报文的前32bits都是三个长度固定的字段:type类型字段(8)code代码字段(8)checksum校验和字段(16) 8bits类型和8bits代码字段:一起决定了ICMP报文的类型。

    这里是FRC中关于ICMP报文格式的说明:

    RFC 792

     

    Message Formats

       ICMP messages are sent using the basic IP header.  The first octet of

       the data portion of the datagram is a ICMP type field; the value of

       this field determines the format of the remaining data.  Any field

       labeled "unused" is reserved for later extensions and must be zero

       when sent, but receivers should not use these fields (except to

       include them in the checksum).  Unless otherwise noted under the

       individual format descriptions, the values of the internet header

       fields are as follows:

       Version

          4

       IHL

          Internet header length in 32-bit words.

       Type of Service

          0

       Total Length

          Length of internet header and data in octets.

       Identification, Flags, Fragment Offset

          Used in fragmentation, see [1].

       Time to Live

          Time to live in seconds; as this field is decremented at each

          machine in which the datagram is processed, the value in this

          field should be at least as great as the number of gateways which

          this datagram will traverse.

       Protocol

          ICMP = 1

       Header Checksum

          The 16 bit one's complement of the one's complement sum of all 16

          bit words in the header.  For computing the checksum, the checksum

          field should be zero.  This checksum may be replaced in the

          future.

    常见的有:

    类型0、代码0:回应应答。

    类型3、代码0:网络不可达

    类型3、代码1:主机不可达

    类型5、代码1:为主机重定向数据包

    类型8、代码0:回应

    类型11、代码0:传输中超出TTL(常说的超时)

     16bits校验和字段:包括数据在内的整个ICMP数据包的校验和,其计算方法和IP头部校验和的计算方法是一样的。

    下图是一张ICMP回应请求和应答报文头部格式

                                                         3

        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1bit

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

          Type         Code              Checksum             |

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                 identify           |     sequence                  |

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                options                             |

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    对于ICMP回应请求和应答报文来说,接下来是16bits标识符字段:用于标识本ICMP进程。最后是16bits序列号字段:用于判断回应应答数据报。ICMP报文包含在IP数据报中,属于IP的一个用户,IP头部就在ICMP报文的前面一个ICMP报文包括IP头部(20字节)、ICMP头部(8字节)和ICMP报文IP头部的Protocol值为1就说明这是一个ICMP报文ICMP头部中的类型(Type)域用于说明ICMP报文的作用及格式此外还有代码(Code)域用于详细说明某种ICMP报文的类型所有数据都在ICMP头部后面。RFC定义了13ICMP报文格式,具体如下:

    类型代码 类型描述

    0 响应应答(ECHO-REPLY

    3 不可到达

    4 源抑制

    5 重定向

    8 响应请求(ECHO-REQUEST

    11 超时

    12 参数失灵

    13 时间戳请求

    14 时间戳应答

    15 信息请求(*已作废)

    16 信息应答(*已作废)

    17 地址掩码请求

    18 地址掩码应答

    30 路由跟踪

    其中代码为1516的信息报文已经作废。

    下面是几种常见的ICMP报文:

    1.响应请求

    我们日常使用最多的ping,就是响应请求(Type=8)和应答(Type=0),一台主机向一个节点发送一个Type=8ICMP报文,如果途中没有异常(例如被路由器丢弃、目标不回应ICMP或传输失败),则目标返回Type=0ICMP报文,说明这台主机存在,更详细的tracert通过计算ICMP报文通过的节点来确定主机与目标之间的网络距离。

    2.目标不可到达、源抑制和超时报文

    这三种报文的格式是一样的,目标不可到达报文(Type=3)在路由器或主机不能传递数据报时使用,例如我们要连接对方一个不存在的系统端口(端口号小于1024)时,将返回Type=3Code=3ICMP报文,它要告诉我们:嘿,别连接了,我不在家的!,常见的不可到达类型还有网络不可到达(Code=0)、主机不可到达(Code=1)、协议不可到达(Code=2)等。源抑制则充当一个控制流量的角色,它通知主机减少数据报流量,由于ICMP没有恢复传输的报文,所以只要停止该报文,主机就会逐渐恢复传输速率。最后,无连接方式网络的问题就是数据报会丢失,或者长时间在网络游荡而找不到目标,或者拥塞导致主机在规定时间内无法重组数据报分段,这时就要触发ICMP超时报文的产生。超时报文的代码域有两种取值:Code=0表示传输超时,Code=1表示重组分段超时。

    以下是针对目标不可达的RFC文档摘要:

    RFC 792

     

     

    Destination Unreachable Message

                                                           3

        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

          Type         Code              Checksum             |

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                  unused                            |

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

           Internet Header + 64 bits of Original Data Datagram      |

       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

     

     

      IP Fields:

       Destination Address

          The source network and address from the original datagram's data.

       ICMP Fields:

       Type

          3

       Code

          0 = net unreachable;

          1 = host unreachable;

          2 = protocol unreachable;

          3 = port unreachable;

          4 = fragmentation needed and DF set;

          5 = source route failed.

       Checksum

          The checksum is the 16-bit ones's complement of the one's

          complement sum of the ICMP message starting with the ICMP Type.

          For computing the checksum , the checksum field should be zero.

          This checksum may be replaced in the future.

       Internet Header + 64 bits of Data Datagram

          The internet header plus the first 64 bits of the original

    3.时间戳

    时间戳请求报文(Type=13)和时间戳应答报文(Type=14)用于测试两台主机之间数据报来回一次的传输时间。传输时,主机填充原始时间戳,接收方收到请求后填充接收时间戳后以Type=14的报文格式返回,发送方计算这个时间差。一些系统不响应这种报文。

    ICMP的种类

    ICMP虽然是网络层的协议,但要将ICMP报文放入IP中发送。ICMP报文的公共头标由1字节的类型(type)、1字节的 码(code)和2字节的校验和(checksum)组成。类型域和代码域用来标识各种ICMP报文。类型域表示ICMP报文的类型,目前已定义了14种,从类型值来看ICMP报文可分为二大类。第1 类是取值为1~127的差错报文,第2类是取值128以上的是信息(informational)报文。
    1
    不能到达信宿(Destination Unreachable)差错报文 
    2
    分组过大(Packet Too Big)差错报文 
    3
    超时(Time Exceeded)差错报文 
    4
    参数问题(Parameter Problem)差错报文 
    128
    返回请求(Echo Request)报文 
    129
    返回应答(Echo Reply)报文 
    130
    组成员查询(Group Membership Query 
    131
    组成员报告(Group Membership Report 
    132
    组成员结束(Group Membership Termination 
    133
    路由器请求(Router Solicitation 
    134
    路由器公告(Router Advertisement 
    135
    邻机请求(Neighbor Solicitation 
    136
    邻机公告(Neighbor Advertisement 
    137
    重定向(Redirect

     

  • 相关阅读:
    彻底理解多态
    变量可以存储在堆中,栈中,方法区中。哪里都可以啊。对象只能存储在堆中
    json序列化后的是字符串,不是二进制。是字符串!!!确定不是二进制!!!
    线程流程理解
    增加一个类的功能可以采用继承或者代理模式或者装饰者模式
    Java 代理模式和装饰者模式的区别
    异常不管咋样,只要抛出了,不管是方法级别抛出,还是类级别抛出。终究有一个地方要对异常进行处理
    汉高澳大利亚sinox为什么不能下载源代码,因为sinox执行unix/linux/windows规划
    使用Visual Studio将Objective-C编译C++
    百度编辑器ueditor简单易用
  • 原文地址:https://www.cnblogs.com/4geek/p/12685550.html
Copyright © 2020-2023  润新知