packet header

#ifndef _HEADER_H
#define _HEADER_H

#include 
//Ethernet packet header
struct EthernetHeader{
	unsigned char mac_dst[6]; 
	unsigned char mac_src[6];
	unsigned short mac_type;
};
//IP packet header
struct IPHeader{ 
    	unsigned char h_verlen; 		//4位首部长度+4位IP版本号 
   	unsigned char tos; 			//8位服务类型TOS 
   	unsigned short total_len; 		//16位总长度(字节) 
   	unsigned short ident; 			//16位标识 
   	unsigned short frag_and_flags; 		//3位标志位 
    	unsigned char ttl; 			//8位生存时间 TTL 
    	unsigned char proto; 			//8位协议 (TCP, UDP 或其他) 
    	unsigned short checksum; 		//16位IP首部校验和 
    	unsigned int sourceIP;			//32位源IP地址 
    	unsigned int destIP; 			//32位目的IP地址 
}; 
//ICMP header
struct ICMPHeader{  
    	unsigned char  icmp_type;  
   	unsigned char  icmp_code; 
    	unsigned short icmp_cksum;  
    	unsigned short icmp_id;  
    	unsigned short icmp_seq;    
    	unsigned short icmp_timestamp;  
};
//UDP header
struct UDPHeader{
    	unsigned short uh_sport;    		//16位源端口
    	unsigned short uh_dport;    		//16位目的端口
   	unsigned int uh_len;			//16位UDP包长度
    	unsigned int uh_sum;			//16位校验和
};
//TCP header
struct TCPHeader{
    	unsigned short th_sport; 		//16位源端口 
    	unsigned short th_dport; 		//16位目的端口 
    	unsigned int   th_seq; 			//32位序列号 
    	unsigned int   th_ack; 			//32位确认号 
    	unsigned char  th_lenres;		//4位首部长度/6位保留字 
    	unsigned char  th_flag; 		//6位标志位
    	unsigned short th_win; 			//16位窗口大小
    	unsigned short th_sum; 			//16位校验和
    	unsigned short th_urp; 			//16位紧急数据偏移量
}; 
//ARP header
struct ARPHeader{
	unsigned short hardware_type;
	unsigned short protocol_type;
	unsigned char  hardware_length;
	unsigned char  protocol_length;
	unsigned short operation;
	char src_mac_addr[6];
	char src_ip_addr[4];
	char dst_mac_addr[6];
	char dst_ip_addr[4];
};
//ARP packet
struct ARPPacket{
	struct EthernetHeader eth_header;
	struct ARPHeader arp_header;
};
#endif


你可能感兴趣的:(ubuntu,C/C++)