packet_types.h

来自「Ubuntu packages of security software。 相」· C头文件 代码 · 共 699 行 · 第 1/2 页

H
699
字号
// IP packet structures...// -----------------------// Note: All of this is hard coded little endian!typedef long n_long;typedef long n_time;struct ip  {    unsigned int ip_hl:4;               /* header length */    unsigned int ip_v:4;                /* version */    u_char ip_tos;                    /* type of service */    u_short ip_len;                     /* total length */    u_short ip_id;                      /* identification */    u_short ip_off;                     /* fragment offset field */#define IP_RF 0x8000                    /* reserved fragment flag */#define IP_DF 0x4000                    /* dont fragment flag */#define IP_MF 0x2000                    /* more fragments flag */#define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */    u_char ip_ttl;                    /* time to live */    u_char ip_p;                      /* protocol */    u_short ip_sum;                     /* checksum */    struct in_addr ip_src, ip_dst;      /* source and dest address */  };#define    MAX_IPOPTLEN            40/* *	IEEE 802.3 Ethernet magic constants.  The frame sizes omit the preamble *	and FCS/CRC (frame check sequence).  */#define ETH_ALEN	6		/* Octets in one ethernet addr	 */#define ETH_HLEN	14		/* Total octets in header.	 */#define ETH_ZLEN	60		/* Min. octets in frame sans FCS */#define ETH_DATA_LEN	1500		/* Max. octets in payload	 */#define ETH_FRAME_LEN	1514		/* Max. octets in frame sans FCS *//* *	These are the defined Ethernet Protocol ID's. */#define ETH_P_LOOP	0x0060		/* Ethernet Loopback packet	*/#define ETH_P_ECHO	0x0200		/* Ethernet Echo packet		*/#define ETH_P_PUP	0x0400		/* Xerox PUP packet		*/#define ETH_P_IP	0x0800		/* Internet Protocol packet	*/#define ETH_P_X25	0x0805		/* CCITT X.25			*/#define ETH_P_ARP	0x0806		/* Address Resolution packet	*/#define	ETH_P_BPQ	0x08FF		/* G8BPQ AX.25 Ethernet Packet	[ NOT AN OFFICIALLY REGISTERED ID ] */#define ETH_P_DEC       0x6000          /* DEC Assigned proto           */#define ETH_P_DNA_DL    0x6001          /* DEC DNA Dump/Load            */#define ETH_P_DNA_RC    0x6002          /* DEC DNA Remote Console       */#define ETH_P_DNA_RT    0x6003          /* DEC DNA Routing              */#define ETH_P_LAT       0x6004          /* DEC LAT                      */#define ETH_P_DIAG      0x6005          /* DEC Diagnostics              */#define ETH_P_CUST      0x6006          /* DEC Customer use             */#define ETH_P_SCA       0x6007          /* DEC Systems Comms Arch       */#define ETH_P_RARP      0x8035		/* Reverse Addr Res packet	*/#define ETH_P_ATALK	0x809B		/* Appletalk DDP		*/#define ETH_P_AARP	0x80F3		/* Appletalk AARP		*/#define ETH_P_IPX	0x8137		/* IPX over DIX			*/#define ETH_P_IPV6	0x86DD		/* IPv6 over bluebook		*//* *	Non DIX types. Won't clash for 1500 types. */ #define ETH_P_802_3	0x0001		/* Dummy type for 802.3 frames  */#define ETH_P_AX25	0x0002		/* Dummy protocol id for AX.25  */#define ETH_P_ALL	0x0003		/* Every packet (be careful!!!) */#define ETH_P_802_2	0x0004		/* 802.2 frames 		*/#define ETH_P_SNAP	0x0005		/* Internal only		*/#define ETH_P_DDCMP     0x0006          /* DEC DDCMP: Internal only     */#define ETH_P_WAN_PPP   0x0007          /* Dummy type for WAN PPP frames*/#define ETH_P_PPP_MP    0x0008          /* Dummy type for PPP MP frames */#define ETH_P_LOCALTALK 0x0009		/* Localtalk pseudo type 	*/#define ETH_P_PPPTALK	0x0010		/* Dummy type for Atalk over PPP*/#define ETH_P_TR_802_2	0x0011		/* 802.2 frames 		*/struct etherproto {	char *s;	u_short p;};extern struct etherproto etherproto_db[];// Ethernet Headerstruct ether_header {	unsigned char	h_dest[ETH_ALEN];	/* destination eth addr	*/	unsigned char	h_source[ETH_ALEN];	/* source ether addr	*/	unsigned short	h_proto;		/* packet type ID field	*/};// ARP/RARP///////////////////////////////////////////////////////////////////////static u_char bcastaddr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };/* *	This structure defines an ethernet arp header. */struct arphdr{	unsigned short	ar_hrd;		/* format of hardware address	*/	unsigned short	ar_pro;		/* format of protocol address	*/	unsigned char	ar_hln;		/* length of hardware address	*/	unsigned char	ar_pln;		/* length of protocol address	*/	unsigned short	ar_op;		/* ARP opcode (command)		*/};#define ARPD_UPDATE	0x01#define ARPD_LOOKUP	0x02#define ARPD_FLUSH	0x03/*#define ARPHRD_ETHER	0x01#define ARPOP_REQUEST	0x01#define ARPOP_REPLY		0x02#define ARPOP_REVREQUEST	0x03#define ARPOP_REVREPLY		0x04*//* * Ethernet Address Resolution Protocol. * * See RFC 826 for protocol description.  Structure below is adapted * to resolving internet addresses.  Field names used correspond to * RFC 826. */struct	ether_arp {	struct	arphdr ea_hdr;	/* fixed-size header */	u_char	arp_sha[ETH_ALEN];	/* sender hardware address */	u_char	arp_spa[4];	/* sender protocol address */	u_char	arp_tha[ETH_ALEN];	/* target hardware address */	u_char	arp_tpa[4];	/* target protocol address */};#define	arp_hrd	ea_hdr.ar_hrd#define	arp_pro	ea_hdr.ar_pro#define	arp_hln	ea_hdr.ar_hln#define	arp_pln	ea_hdr.ar_pln#define	arp_op	ea_hdr.ar_op// IP Header in Little Endian//////////////////////////////struct iphdr {	u_char	ip_hl:4,		/* header length */			ip_v:4;			/* version */	u_char	ip_tos;			/* type of service */	short	ip_len;			/* total length */	u_short	ip_id;			/* identification */	short	ip_off;			/* fragment offset field */#define	IP_DF 0x4000		/* dont fragment flag */#define	IP_MF 0x2000		/* more fragments flag */	u_char	ip_ttl;			/* time to live */	u_char	ip_p;			/* protocol */	u_short	ip_sum;			/* checksum */	struct	in_addr ip_src,ip_dst;	/* source and dest address */};#define	IP_MAXPACKET	65535		/* maximum packet size */// Definitions for options.#define	IPOPT_COPIED(o)		((o)&0x80)#define	IPOPT_CLASS(o)		((o)&0x60)#define	IPOPT_NUMBER(o)		((o)&0x1f)#define	IPOPT_CONTROL		0x00#define	IPOPT_RESERVED1		0x20#define	IPOPT_DEBMEAS		0x40#define	IPOPT_RESERVED2		0x60#define	IPOPT_EOL		0		/* end of option list */#define	IPOPT_NOP		1		/* no operation */#define	IPOPT_RR		7		/* record packet route */#define	IPOPT_TS		68		/* timestamp */#define	IPOPT_SECURITY	130		/* provide s,c,h,tcc */#define	IPOPT_LSRR		131		/* loose source route */#define	IPOPT_SATID		136		/* satnet id */#define	IPOPT_SSRR		137		/* strict source route */// Time stamp option structure.struct	ip_timestamp {	u_char	ipt_code;		/* IPOPT_TS */	u_char	ipt_len;		/* size of structure (variable) */	u_char	ipt_ptr;		/* index of current entry */	u_char	ipt_flg:4,		/* flags, see below */		ipt_oflw:4;			/* overflow counter */	union ipt_timestamp {		n_long	ipt_time[1];		struct	ipt_ta {			struct in_addr ipt_addr;			n_long ipt_time;		} ipt_ta[1];	} ipt_timestamp;};/* flag bits for ipt_flg */#define	IPOPT_TS_TSONLY		0		/* timestamps only */#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */#define	IPOPT_TS_PRESPEC	2		/* specified modules only *//* bits for security (not byte swapped) */#define	IPOPT_SECUR_UNCLASS	0x0000#define	IPOPT_SECUR_CONFID	0xf135#define	IPOPT_SECUR_EFTO	0x789a#define	IPOPT_SECUR_MMMM	0xbc4d#define	IPOPT_SECUR_RESTR	0xaf13#define	IPOPT_SECUR_SECRET	0xd788#define	IPOPT_SECUR_TOPSECRET	0x6bc5// ICMP Header//////////////////////////////////////////////////////////////////////////struct icmphdr {//	u_char	icmp_type;		/* type of message, see below *///	u_char	icmp_code;		/* type sub code *///	u_short	icmp_cksum;		/* ones complement cksum of struct *///	union {//		u_char ih_pptr;			/* ICMP_PARAMPROB *///		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT *///		struct ih_idseq {//			n_short	icd_id;//			n_short	icd_seq;//		} ih_idseq;//		int ih_void;//	} icmp_hun;//#define	icmp_pptr	icmp_hun.ih_pptr//#define	icmp_gwaddr	icmp_hun.ih_gwaddr//#define	icmp_id		icmp_hun.ih_idseq.icd_id//#define	icmp_seq	icmp_hun.ih_idseq.icd_seq//#define	icmp_void	icmp_hun.ih_void//	union {//		struct id_ts {//			n_time its_otime;//			n_time its_rtime;//			n_time its_ttime;//		} id_ts;//		struct id_ip  {//			struct iphdr idi_ip;//			/* options and then 64 bits of data *///		} id_ip;//		u_long	id_mask;//		char	id_data[1];//	} icmp_dun;//#define	icmp_otime	icmp_dun.id_ts.its_otime//#define	icmp_rtime	icmp_dun.id_ts.its_rtime//#define	icmp_ttime	icmp_dun.id_ts.its_ttime//#define	icmp_ip		icmp_dun.id_ip.idi_ip//#define	icmp_mask	icmp_dun.id_mask//#define	icmp_data	icmp_dun.id_data//};//typedef struct icmp_hdr icmp;/* * Lower bounds on packet lengths for various types. * For the error advice packets must first insure that the * packet is large enought to contain the returned ip header. * Only then can we do the check to see if 64 bits of packet * data have been returned, since we need to check the returned * ip header length. */#define	ICMP_MINLEN	8				/* abs minimum */#define	ICMP_TSLEN	(8 + 3 * sizeof (n_time))	/* timestamp */#define	ICMP_MASKLEN	12				/* address mask */#define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8)	/* min */#define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8)	/* N.B.: must separately check that ip_hl >= 5 *//* * Definition of type and code field values. */#define	ICMP_ECHOREPLY		0		/* echo reply *//* UNREACH codes */#define ICMP_UNREACH					3       /* dest unreachable, codes: */ #define ICMP_UNREACH_NET                0       /* bad net */#define ICMP_UNREACH_HOST               1       /* bad host */#define ICMP_UNREACH_PROTOCOL           2       /* bad protocol */#define ICMP_UNREACH_PORT               3       /* bad port */#define ICMP_UNREACH_NEEDFRAG           4       /* IP_DF caused drop */#define ICMP_UNREACH_SRCFAIL            5       /* src route failed */#define ICMP_UNREACH_NET_UNKNOWN        6       /* unknown net */#define ICMP_UNREACH_HOST_UNKNOWN       7       /* unknown host */#define ICMP_UNREACH_ISOLATED           8       /* src host isolated */#define ICMP_UNREACH_NET_PROHIB         9       /* net denied */#define ICMP_UNREACH_HOST_PROHIB        10      /* host denied */#define ICMP_UNREACH_TOSNET             11      /* bad tos for net */#define ICMP_UNREACH_TOSHOST            12      /* bad tos for host */#define ICMP_UNREACH_FILTER_PROHIB      13      /* admin prohib */#define ICMP_UNREACH_HOST_PRECEDENCE    14      /* host prec vio. */#define ICMP_UNREACH_PRECEDENCE_CUTOFF  15      /* prec cutoff */   #define	ICMP_SOURCEQUENCH				4		/* packet lost, slow down */#define ICMP_ROUTERADVERT				9       /* router advertisement */#define ICMP_ROUTERSOLICIT				10      /* router solicitation */    #define	ICMP_REDIRECT					5		/* shorter route, codes: */#define	ICMP_REDIRECT_NET				0		/* for network */#define	ICMP_REDIRECT_HOST				1		/* for host */#define	ICMP_REDIRECT_TOSNET			2		/* for tos and net */#define	ICMP_REDIRECT_TOSHOST			3		/* for tos and host */#define	ICMP_ECHO						8		/* echo service */#define	ICMP_TIMXCEED					11		/* time exceeded, code: */#define	ICMP_TIMXCEED_INTRANS			0		/* ttl==0 in transit */#define	ICMP_TIMXCEED_REASS				1		/* ttl==0 in reass */#define	ICMP_PARAMPROB					12		/* ip header bad */#define	ICMP_TSTAMP						13		/* timestamp request */#define	ICMP_TSTAMPREPLY				14		/* timestamp reply */#define	ICMP_IREQ						15		/* information request */#define	ICMP_IREQREPLY					16		/* information reply */#define	ICMP_MASKREQ					17		/* address mask request */#define	ICMP_MASKREPLY					18		/* address mask reply */#define	ICMP_MAXTYPE		18#define	ICMP_INFOTYPE(type) \	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)/*** ICMP types ********************************************************/#define ICMP_TYPE_0     "Echo reply"#define ICMP_TYPE_3     "Destination unreachable"#define ICMP_TYPE_4     "Source quench"#define ICMP_TYPE_5     "Redirect"#define ICMP_TYPE_8     "Echo"#define ICMP_TYPE_11    "Time exceeded"#define ICMP_TYPE_12    "Parameter problem"#define ICMP_TYPE_13    "Timestamp"#define ICMP_TYPE_14    "Timestamp reply"#define ICMP_TYPE_15    "Information request"#define ICMP_TYPE_16    "Information reply"#define ICMP_TYPE_17    "Address mask request"#define ICMP_TYPE_18    "Adress mask reply"/* pulled token stuff from tcpdump */struct tok {	int v;			/* value */	char *s;		/* string */};// TCP/////////////////////////////////////////////////////////////////////////typedef	u_long	tcp_seq;// TCP header. Per RFC 793, September, 1981. In Little Endian

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?