-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacket_struct.h
More file actions
72 lines (63 loc) · 1.76 KB
/
packet_struct.h
File metadata and controls
72 lines (63 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef DEF_PACKET_STRUCT
#define DEF_PACKET_STRUCT
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ether.h>
#define BUFF_SIZE 1518
#define ETH_SIZE 14
#define ARP_SIZE 28
#define ARP_PACKET_SIZE (ETH_SIZE+ARP_SIZE)
#define ETH_ADDR_SIZE 6
#define IP_ADDR_SIZE 4
typedef u_char Packet;
typedef struct in_addr IP;
typedef struct ether_addr MAC;
struct Host {
IP ip;
MAC mac;
};
/*-----------------------------------------------------------------------------
* Helper methods to compare MAC , IP & Hosts
*-----------------------------------------------------------------------------*/
int cmp_mac(const MAC * m1,const MAC * m2);
int cmp_ip(const IP * i1,const IP * i2) ;
int cmp_host(const struct Host * h1,const struct Host * h2) ;
void copy_mac(MAC * m1,const MAC * m2);
void copy_ip(IP * i1,const IP * i2) ;
void copy_host(struct Host * h1, const struct Host * h2) ;
void print_host(const struct Host * host);
void print_mac(const MAC * mac);
void print_ip(const IP * ip);
typedef struct __attribute__ ((__packed__)) pkt_eth {
MAC dest;
MAC src;
u_short type;
} pkt_eth;
#define ETHERTYPE_ARP 0x0806
#define ARP_REQUEST 1
#define ARP_REPLY 2
typedef struct __attribute__ ((__packed__)) pkt_arp {
u_short htype;/* hardware type => ethernet , etc */
u_short ptype; /*protocol type => ipv4 or ipv6 */
u_char hard_addr_len; /* usually 6 bytes for ethernet */
u_char proto_addr_len; /*usually 8 bytes for ipv4 */
u_short opcode; /* type of arp */
MAC hard_addr_send;
IP proto_addr_send;
MAC hard_addr_dest;
IP proto_addr_dest;
} pkt_arp;
#define ETHERTYPE_IP 0x0800
typedef struct pkt_ip {
u_char vhl;
u_char tos;
u_short len;
u_short id;
u_short off;
u_char ttl;
u_char proto;
u_short crc;
IP addr_src;
IP addr_dest;
} pkt_ip;
#endif