ekg2  GIT master
sniff_ip.h
Idź do dokumentacji tego pliku.
1 /* XXX, check includes */
2 #include <stdio.h>
3 #include <signal.h>
4 #include <pcap.h>
5 
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <netinet/in.h>
9 #include <arpa/inet.h>
10 
11 #define SIZE_ETHERNET 14 /* ethernet headers are always exactly 14 bytes [1] */
12 #define ETHER_ADDR_LEN 6 /* Ethernet addresses are 6 bytes */
13 
14 struct ethhdr { /* Ethernet header */
15  u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */
16  u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */
17  u_short ether_type; /* IP? ARP? RARP? etc */
18 };
19 
20 /* from tcpdump sll.h */
21 
22 #define SIZE_SLL 16 /* total header length */
23 #define SLL_ADDRLEN 8 /* length of address field */
24 
25 struct sll_header {
26  u_gint16 sll_pkttype; /* packet type */
27  u_gint16 sll_hatype; /* link-layer address type */
28  u_gint16 sll_halen; /* link-layer address length */
29  u_gint8 sll_addr[SLL_ADDRLEN]; /* link-layer address */
30  u_gint16 sll_protocol; /* protocol */
31 };
32 
33 struct iphdr { /* IP header */
34 // u_char ip_vhl; /* version << 4 | header length >> 2 */
35  unsigned int ip_hl:4; /* header length */
36  unsigned int ip_v:4; /* version */
37 
38  u_char ip_tos; /* type of service */
39  u_short ip_len; /* total length */
40  u_short ip_id; /* identification */
41  u_short ip_off; /* fragment offset field */
42  #define IP_RF 0x8000 /* reserved fragment flag */
43  #define IP_DF 0x4000 /* dont fragment flag */
44  #define IP_MF 0x2000 /* more fragments flag */
45  #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
46  u_char ip_ttl; /* time to live */
47  u_char ip_p; /* protocol */
48  u_short ip_sum; /* checksum */
49  struct in_addr ip_src,ip_dst; /* source and dest address */
50 };
51 
52 typedef u_int tcp_seq;
53 
54 struct tcphdr { /* TCP header */
55  u_short th_sport; /* source port */
56  u_short th_dport; /* destination port */
57  tcp_seq th_seq; /* sequence number */
58  tcp_seq th_ack; /* acknowledgement number */
59  u_char th_offx2; /* data offset, rsvd */
60 #define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4)
61  u_char th_flags;
62  u_short th_win; /* window */
63  u_short th_sum; /* checksum */
64  u_short th_urp; /* urgent pointer */
65 };
66 
67 #define TH_FIN 0x01
68 #define TH_SYN 0x02
69 #define TH_RST 0x04
70 #define TH_PUSH 0x08
71 #define TH_ACK 0x10
72 #define TH_URG 0x20
73 #define TH_ECE 0x40
74 #define TH_CWR 0x80
75 
76 #define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
77 
78 struct udphdr { /* UDP header */
79  u_short th_sport; /* source port */
80  u_short th_dport; /* destination port */
81  u_short th_len; /* length */
82  u_short th_sum; /* checksum */
83 };
84 
85 struct icmphdr { /* ICMP header */
86  u_char icmp_type;
87  u_char icmp_code;
88  u_short icmp_cksum;
89 };
90 
91 #define ETHERTYPE_IP 0x0800 /* IP */
92 #define ETHERTYPE_ARP 0x0806 /* Address resolution */
93 
u_char ether_shost[6]
Definition: sniff_ip.h:16
u_short ip_sum
Definition: sniff_ip.h:48
u_char ether_dhost[6]
Definition: sniff_ip.h:15
tcp_seq th_ack
Definition: sniff_ip.h:58
u_short th_sum
Definition: sniff_ip.h:63
u_gint16 sll_pkttype
Definition: sniff_ip.h:26
u_short th_urp
Definition: sniff_ip.h:64
u_short ether_type
Definition: sniff_ip.h:17
u_short ip_id
Definition: sniff_ip.h:40
u_short th_sum
Definition: sniff_ip.h:82
u_short th_sport
Definition: sniff_ip.h:55
u_char th_flags
Definition: sniff_ip.h:61
Definition: sniff_ip.h:33
u_char ip_tos
Definition: sniff_ip.h:38
u_gint16 sll_halen
Definition: sniff_ip.h:28
u_gint16 sll_hatype
Definition: sniff_ip.h:27
u_char ip_ttl
Definition: sniff_ip.h:46
unsigned int ip_v
Definition: sniff_ip.h:36
u_short th_dport
Definition: sniff_ip.h:56
u_short th_dport
Definition: sniff_ip.h:80
unsigned int ip_hl
Definition: sniff_ip.h:35
Definition: sniff_ip.h:78
u_short ip_off
Definition: sniff_ip.h:41
Definition: sniff_ip.h:54
u_char th_offx2
Definition: sniff_ip.h:59
u_short th_win
Definition: sniff_ip.h:62
u_char icmp_code
Definition: sniff_ip.h:87
Definition: sniff_ip.h:25
u_short ip_len
Definition: sniff_ip.h:39
u_short th_sport
Definition: sniff_ip.h:79
u_char ip_p
Definition: sniff_ip.h:47
u_short icmp_cksum
Definition: sniff_ip.h:88
#define ETHER_ADDR_LEN
Definition: sniff_ip.h:12
tcp_seq th_seq
Definition: sniff_ip.h:57
#define SLL_ADDRLEN
Definition: sniff_ip.h:23
u_int tcp_seq
Definition: sniff_ip.h:52
Definition: sniff_ip.h:14
u_short th_len
Definition: sniff_ip.h:81
Definition: sniff_ip.h:85
u_char icmp_type
Definition: sniff_ip.h:86
u_gint16 sll_protocol
Definition: sniff_ip.h:30