18,356
社区成员
发帖
与我相关
我的任务
分享
// Definition of IP header
typedef struct _ipheader
{
UINT headerLen : 4; // Length of the header
UINT version : 4; // Version of IP
UCHAR tos; // Type of service
USHORT totalLen; // Total length of the packet
USHORT id; // Unique identifier
USHORT flagsAndFrag; // Flags and Fragment Offset
UCHAR ttl; // Time to live
UCHAR proto; // Protocol (TCP, UDP etc)
USHORT checksum; // IP checksum
ULONG sourceIP;
ULONG destIP;
} IPHeader;
// Definition of IP options
typedef struct _ipoptions
{
UCHAR code; // Options type
UCHAR len; // Length of options
UCHAR ptr; // Offset into options
ULONG addr[9]; // List of IP addrs
} IPOptions;
IPHeader * pIPHeader = (IPHeader *)pPacket;
// Number of 32-bit words * 4 = bytes
int ipHeaderLen = pIPHeader->headerLen * 4;
ICMPHeader * pIcmpHeader = (ICMPHeader *)(pPacket + ipHeaderLen);