[英]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.