IP TCP UDP数据报头的相关记录

IP TCP UDP数据报头的相关记录

IP数据报头

typedef struct _IP_HEADER_V4_
{
	union
	{
		UINT8 versionAndHeaderLength;
		struct
		{
			UINT8 headerLength : 4;
			UINT8 version : 4;
		};
	};
	union
	{
		UINT8  typeOfService;
		UINT8  differentiatedServicesCodePoint;
		struct
		{
			UINT8 explicitCongestionNotification : 2;
			UINT8 typeOfService6bit : 6;
		};
	};
	UINT16 totalLength;
	UINT16 identification;
	union
	{
		UINT16 flagsAndFragmentOffset;
		struct
		{
			UINT16 fragmentOffset : 13;
			UINT16 flags : 3;
		};
	};
	UINT8  timeToLive;
	UINT8  protocol;
	UINT16 checksum;
	BYTE   pSourceAddress[sizeof(UINT32)];
	BYTE   pDestinationAddress[sizeof(UINT32)];
}IP_HEADER_V4, *PIP_HEADER_V4;
IP报头的长度
    IP_HEADER_V4 pHeader;
    int nLength = pHeader.headerLength * 4;

TCP数据报头

typedef struct _TCP_HEADER_
{
	UINT16 sourcePort;
	UINT16 destinationPort;
	UINT32 sequenceNumber;
	UINT32 acknowledgementNumber;
	union
	{
		UINT8 dataOffsetReservedAndNS;
		struct
		{
			UINT8 nonceSum : 1;
			UINT8 reserved : 3;
			UINT8 dataOffset : 4;
		}dORNS;
	};
	union
	{
		UINT8 controlBits;
		struct
		{
			UINT8 FIN : 1;
			UINT8 SYN : 1;
			UINT8 RST : 1;
			UINT8 PSH : 1;
			UINT8 ACK : 1;
			UINT8 URG : 1;
			UINT8 ECE : 1;
			UINT8 CWR : 1;
		};
	};
	UINT16 window;
	UINT16 checksum;
	UINT16 urgentPointer;
}TCP_HEADER, *PTCP_HEADER;
TCP报头的长度
    TCP_HEADER pHeader;
    int nLength = pHeader.dORNS.dataOffset * 4;

UDP数据报头

typedef struct _UDP_HEADER_
{
	UINT16 sourcePort;
	UINT16 destinationPort;
	UINT16 length;
	UINT16 checksum;
}UDP_HEADER, *PUDP_HEADER;
UDP报头的长度 = 固定长度

网络字节序的相互转换

checksum值的计算

posted @ 2023-02-26 22:04  是谁走漏了消息  阅读(42)  评论(0编辑  收藏  举报