Replace the ETT_ "enum" members, declared in "packet.h", with
[metze/wireshark/wip.git] / packet.h
1 /* packet.h
2  * Definitions for packet disassembly structures and routines
3  *
4  * $Id: packet.h,v 1.142 1999/11/16 11:43:05 guy 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 #ifndef __WTAP_H__
31 #include "wiretap/wtap.h"
32 #endif
33
34 #ifndef __PROTO_H__
35 #include "proto.h"
36 #endif
37
38 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
39  * byte array, returns the value of the two or four bytes at the pointer.
40  * The pletoh[sl] versions return the little-endian representation.
41  */
42
43 #define pntohs(p)  ((guint16)                       \
44                     ((guint16)*((guint8 *)p+0)<<8|  \
45                      (guint16)*((guint8 *)p+1)<<0))
46
47 #define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
48                     (guint32)*((guint8 *)p+1)<<16|  \
49                     (guint32)*((guint8 *)p+2)<<8|   \
50                     (guint32)*((guint8 *)p+3)<<0)
51
52 #define pletohs(p) ((guint16)                       \
53                     ((guint16)*((guint8 *)p+1)<<8|  \
54                      (guint16)*((guint8 *)p+0)<<0))
55
56 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
57                     (guint32)*((guint8 *)p+2)<<16|  \
58                     (guint32)*((guint8 *)p+1)<<8|   \
59                     (guint32)*((guint8 *)p+0)<<0)
60
61
62 #define hi_nibble(b) ((b & 0xf0) >> 4)
63 #define lo_nibble(b) (b & 0x0f)
64
65 /* Useful when you have an array whose size you can tell at compile-time */
66 #define array_length(x) (sizeof x / sizeof x[0])
67
68
69 /* Useful when highlighting regions inside a dissect_*() function. With this
70  * macro, you can highlight from an arbitrary offset to the end of the
71  * packet (which may come before the end of the frame).
72  * See dissect_data() for an example.
73  */
74 #define END_OF_FRAME    (pi.captured_len - offset)
75
76 /* Check whether the "len" bytes of data starting at "offset" is
77  * entirely inside the captured data for this packet. */
78 #define BYTES_ARE_IN_FRAME(offset, len) ((offset) + (len) <= pi.captured_len)
79
80 /* Check whether there's any data at all starting at "offset". */
81 #define IS_DATA_IN_FRAME(offset)        ((offset) < pi.captured_len)
82                 
83 /* To pass one of two strings, singular or plural */
84 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
85
86 typedef struct _column_info {
87   gint       num_cols;  /* Number of columns */
88   gint      *col_fmt;   /* Format of column */
89   gboolean **fmt_matx;  /* Specifies which formats apply to a column */
90   gint      *col_width; /* Column widths to use during a "-S" capture */
91   gchar    **col_title; /* Column titles */
92   gchar    **col_data;  /* Column data */
93 } column_info;
94
95 #define COL_MAX_LEN 256
96 #define COL_MAX_INFO_LEN 4096
97
98 typedef struct _packet_counts {
99   gint           tcp;
100   gint           udp;
101   gint           icmp;
102   gint           ospf;
103   gint           gre;
104   gint           netbios;
105   gint           other;
106   gint           total;
107 } packet_counts;
108
109 /* XXX - some of this stuff is used only while a packet is being dissected;
110    should we keep around a separate data structure for that, to save
111    memory?
112
113    Also, should the pseudo-header be supplied by Wiretap when you do a
114    seek-and-read, so that we don't have to save it for all frames? */
115 typedef struct _frame_data {
116   struct _frame_data *next; /* Next element in list */
117   struct _frame_data *prev; /* Previous element in list */
118   guint32      num;       /* Frame number */
119   guint32      pkt_len;   /* Packet length */
120   guint32      cap_len;   /* Amount actually captured */
121   guint32      rel_secs;  /* Relative seconds */
122   guint32      rel_usecs; /* Relative microseconds */
123   guint32      abs_secs;  /* Absolute seconds */
124   guint32      abs_usecs; /* Absolute microseconds */
125   guint32      del_secs;  /* Delta seconds */
126   guint32      del_usecs; /* Delta microseconds */
127   long         file_off;  /* File offset */
128   column_info *cinfo;     /* Column formatting information */
129   gint         row;       /* Row number for this packet in the display */
130   int          lnk_t;     /* Per-packet encapsulation/data-link type */
131   gboolean     passed_dfilter; /* TRUE = display, FALSE = no display */
132   union pseudo_header pseudo_header; /* "pseudo-header" from wiretap */
133 } frame_data;
134
135 /* Types of addresses Ethereal knows about. */
136 typedef enum {
137   AT_NONE,              /* no link-layer address */
138   AT_ETHER,             /* MAC (Ethernet, 802.x, FDDI) address */
139   AT_IPv4,              /* IPv4 */
140   AT_IPv6,              /* IPv6 */
141   AT_IPX,               /* IPX */
142   AT_SNA,               /* SNA */
143   AT_ATALK,             /* Appletalk DDP */
144   AT_VINES              /* Banyan Vines */
145 } address_type;
146
147 typedef struct _address {
148   address_type  type;           /* type of address */
149   int           len;            /* length of address, in bytes */
150   const guint8 *data;           /* bytes that constitute address */
151 } address;
152
153 #define SET_ADDRESS(addr, addr_type, addr_len, addr_data) { \
154         (addr)->type = (addr_type); \
155         (addr)->len = (addr_len); \
156         (addr)->data = (addr_data); \
157         }
158
159 /* Types of port numbers Ethereal knows about. */
160 typedef enum {
161   PT_NONE,              /* no port number */
162   PT_TCP,               /* TCP */
163   PT_UDP                /* UDP */
164 } port_type;
165
166 typedef struct _packet_info {
167   int     len;
168   int     captured_len;
169   address dl_src;               /* link-layer source address */
170   address dl_dst;               /* link-layer destination address */
171   address net_src;              /* network-layer source address */
172   address net_dst;              /* network-layer destination address */
173   address src;                  /* source address (net if present, DL otherwise )*/
174   address dst;                  /* destination address (net if present, DL otherwise )*/
175   guint32 ipproto;
176   port_type ptype;              /* type of the following two port numbers */
177   guint32 srcport;              /* source port */
178   guint32 destport;             /* destination port */
179   guint32 match_port;
180   int     iplen;
181   int     iphdrlen;
182 } packet_info;
183
184 extern packet_info pi;
185
186 /* Struct for the match_strval function */
187
188 typedef struct _value_string {
189   guint32  value;
190   gchar   *strptr;
191 } value_string;
192
193 /* Struct for boolean enumerations */
194 typedef struct true_false_string {
195         char    *true_string;
196         char    *false_string;
197 } true_false_string;
198
199
200 /* Many of the structs and definitions below and in packet-*.c files
201  * were taken from include files in the Linux distribution. */
202
203 typedef struct tcp_extra_data {
204   int match_port;
205   int sport;
206   int dport;
207 } tcp_extra_data;
208
209 /* Utility routines used by packet*.c */
210 gchar*     ether_to_str(const guint8 *);
211 gchar*     ip_to_str(const guint8 *);
212 struct e_in6_addr;
213 gchar*     ip6_to_str(struct e_in6_addr *);
214 gchar*     ipx_addr_to_str(guint32, const guint8 *);
215 gchar*     abs_time_to_str(struct timeval*);
216 gchar*     rel_time_to_str(struct timeval*);
217 gchar*     time_secs_to_str(guint32);
218 gchar*     bytes_to_str(const guint8 *, int);
219 const u_char *find_line_end(const u_char *data, const u_char *dataend,
220     const u_char **eol);
221 int        get_token_len(const u_char *linep, const u_char *lineend,
222     const u_char **next_token);
223 gchar*     format_text(const u_char *line, int len);
224 gchar*     val_to_str(guint32, const value_string *, const char *);
225 gchar*     match_strval(guint32, const value_string*);
226 char * decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width);
227 const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
228   const char *truedesc, const char *falsedesc);
229 const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
230   const value_string *tab, const char *fmt);
231 const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
232   const char *fmt);
233 gint       check_col(frame_data *, gint);
234 #if __GNUC__ == 2
235 void       col_add_fstr(frame_data *, gint, gchar *, ...)
236     __attribute__((format (printf, 3, 4)));
237 void       col_append_fstr(frame_data *, gint, gchar *, ...)
238     __attribute__((format (printf, 3, 4)));
239 #else
240 void       col_add_fstr(frame_data *, gint, gchar *, ...);
241 void       col_append_fstr(frame_data *, gint, gchar *, ...);
242 #endif
243 void       col_add_str(frame_data *, gint, const gchar *);
244 void       col_append_str(frame_data *, gint, gchar *);
245
246 void blank_packetinfo(void);
247
248 void afs_init_protocol(void);
249 void rpc_init_protocol(void);
250 void smb_init_protocol(void);
251
252 void dissect_packet(const u_char *, frame_data *, proto_tree *);
253
254 /*
255  * Routines in packet-*.c
256  * Routines should take three args: packet data *, cap_len, packet_counts *
257  * They should never modify the packet data.
258  */
259 void capture_clip(const u_char *, guint32, packet_counts *);
260 void capture_eth(const u_char *, guint32, packet_counts *);
261 void capture_fddi(const u_char *, guint32, packet_counts *);
262 void capture_null(const u_char *, guint32, packet_counts *);
263 void capture_ppp(const u_char *, guint32, packet_counts *);
264 void capture_raw(const u_char *, guint32, packet_counts *);
265 void capture_tr(const u_char *, guint32, packet_counts *);
266
267 /*
268  * Routines in packet-*.c
269  * Routines should take four args: packet data *, offset, cap_len,
270  * packet_counts *
271  * They should never modify the packet data.
272  */
273 void capture_netbios(const u_char *, int, guint32, packet_counts *);
274 void capture_llc(const u_char *, int, guint32, packet_counts *);
275 void capture_ip(const u_char *, int, guint32, packet_counts *);
276
277 /*
278  * Routines in packet-*.c
279  * Routines should take three args: packet data *, frame_data *, tree *
280  * They should never modify the packet data.
281  */
282 void dissect_ascend(const u_char *, frame_data *, proto_tree *);
283 void dissect_atm(const u_char *, frame_data *, proto_tree *);
284 void dissect_clip(const u_char *, frame_data *, proto_tree *);
285 void dissect_lapb(const u_char *, frame_data *, proto_tree *);
286 void dissect_lapd(const u_char *, frame_data *, proto_tree *);
287 void dissect_null(const u_char *, frame_data *, proto_tree *);
288 void dissect_ppp(const u_char *, frame_data *, proto_tree *);
289 void dissect_raw(const u_char *, frame_data *, proto_tree *);
290
291 /*
292  * Routines in packet-*.c
293  * Routines should take four args: packet data *, frame_data *, tree *,
294  * gboolean
295  * They should never modify the packet data.
296  */
297 void dissect_fddi(const u_char *, frame_data *, proto_tree *, gboolean);
298
299 typedef void    (*DissectFunc)  (const u_char*, int, frame_data*, proto_tree*);
300
301 /*
302  * Routines in packet-*.c
303  * Routines should take four args: packet data *, offset, frame_data *,
304  * tree *
305  * They should never modify the packet data.
306  */
307 int dissect_ah(const u_char *, int, frame_data *, proto_tree *);
308 void dissect_aarp(const u_char *, int, frame_data *, proto_tree *);
309 void dissect_afs(const u_char *, int, frame_data *, proto_tree *);
310 void dissect_arp(const u_char *, int, frame_data *, proto_tree *);
311 void dissect_bgp(const u_char *, int, frame_data *, proto_tree *);
312 void dissect_bootp(const u_char *, int, frame_data *, proto_tree *);
313 void dissect_bpdu(const u_char *, int, frame_data *, proto_tree *);
314 void dissect_cdp(const u_char *, int, frame_data *, proto_tree *);
315 void dissect_cotp(const u_char *, int, frame_data *, proto_tree *);
316 void dissect_data(const u_char *, int, frame_data *, proto_tree *);
317 void dissect_ddp(const u_char *, int, frame_data *, proto_tree *);
318 void dissect_dns(const u_char *, int, frame_data *, proto_tree *);
319 void dissect_eigrp(const u_char *, int, frame_data *, proto_tree *);            
320 void dissect_esp(const u_char *, int, frame_data *, proto_tree *);
321 void dissect_eth(const u_char *, int, frame_data *, proto_tree *);
322 void dissect_ftp(const u_char *, int, frame_data *, proto_tree *);
323 void dissect_ftpdata(const u_char *, int, frame_data *, proto_tree *);
324 void dissect_giop(const u_char *, int, frame_data *, proto_tree *);
325 void dissect_http(const u_char *, int, frame_data *, proto_tree *);
326 void dissect_icmp(const u_char *, int, frame_data *, proto_tree *);
327 void dissect_icmpv6(const u_char *, int, frame_data *, proto_tree *);
328 void dissect_igmp(const u_char *, int, frame_data *, proto_tree *);
329 void dissect_ip(const u_char *, int, frame_data *, proto_tree *);
330 void dissect_ipcomp(const u_char *, int, frame_data *, proto_tree *);
331 void dissect_ipp(const u_char *, int, frame_data *, proto_tree *);
332 void dissect_ipv6(const u_char *, int, frame_data *, proto_tree *);
333 void dissect_ipx(const u_char *, int, frame_data *, proto_tree *);
334 void dissect_llc(const u_char *, int, frame_data *, proto_tree *);
335 void dissect_lpd(const u_char *, int, frame_data *, proto_tree *);
336 void dissect_mapi(const u_char *, int, frame_data *, proto_tree *);
337 void dissect_nbdgm(const u_char *, int, frame_data *, proto_tree *);
338 void dissect_netbios(const u_char *, int, frame_data *, proto_tree *);
339 void dissect_nbipx(const u_char *, int, frame_data *, proto_tree *);
340 void dissect_nbns(const u_char *, int, frame_data *, proto_tree *);
341 void dissect_nbss(const u_char *, int, frame_data *, proto_tree *);
342 void dissect_ncp(const u_char *, int, frame_data *, proto_tree *);
343 void dissect_nntp(const u_char *, int, frame_data *, proto_tree *);
344 void dissect_ntp(const u_char *, int, frame_data *, proto_tree *);
345 void dissect_nwlink_dg(const u_char *, int, frame_data *, proto_tree *);
346 void dissect_osi(const u_char *, int, frame_data *, proto_tree *);
347 void dissect_ospf(const u_char *, int, frame_data *, proto_tree *);
348 void dissect_ospf_hello(const u_char *, int, frame_data *, proto_tree *);
349 void dissect_pim(const u_char *, int, frame_data *, proto_tree *);
350 void dissect_pop(const u_char *, int, frame_data *, proto_tree *);
351 void dissect_pppoed(const u_char *, int, frame_data *, proto_tree *);
352 void dissect_pppoes(const u_char *, int, frame_data *, proto_tree *);
353 void dissect_icp(const u_char *,int, frame_data *, proto_tree *);
354 void dissect_icq(const u_char *,int, frame_data *, proto_tree *);
355 void dissect_imap(const u_char *,int, frame_data *, proto_tree *);
356 void dissect_isakmp(const u_char *, int, frame_data *, proto_tree *);
357 void dissect_pim(const u_char *, int, frame_data *, proto_tree *);
358 void dissect_q931(const u_char *, int, frame_data *, proto_tree *);
359 void dissect_radius(const u_char *, int, frame_data *, proto_tree *);
360 void dissect_rip(const u_char *, int, frame_data *, proto_tree *);
361 void dissect_ripng(const u_char *, int, frame_data *, proto_tree *);
362 void dissect_rsvp(const u_char *, int, frame_data *, proto_tree *);
363 void dissect_rtsp(const u_char *, int, frame_data *, proto_tree *);
364 void dissect_rx(const u_char *, int, frame_data *, proto_tree *);
365 void dissect_sdp(const u_char *, int, frame_data *, proto_tree *);
366 void dissect_sna(const u_char *, int, frame_data *, proto_tree *);
367 void dissect_snmp(const u_char *, int, frame_data *, proto_tree *);
368 void dissect_tcp(const u_char *, int, frame_data *, proto_tree *);
369 void dissect_telnet(const u_char *, int, frame_data *, proto_tree *);
370 void dissect_tftp(const u_char *, int, frame_data *, proto_tree *);
371 void dissect_tr(const u_char *, int, frame_data *, proto_tree *);
372 void dissect_trmac(const u_char *, int, frame_data *, proto_tree *);
373 void dissect_udp(const u_char *, int, frame_data *, proto_tree *);
374 void dissect_vines(const u_char *, int, frame_data *, proto_tree *);
375 void dissect_vines_arp(const u_char *, int, frame_data *, proto_tree *);
376 void dissect_vines_frp(const u_char *, int, frame_data *, proto_tree *);
377 void dissect_vines_icp(const u_char *, int, frame_data *, proto_tree *);
378 void dissect_vines_ipc(const u_char *, int, frame_data *, proto_tree *);
379 void dissect_vines_rtp(const u_char *, int, frame_data *, proto_tree *);
380 void dissect_vines_spp(const u_char *, int, frame_data *, proto_tree *);
381 void dissect_vlan(const u_char *, int, frame_data *, proto_tree *);
382 void dissect_payload_ppp(const u_char *, int, frame_data *, proto_tree *);
383 void dissect_x25(const u_char *, int, frame_data *, proto_tree *);
384 void dissect_yhoo(const u_char *, int, frame_data *, proto_tree *);
385
386 void dissect_smb(const u_char *, int, frame_data *, proto_tree *, int);
387 void dissect_pptp(const u_char *, int, frame_data *, proto_tree *);
388 void dissect_gre(const u_char *, int, frame_data *, proto_tree *);
389
390 /*
391  * Routines in packet-*.c
392  * Routines should take four args: packet data *, offset, frame_data *,
393  * tree *
394  * They should never modify the packet data.
395  * They should return TRUE if the packet is of the type the routine would
396  * dissect, FALSE otherwise.
397  */
398 gboolean dissect_rpc(const u_char *, int, frame_data *, proto_tree *);
399
400 void init_dissect_rpc(void);
401 void init_dissect_udp(void);
402 void init_dissect_x25(void);
403
404 /* These functions are in ethertype.c */
405 void capture_ethertype(guint16 etype, int offset,
406                 const u_char *pd, guint32 cap_len, packet_counts *ld);
407 void ethertype(guint16 etype, int offset,
408                 const u_char *pd, frame_data *fd, proto_tree *tree,
409                 proto_tree *fh_tree, int item_id);
410 extern const value_string etype_vals[];
411
412 /* These functions are in packet-arp.c */
413 gchar *arphrdaddr_to_str(guint8 *ad, int ad_len, guint16 type);
414 gchar *arphrdtype_to_str(guint16 hwtype, const char *fmt);
415
416 /* ipproto.c */
417 extern const char *ipprotostr(int proto);
418
419 /*
420  * All of the possible columns in summary listing.
421  *
422  * NOTE: The SRC and DST entries MUST remain in this order, or else you
423  * need to fix the offset #defines before get_column_format!
424  */
425 enum {
426   COL_NUMBER,         /* Packet list item number */
427   COL_CLS_TIME,       /* Command line-specified time (default relative) */
428   COL_REL_TIME,       /* Relative time */
429   COL_ABS_TIME,       /* Absolute time */
430   COL_DELTA_TIME,     /* Delta time */
431   COL_DEF_SRC,        /* Source address */
432   COL_RES_SRC,        /* Resolved source */
433   COL_UNRES_SRC,      /* Unresolved source */
434   COL_DEF_DL_SRC,     /* Data link layer source address */
435   COL_RES_DL_SRC,     /* Resolved DL source */
436   COL_UNRES_DL_SRC,   /* Unresolved DL source */
437   COL_DEF_NET_SRC,    /* Network layer source address */
438   COL_RES_NET_SRC,    /* Resolved net source */
439   COL_UNRES_NET_SRC,  /* Unresolved net source */
440   COL_DEF_DST,        /* Destination address */
441   COL_RES_DST,        /* Resolved dest */
442   COL_UNRES_DST,      /* Unresolved dest */
443   COL_DEF_DL_DST,     /* Data link layer dest address */
444   COL_RES_DL_DST,     /* Resolved DL dest */
445   COL_UNRES_DL_DST,   /* Unresolved DL dest */
446   COL_DEF_NET_DST,    /* Network layer dest address */
447   COL_RES_NET_DST,    /* Resolved net dest */
448   COL_UNRES_NET_DST,  /* Unresolved net dest */
449   COL_DEF_SRC_PORT,   /* Source port */
450   COL_RES_SRC_PORT,   /* Resolved source port */
451   COL_UNRES_SRC_PORT, /* Unresolved source port */
452   COL_DEF_DST_PORT,   /* Destination port */
453   COL_RES_DST_PORT,   /* Resolved dest port */
454   COL_UNRES_DST_PORT, /* Unresolved dest port */
455   COL_PROTOCOL,       /* Protocol */
456   COL_INFO,           /* Description */
457   COL_PACKET_LENGTH,  /* Packet length in bytes */
458   NUM_COL_FMTS        /* Should always be last */
459 };
460
461 #endif /* packet.h */