TCP包结构简介

来源:互联网 发布:cocos2d.js sdk 编辑:程序博客网 时间:2024/06/05 14:29

TCP Header

这里写图片描述

按照上图BIT坐标:

  • 0-0 至 0-15 发送方端口;
  • 0-16 至 0-31 接收方端口;
  • 32-0 至 32-31 sequence number,TCP序列号;!!!
  • 64-0 至 64-31 ack number,TCP确认号,为TCP序列号+1;
  • 96-0 至 96-3 数据偏移量;
  • 96-4 至 96-6 预留位;
  • 96-7 至 96-15 FLAG 标志位;
  • 96-16 至 96-31 缓冲区大小;
  • 128-0 至 128-15 校验位;
  • 128-16 至 128-31 标识urgent data的位置;
  • 160-0 至 … 选项段;

TCP FLAG 标志位

  1. NS (1 bit): ECN-nonce - concealment protection (experimental: see RFC 3540).
  2. CWR (1 bit): Congestion Window Reduced (CWR) flag is set by the sending host to indicate that it received a TCP segment with the ECE flag set and had responded in congestion control mechanism (added to header by RFC 3168).
  3. ECE (1 bit): ECN-Echo has a dual role, depending on the value of the SYN flag. It indicates:
    • If the SYN flag is set (1), that the TCP peer is ECN capable.
    • If the SYN flag is clear (0), that a packet with Congestion Experienced flag set (ECN=11) in IP header was received during normal transmission (added to header by RFC 3168). This serves as an indication of network congestion (or impending congestion) to the TCP sender.
  4. URG (1 bit): indicates that the Urgent pointer field is significant
  5. ACK (1 bit): indicates that the Acknowledgment field is significant. All packets after the initial SYN packet sent by the client should have this flag set.
  6. PSH (1 bit): Push function. Asks to push the buffered data to the receiving application.
  7. RST (1 bit): Reset the connection
  8. SYN (1 bit): Synchronize sequence numbers. Only the first packet sent from each end should have this flag set. Some other flags and fields change meaning based on this flag, and some are only valid for when it is set, and others when it is clear.
  9. FIN (1 bit): Last packet from sender.

标志位对应的位置在上图中BIT坐标:96-7 至 96-15;

原创粉丝点击