?? protoinfo.h
字號:
//////////////////////////////////////////////////
// protoinfo.h文件
/*
定義協議格式
定義協議中使用的宏
*/
#ifndef __PROTOINFO_H__
#define __PROTOINFO_H__
#define ETHERTYPE_IP 0x0800
#define ETHERTYPE_ARP 0x0806
typedef struct _ETHeader // 14字節的以太頭
{
UCHAR dhost[6]; // 目的MAC地址destination mac address
UCHAR shost[6]; // 源MAC地址source mac address
USHORT type; // 下層協議類型,如IP(ETHERTYPE_IP)、ARP(ETHERTYPE_ARP)等
} ETHeader, *PETHeader;
#define ARPHRD_ETHER 1
// ARP協議opcodes
#define ARPOP_REQUEST 1 // ARP 請求
#define ARPOP_REPLY 2 // ARP 響應
typedef struct _ARPHeader // 28字節的ARP頭
{
USHORT hrd; // 硬件地址空間,以太網中為ARPHRD_ETHER
USHORT eth_type; // 以太網類型,ETHERTYPE_IP ??
UCHAR maclen; // MAC地址的長度,為6
UCHAR iplen; // IP地址的長度,為4
USHORT opcode; // 操作代碼,ARPOP_REQUEST為請求,ARPOP_REPLY為響應
UCHAR smac[6]; // 源MAC地址
UCHAR saddr[4]; // 源IP地址
UCHAR dmac[6]; // 目的MAC地址
UCHAR daddr[4]; // 目的IP地址
} ARPHeader, *PARPHeader;
// 協議
#define PROTO_ICMP 1
#define PROTO_IGMP 2
#define PROTO_TCP 6
#define PROTO_UDP 17
typedef struct _IPHeader // 20字節的IP頭
{
UCHAR iphVerLen; // 版本號和頭長度(各占4位)
UCHAR ipTOS; // 服務類型
USHORT ipLength; // 封包總長度,即整個IP報的長度
USHORT ipID; // 封包標識,惟一標識發送的每一個數據報
USHORT ipFlags; // 標志
UCHAR ipTTL; // 生存時間,就是TTL
UCHAR ipProtocol; // 協議,可能是TCP、UDP、ICMP等
USHORT ipChecksum; // 校驗和
ULONG ipSource; // 源IP地址
ULONG ipDestination; // 目標IP地址
} IPHeader, *PIPHeader;
// 定義TCP標志
#define TCP_FIN 0x01
#define TCP_SYN 0x02
#define TCP_RST 0x04
#define TCP_PSH 0x08
#define TCP_ACK 0x10
#define TCP_URG 0x20
#define TCP_ACE 0x40
#define TCP_CWR 0x80
typedef struct _TCPHeader // 20字節的TCP頭
{
USHORT sourcePort; // 16位源端口號
USHORT destinationPort; // 16位目的端口號
ULONG sequenceNumber; // 32位序列號
ULONG acknowledgeNumber; // 32位確認號
UCHAR dataoffset; // 高4位表示數據偏移
UCHAR flags; // 6位標志位
//FIN - 0x01
//SYN - 0x02
//RST - 0x04
//PUSH- 0x08
//ACK- 0x10
//URG- 0x20
//ACE- 0x40
//CWR- 0x80
USHORT windows; // 16位窗口大小
USHORT checksum; // 16位校驗和
USHORT urgentPointer; // 16位緊急數據偏移量
} TCPHeader, *PTCPHeader;
typedef struct _UDPHeader
{
USHORT sourcePort; // 源端口號
USHORT destinationPort;// 目的端口號
USHORT len; // 封包長度
USHORT checksum; // 校驗和
} UDPHeader, *PUDPHeader;
#endif // __PROTOINFO_H__
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -