[英]TCP Header and Checksum
我需要澄清在计算校验和时正确使用TCP标头和伪标头。 伪标头是否需要紧跟在IP标头之后和真实TCP标头之前? 这是我所拥有的:
IPHeader *iph = (IPHeader *)(packet + ETHER_SIZE); //ETHER_SIZE == 14
ipLen = ntohs(iph->totLen) * 4;
TCPPseudo *tcps = (TCPPseudo *)(packet + ETHER_SIZE + ipLen);
TCPHeader *tcp = (TCPHeader *)(tcps + sizeof(TCPPseudo));
这是我的标题:
typedef struct __attribute__((__packed__)) IPHeader {
#if __BYTE_ORDER__ == __LITTLE_ENDIAN__
uint8_t hdrLen:4;
uint8_t version:4;
#else
uint8_t version:4;
uint8_t hdrLen:4;
#endif
uint8_t TOS;
uint16_t totLen;
uint16_t id;
uint16_t offset;
#define DF 0x4
#define MF 0x2
#define OFF 0
uint8_t TTL;
uint8_t protocol;
uint16_t checksum;
struct in_addr srcIP;
struct in_addr destIP;
}IPHeader;
typedef struct __attribute__((__packed__)) TCPHeader {
uint16_t srcPort;
uint16_t destPort;
uint32_t seqNum;
uint32_t ackNum;
uint8_t offset:4;
uint8_t res:4;
uint8_t flags;
uint16_t window;
uint16_t checksum;
uint16_t urg;
}TCPHeader;
typedef struct __attribute__((__packed__)) TCPPseudo {
struct in_addr srcAddr;
struct in_addr destAddr;
uint8_t zeroes;
uint8_t protocol;
uint16_t len;
}TCPPseudo;
校验和是否需要同时获取伪头和“真实”头的长度以及两者的地址?
伪标头在物理上不存在。 它不是通过网络发送的数据包的一部分。 它仅用于说明IP头的哪些部分包括在TCP头校验和计算中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.