zoukankan      html  css  js  c++  java
  • 数据包结构 校验和 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

  • 相关阅读:
    WINCE/WM5.0如何让安装完后自动运行程序
    Android 图片透明度处理代码
    windows mobile UI 自定义开始菜单图标
    Windows mobile 6捕获键盘操作
    HTTP的post和get总结
    提供一个Windows mobile Native UI 程序,循序渐进开发,并附有代码!
    Windows Mobile 中ComboBox【下拉列表】的使用
    注册表修改今日桌面左右软键的功能
    .net compact framework 注册表操作
    两种实现Toast 的例子(图片&文字)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15048293.html
Copyright © 2011-2022 走看看