IPX over IP (rfc 1234) added. Very trivial.
[obnox/wireshark/wip.git] / packet.h
1 /* packet.h
2  * Definitions for packet disassembly structures and routines
3  *
4  * $Id: packet.h,v 1.6 1998/09/21 16:16:00 gram Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26
27 #ifndef __PACKET_H__
28 #define __PACKET_H__
29
30 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
31  * byte array, returns the value of the two or four bytes at the pointer.
32  * Handy for 
33  */
34
35 #if BYTE_ORDER == LITTLE_ENDIAN
36 #define pntohs(p)        ((guint16)                             \
37                           ((guint16)*((guint8 *)p+0)<<8|        \
38                            (guint16)*((guint8 *)p+1)<<0))
39
40 #define pntohl(p)       ((guint32)*((guint8 *)p+0)<<24|          \
41                          (guint32)*((guint8 *)p+1)<<16|          \
42                          (guint32)*((guint8 *)p+2)<<8|           \
43                          (guint32)*((guint8 *)p+3)<<0)
44 #else /* BIG_ENDIAN */
45 #define pntohs(p)        ((guint16)                             \
46                           ((guint16)*((guint8 *)p+1)<<8|        \
47                            (guint16)*((guint8 *)p+0)<<0))
48
49 #define pntohl(p)       ((guint32)*((guint8 *)p+3)<<24|          \
50                          (guint32)*((guint8 *)p+2)<<16|          \
51                          (guint32)*((guint8 *)p+1)<<8|           \
52                          (guint32)*((guint8 *)p+0)<<0)
53 #endif /* LITTLE_ENDIAN */
54
55 #define IEEE_802_3_MAX_LEN 1500
56 #define BYTE_VIEW_WIDTH    16
57
58 typedef struct _frame_data {
59   guint32  pkt_len;         /* Packet length */
60   guint32  cap_len;         /* Amount actually captured */
61   guint32  secs;            /* Seconds */
62   guint32  usecs;           /* Microseconds */
63   long     file_off;        /* File offset */
64   gchar   *win_info[5];        /* Packet list text */
65 } frame_data;
66
67 typedef struct _packet_info {
68   char *srcip;
69   int ip_src;
70   char *destip;
71   int ipproto;
72   int srcport;
73   int destport;
74   int iplen;
75   int iphdrlen;
76 } packet_info;
77
78 /* Many of the structs and definitions below were taken from include files
79  * in the Linux distribution. */
80
81 /* ARP / RARP structs and definitions */
82
83 typedef struct _e_ether_arp {
84   guint16 ar_hrd;
85   guint16 ar_pro;
86   guint8  ar_hln;
87   guint8  ar_pln;
88   guint16 ar_op;
89   guint8  arp_sha[6];
90   guint8  arp_spa[4];
91   guint8  arp_tha[6];
92   guint8  arp_tpa[4];
93 } e_ether_arp;
94
95 #ifndef ARPOP_REQUEST
96 #define ARPOP_REQUEST  1       /* ARP request.  */
97 #endif
98 #ifndef ARPOP_REPLY
99 #define ARPOP_REPLY    2       /* ARP reply.  */
100 #endif
101 /* Some OSes have different names, or don't define these at all */
102 #ifndef ARPOP_RREQUEST
103 #define ARPOP_RREQUEST 3       /* RARP request.  */
104 #endif
105 #ifndef ARPOP_RREPLY
106 #define ARPOP_RREPLY   4       /* RARP reply.  */
107 #endif
108
109 /* ICMP structs and definitions */
110
111 typedef struct _e_icmp {
112   guint8  icmp_type;
113   guint8  icmp_code;
114   guint16 icmp_cksum;
115   union {
116     struct {  /* Address mask request/reply */
117       guint16 id;
118       guint16 seq;
119       guint32 sn_mask;
120     } am;
121     struct {  /* Timestap request/reply */
122       guint16 id;
123       guint16 seq;
124       guint32 orig;
125       guint32 recv;
126       guint32 xmit;
127     } ts;
128     guint32 zero;  /* Unreachable */
129   } opt;
130 } e_icmp;
131
132 #define ICMP_ECHOREPLY     0
133 #define ICMP_UNREACH       3
134 #define ICMP_SOURCEQUENCH  4
135 #define ICMP_REDIRECT      5
136 #define ICMP_ECHO          8
137 #define ICMP_TIMXCEED     11
138 #define ICMP_PARAMPROB    12
139 #define ICMP_TSTAMP       13
140 #define ICMP_TSTAMPREPLY  14
141 #define ICMP_IREQ         15
142 #define ICMP_IREQREPLY    16
143 #define ICMP_MASKREQ      17
144 #define ICMP_MASKREPLY    18
145
146 /* IGMP structs and definitions */
147
148 typedef struct _e_igmp {
149 #if BYTE_ORDER == BIG_ENDIAN
150   guint8  igmp_v:4;
151   guint8  igmp_t:4;
152 #else /* Little endian */
153   guint8  igmp_t:4;
154   guint8  igmp_v:4;
155 #endif
156   guint8  igmp_unused;
157   guint16 igmp_cksum;
158   guint32 igmp_gaddr;
159 } e_igmp;
160
161 #define IGMP_M_QRY     0x01
162 #define IGMP_V1_M_RPT  0x02
163 #define IGMP_V2_LV_GRP 0x07
164 #define IGMP_DVMRP     0x03
165 #define IGMP_PIM       0x04
166 #define IGMP_V2_M_RPT  0x06
167 #define IGMP_MTRC_RESP 0x1e
168 #define IGMP_MTRC      0x1f
169
170 /* IP structs and definitions */
171
172 typedef struct _e_ip {
173 #if BYTE_ORDER == BIG_ENDIAN
174   guint8  ip_v:4;
175   guint8  ip_hl:4;
176 #else /* Little endian */
177   guint8  ip_hl:4;
178   guint8  ip_v:4;
179 #endif
180   guint8  ip_tos;
181   guint16 ip_len;
182   guint16 ip_id;
183   guint16 ip_off;
184   guint8  ip_ttl;
185   guint8  ip_p;
186   guint16 ip_sum;
187   guint32 ip_src;
188   guint32 ip_dst;
189 } e_ip;
190
191 #define IPTOS_TOS_MASK    0x1E
192 #define IPTOS_TOS(tos)    ((tos) & IPTOS_TOS_MASK)
193 #define IPTOS_NONE        0x00
194 #define IPTOS_LOWDELAY    0x10
195 #define IPTOS_THROUGHPUT  0x08
196 #define IPTOS_RELIABILITY 0x04
197 #define IPTOS_LOWCOST     0x02
198
199 #define IP_PROTO_ICMP  1
200 #define IP_PROTO_IGMP  2
201 #define IP_PROTO_TCP   6
202 #define IP_PROTO_UDP  17
203 #define IP_PROTO_OSPF 89
204
205 /* PPP structs and definitions */
206
207 typedef struct _e_ppphdr {
208   guint8  ppp_flag;
209   guint8  ppp_addr;
210   guint8  ppp_ctl;
211   guint16 ppp_prot;
212 } e_ppphdr;
213
214 /* TCP structs and definitions */
215
216 typedef struct _e_tcphdr {
217   guint16 th_sport;
218   guint16 th_dport;
219   guint32 th_seq;
220   guint32 th_ack;
221 #if BYTE_ORDER == LITTLE_ENDIAN
222   guint8  th_x2:4;
223   guint8  th_off:4;
224 #else
225   guint8  th_off:4;
226   guint8  th_x2:4;
227 #endif
228   guint8  th_flags;
229 #define TH_FIN  0x01
230 #define TH_SYN  0x02
231 #define TH_RST  0x04
232 #define TH_PUSH 0x08
233 #define TH_ACK  0x10
234 #define TH_URG  0x20
235   guint16 th_win;
236   guint16 th_sum;
237   guint16 th_urp;
238 } e_tcphdr;
239
240 /* UDP structs and definitions */
241
242 typedef struct _e_udphdr {
243   guint16 uh_sport;
244   guint16 uh_dport;
245   guint16 uh_ulen;
246   guint16 uh_sum;
247 } e_udphdr;
248
249 /* UDP Ports -> should go in packet-udp.h */
250
251 #define UDP_PORT_DNS 53
252 #define UDP_PORT_BOOTPS 67
253 #define UDP_PORT_IPX 213
254 #define UDP_PORT_RIP 520
255
256 /* TCP Ports */
257
258 #define TCP_PORT_PRINTER 515
259
260 /* Tree types.  Each dissect_* routine should have one for each
261    add_subtree() call. */
262
263 #define ETT_IEEE8023      0
264 #define ETT_ETHER2        1
265 #define ETT_LLC           2
266 #define ETT_TOKEN_RING    3
267 #define ETT_TR_IERR_CNT   4
268 #define ETT_TR_NERR_CNT   5
269 #define ETT_TR_MAC        6
270 #define ETT_PPP           7
271 #define ETT_ARP           8
272 #define ETT_IP            9
273 #define ETT_UDP          10
274 #define ETT_TCP          11
275 #define ETT_ICMP         12
276 #define ETT_IGMP         13
277 #define ETT_IPX          14
278 #define ETT_SPX          15
279 #define ETT_NCP          16
280 #define ETT_DNS          17
281 #define ETT_DNS_ANS      18
282 #define ETT_DNS_QRY      19
283 #define ETT_RIP          20
284 #define ETT_RIP_VEC      21
285 #define ETT_OSPF         22
286 #define ETT_OSPF_HDR     23
287 #define ETT_OSPF_HELLO   24
288 #define ETT_OSPF_DESC    25
289 #define ETT_OSPF_LSR     26
290 #define ETT_OSPF_LSA_UPD 27
291 #define ETT_OSPF_LSA     28
292 #define ETT_LPD          29
293 #define ETT_RAW          30
294 #define ETT_BOOTP        31
295 #define ETT_BOOTP_OPTION 32
296 #define ETT_IPv6         33
297 #define ETT_CLNP         34
298 #define ETT_COTP         35
299 #define ETT_VINES        36
300 #define ETT_VSPP         37
301
302 /* Should be the last item number plus one */
303 #define NUM_TREE_TYPES 38
304
305 /* The version of pcap.h that comes with some systems is missing these
306  * #defines.
307  */
308
309 #ifndef DLT_RAW
310 #define DLT_RAW 12
311 #endif
312
313 #ifndef DLT_SLIP_BSDOS
314 #define DLT_SLIP_BSDOS 13
315 #endif
316
317 #ifndef DLT_PPP_BSDOS
318 #define DLT_PPP_BSDOS 14
319 #endif
320
321 /* Utility routines used by packet*.c */
322 gchar*     ether_to_str(guint8 *);
323 gchar*     ip_to_str(guint8 *);
324 void       packet_hex_print(GtkText *, guint8 *, gint, gint, gint);
325 GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...);
326 void       decode_start_len(GtkTreeItem *, gint*, gint*);
327
328 /* Routines in packet.c */
329 void dissect_packet(const u_char *, frame_data *, GtkTree *);
330 void add_subtree(GtkWidget *, GtkWidget*, gint);
331 void expand_tree(GtkWidget *, gpointer);
332 void collapse_tree(GtkWidget *, gpointer);
333
334 /*
335  * Routines in packet-*.c
336  * Routines should take three args: packet data *, frame_data *, tree *
337  * They should never modify the packet data.
338  */
339 void dissect_eth(const u_char *, frame_data *, GtkTree *);
340 void dissect_ppp(const u_char *, frame_data *, GtkTree *);
341 void dissect_raw(const u_char *, frame_data *, GtkTree *);
342 void dissect_tr(const u_char *, frame_data *, GtkTree *);
343
344 /*
345  * Routines in packet-*.c
346  * Routines should take four args: packet data *, offset, frame_data *,
347  * tree *
348  * They should never modify the packet data.
349  */
350 void dissect_arp(const u_char *, int, frame_data *, GtkTree *);
351 void dissect_bootp(const u_char *, int, frame_data *, GtkTree *);
352 void dissect_data(const u_char *, int, frame_data *, GtkTree *);
353 void dissect_dns(const u_char *, int, frame_data *, GtkTree *);
354 void dissect_icmp(const u_char *, int, frame_data *, GtkTree *);
355 void dissect_igmp(const u_char *, int, frame_data *, GtkTree *);
356 void dissect_ip(const u_char *, int, frame_data *, GtkTree *);
357 void dissect_ipv6(const u_char *, int, frame_data *, GtkTree *);
358 void dissect_ipx(const u_char *, int, frame_data *, GtkTree *);
359 void dissect_llc(const u_char *, int, frame_data *, GtkTree *);
360 void dissect_lpd(const u_char *, int, frame_data *, GtkTree *);
361 void dissect_osi(const u_char *, int, frame_data *, GtkTree *);
362 void dissect_ospf(const u_char *, int, frame_data *, GtkTree *);
363 void dissect_ospf_hello(const u_char *, int, frame_data *, GtkTree *);
364 void dissect_tcp(const u_char *, int, frame_data *, GtkTree *);
365 void dissect_trmac(const u_char *, int, frame_data *, GtkTree *);
366 void dissect_udp(const u_char *, int, frame_data *, GtkTree *);
367 void dissect_vines(const u_char *, int, frame_data *, GtkTree *);
368 void dissect_vspp(const u_char *, int, frame_data *, GtkTree *);
369
370 /* This function is in ethertype.c */
371 void ethertype(guint16 etype, int offset,
372                 const u_char *pd, frame_data *fd, GtkTree *tree,
373                 GtkWidget *fh_tree);
374
375 #endif /* packet.h */