📄 packetheader.h
字号:
///-----------------------------
//数据包头结构体
//方便构造各类数据包头
//Author:Rex Ding
//#include "packetHeader.h"
///-----------------------------
//#include "pcap.h"
typedef struct ip_address //IP地址的结构体形式
{
u_char byte1;
u_char byte2;
u_char byte3;
u_char byte4;
}ip_address;
typedef struct EtherHeader //数据链路层头部,以太网下14字节
{
unsigned char DesMAC[6]; /* destination HW addrress */
unsigned char SrcMAC[6]; /* source HW addresss */
unsigned short Ethertype; /* ethernet type */
}ether_header;
typedef struct IPHeader //IP层头部20字节
{
u_char ver_ihl; // Version (4 bits) + Internet header length (4 bits)
u_char tos; // Type of service
u_short tlen; // Total length
u_short identification; // Identification
u_short flags_fo; // Flags (3 bits) + Fragment offset (13 bits)
u_char ttl; // Time to live
u_char proto; // Protocol
u_short crc; // Header checksum
ip_address saddr; // Source address
ip_address daddr; // Destination address
u_int op_pad; // Option + Padding
}ip_header;
typedef struct UDPHeader //UDP头部8字节
{
u_short sport; // Source port
u_short dport; // Destination port
u_short len; // Datagram length
u_short crc; // Checksum
}udp_header;
typedef struct DHCPHeader //DHCP报文236字节+4字节MagicCookie
{
u_char OP; //应答模式
u_char h_type; //硬件类型
u_char h_len; //硬件长度
u_char hops; //DHCP RELAY的跳数
u_int xid; //事务ID
u_short seconds; //经过的秒数
u_short flags; //标志位
u_long ciaddr; //客户机地址
u_long yiaddr; //服务器给你的地址
u_long sevraddr; //服务器的地址
u_long giaddr; //中继地址
u_char chaddr[16]; //客户机硬件地址
u_char servername[64]; //服务器名字
u_char file[128]; //启动文件
//选项字段---表示DHCP的各种操作,不定长
//u_int magcookie; //BOOTP头部
}dhcp_header;
//DHCP Option内容
typedef struct DHCPMess //DHCP报文消息类型3字节
{
u_char code;
u_char len;
u_char value;
}dhcpmessage;
typedef struct ClientIdentifier //DHCP客户端标示8字节
{
u_char code;
u_char len;
u_char ClientMAC[6];
}clientID;
typedef struct ServerIdentifier //DHCP服务端标示6字节
{
u_char code;
u_char len;
u_long SerIPaddr;
}serverID;
typedef struct LeaseTime //DHCP服务端给的租约时间4字节
{
u_char code;
u_char len;
u_int time;
}lease_time;
//typedef struct RPL //DHCP请求IP地址6字节
//{
// u_char code;
// u_char len;
// u_char SUBNETMASK;
// u_char BROADCASTADDR;
// u_char TIMEOFFSET;
// u_char ROUTER;
// u_char DOMAINNAME;
// u_char DHCP_DNS;
// u_char HOSTNAME;
//}requestPL;
//typedef struct RequestIP //DHCP请求IP地址6字节
//{
// u_char code;
// u_char len;
// ip_address reqIPaddr;
//}requestIP;
typedef struct DHCPOption //DHCP选项字段
{
u_long magcookie; //BOOTP头部
dhcpmessage dhcpmess;
}dhcpoption;
typedef struct Offer_Option //DHCP选项字段
{
u_long magcookie; //BOOTP头部4字节
dhcpmessage dhcpmess; //3字节
serverID server_id; //code+len2字节+4字节ip
}offer_op;
typedef struct ACK_Option //DHCP选项字段
{
u_long magcookie; //BOOTP头部
dhcpmessage dhcpmess;
serverID server_id;
lease_time lease_ti;
}ack_op;
typedef struct TCPHeader //TCP层头部20字节
{
u_short tcp_src_port; //Source port
u_short tcp_dst_port; //Destination port
u_long tcp_sequence; //序号
u_long tcp_ack; //确认号
u_char tcp_unknow; //未知比特
u_char tcp_flag; //标志比特
u_short tcp_window; //窗口大小
u_short tcp_checksum; //校验和
u_short tcp_urgent_pointer;//紧急指针
}tcp_header;
typedef struct ARPHeader //ARP数据帧结构
{
u_short arp_hardware_type; //硬件地址类型
u_short arp_protocol_type; //协议地址类型
u_char arp_hardware_lenth; //硬件地址lenth
u_char arp_protocol_lenth; //协议地址lenth
u_short arp_operation_code; //操作类型
u_char enet_src[6]; //源硬件地址
u_long src_ip; //源IP地址
u_char enet_dst[6]; //源硬件地址
u_long dst_ip; //源IP地址
}arp_header;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -