ekg2  GIT master
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
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