• 数据包结构 校验和 TCP checksum for IPv4 TCP checksum for IPv6


    TCP checksum for IPv4[edit]

    When TCP runs over IPv4, the method used to compute the checksum is defined in RFC 793:

    The checksum field is the 16 bit one's complement of the one's complement sum of all 16-bit words in the header and text. If a segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a 16-bit word for checksum purposes. The pad is not transmitted as part of the segment. While computing the checksum, the checksum field itself is replaced with zeros.

    In other words, after appropriate padding, all 16-bit words are added using one's complement arithmetic. The sum is then bitwise complemented and inserted as the checksum field. A pseudo-header that mimics the IPv4 packet header used in the checksum computation is shown in the table below.

    TCP pseudo-header for checksum computation (IPv4)
    Bit offset0–34–78–1516–31
    0 Source address
    32 Destination address
    64 Zeros Protocol TCP length
    96 Source port Destination port
    128 Sequence number
    160 Acknowledgement number
    192 Data offset Reserved Flags Window
    224 Checksum Urgent pointer
    256 Options (optional)
    256/288+  
    Data
     

    The source and destination addresses are those of the IPv4 header. The protocol value is 6 for TCP (cf. List of IP protocol numbers). The TCP length field is the length of the TCP header and data (measured in octets).

    TCP checksum for IPv6[edit]

    When TCP runs over IPv6, the method used to compute the checksum is changed, as per RFC 2460:

    Any transport or other upper-layer protocol that includes the addresses from the IP header in its checksum computation must be modified for use over IPv6, to include the 128-bit IPv6 addresses instead of 32-bit IPv4 addresses.

    A pseudo-header that mimics the IPv6 header for computation of the checksum is shown below.

    TCP pseudo-header for checksum computation (IPv6)
    Bit offset0–78–1516–2324–31
    0 Source address
    32
    64
    96
    128 Destination address
    160
    192
    224
    256 TCP length
    288 Zeros Next header
    = Protocol
    320 Source port Destination port
    352 Sequence number
    384 Acknowledgement number
    416 Data offset Reserved Flags Window
    448 Checksum Urgent pointer
    480 Options (optional)
    480/512+  
    Data
     
      • Source address: the one in the IPv6 header
      • Destination address: the final destination; if the IPv6 packet doesn't contain a Routing header, TCP uses the destination address in the IPv6 header, otherwise, at the originating node, it uses the address in the last element of the Routing header, and, at the receiving node, it uses the destination address in the IPv6 header.
      • TCP length: the length of the TCP header and data
      • Next Header: the protocol value for TCP

    https://en.wikipedia.org/wiki/Transmission_Control_Protocol

  • 相关阅读:
    oracle归档空间不足的问题(rman删除归档日志)
    oracle DG查看延时时间
    Convert JS object to JSON string
    转:微信公众平台开发(80) 上传下载多媒体文件
    生成带参数的二维码
    关闭微信浏览器可以使用
    微信内置浏览器的JsAPI(WeixinJSBridge续)进入全屏
    如何隐藏微信公众平台右上角按钮
    微信公众平台服务号、订阅号的相关说明选择字号:
    微信公众平台群发消息的方法及注意事项
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15048293.html
Copyright © 2020-2023  润新知