// Kenya Amann and Mark Hendrickson
// CS372
// Sniffer headers
// Brandion Mickelson


#define  SWAPLONG(y) \
( (((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff) )

#define  SWAPSHORT(y) \
 ( (((y)&0xff)<<8) | (((y)&0xff00)>>8) )

 
typedef unsigned char  u_char;
typedef unsigned short u_short;
typedef unsigned long  u_long;

typedef struct // 802.3 header
{
	u_char	dest_addr[6];
	u_char	src_addr[6];
	u_short	len;				// must be SWAPSHORT()
	u_char	dsap;
	u_char	ssap;
	u_char	cntl;
	u_char	org_code[3];
	u_short	type;				// must be SWAPSHORT()
	u_char	data[1492];
	u_long	crc;				// must be SWAPLONG()
} p_802_3_t;

typedef struct // 802.2 header
{
	u_char	dsap;
	u_char	ssap;
	u_char	cntl;
	u_char	org_code[3];
	u_short	type;				// must be SWAPSHORT()
	u_char	data[1492];
	u_long	crc;				// must be SWAPLONG()
} p_802_2_t;

typedef struct // ethernet II header
{
	u_char	dest_addr[6];
	u_char	src_addr[6];
	u_short	type;				// must be SWAPSHORT()
	u_char	data[1500];
	u_long	crc;				// must be SWAPLONG()
} p_ethernet_II_t;

typedef struct // IP header
{
	u_char	ver_len;			// 4-bit Version & 4-bit Header Length
	u_char	tos;
	u_short	ip_len;			// Total length in bytes
   u_short	id;
   u_short	flags_offset;	// 3-bit flags & 12-bit offset
	u_char	ttl;
	u_char	protocol;
	u_short	checksum;
	u_char	src_addr[4];
	u_char	dest_addr[4];
	union {
   	u_char	options[11][32];  // (if any)
   	u_char	data[1492];			// ip data length?  38-1492
   };
} ip_t;

typedef struct // UDP header
{
	u_short	src_port;
	u_short	dest_port;
	u_short	udp_len;
	u_short	checksum;
	u_char	data[1473];			// UDP data length?
} udp_t;

typedef struct // TCP header
{
	u_short	src_port;
	u_short	dest_port;
	u_long	seq_num;
	u_long	ack_num;
	u_short	len_flags;	 	// 4-bit header len & 6 res. & 6 flags
	u_short	window;
	u_short	checksum;
	u_short	urgent;
	// u_long options (if any)
	u_char	data[1460];			// TCP data length?
} tcp_t;

typedef struct // ARP header
{
	u_short	hardware;
	u_short	protocol;
	u_char	hard_sz;
	u_char	proto_sz;
	u_short	op;
	u_char	send_mac[6];
	u_char   send_ip[4];
	u_char	target_mac[6];
	u_char	target_ip[4];
} arp_t;

typedef struct // ICMP header
{
	u_char	type;
	u_char	code;
	u_short	checksum;
	u_char	data[1500];			// ICMP data length?
} icmp_t;


