Added Johan's RADIUS dissector, finally. I modified it to fit in with the
[obnox/wireshark/wip.git] / packet.h
1 /* packet.h
2  * Definitions for packet disassembly structures and routines
3  *
4  * $Id: packet.h,v 1.66 1999/07/08 04:23:04 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 #ifndef __PROTO_H__
31 #include "proto.h"
32 #endif
33
34 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
35  * byte array, returns the value of the two or four bytes at the pointer.
36  * The pletoh[sl] versions return the little-endian representation.
37  */
38
39 #define pntohs(p)  ((guint16)                       \
40                     ((guint16)*((guint8 *)p+0)<<8|  \
41                      (guint16)*((guint8 *)p+1)<<0))
42
43 #define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
44                     (guint32)*((guint8 *)p+1)<<16|  \
45                     (guint32)*((guint8 *)p+2)<<8|   \
46                     (guint32)*((guint8 *)p+3)<<0)
47
48 #define pletohs(p) ((guint16)                       \
49                     ((guint16)*((guint8 *)p+1)<<8|  \
50                      (guint16)*((guint8 *)p+0)<<0))
51
52 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
53                     (guint32)*((guint8 *)p+2)<<16|  \
54                     (guint32)*((guint8 *)p+1)<<8|   \
55                     (guint32)*((guint8 *)p+0)<<0)
56
57
58 #define hi_nibble(b) ((b & 0xf0) >> 4)
59 #define lo_nibble(b) (b & 0x0f)
60
61 /* Byte ordering */
62 #ifndef BYTE_ORDER
63   #define LITTLE_ENDIAN 4321
64   #define BIG_ENDIAN 1234
65   #ifdef WORDS_BIGENDIAN
66     #define BYTE_ORDER BIG_ENDIAN
67   #else
68     #define BYTE_ORDER LITTLE_ENDIAN
69   #endif
70 #endif
71
72 /* Useful when you have an array whose size you can tell at compile-time */
73 #define array_length(x) (sizeof x / sizeof x[0])
74
75
76 /* Useful when highlighting regions inside a dissect_*() function. With this
77  * macro, you can highlight from an arbitrary offset to the end of the
78  * frame. See dissect_data() for an example.
79  */
80 #define END_OF_FRAME    (fd->cap_len - offset)
81                 
82 /* To pass one of two strings, singular or plural */
83 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
84
85 typedef struct _column_info {
86   gint       num_cols; /* Number of columns */
87   gchar    **col_title;/* Column title */
88   gboolean **fmt_matx; /* Specifies which formats apply to a column */
89   gchar    **col_data; /* Column data */
90   gint     *col_width; /* Column width */
91 } column_info;
92
93 #define COL_MAX_LEN 256
94
95 typedef struct _packet_counts {
96   gint           tcp;
97   gint           udp;
98   gint           ospf;
99   gint           gre;
100   gint           other;
101   gint           total;
102 } packet_counts;
103
104 typedef struct _frame_data {
105   guint32      pkt_len;   /* Packet length */
106   guint32      cap_len;   /* Amount actually captured */
107   guint32      rel_secs;  /* Relative seconds */
108   guint32      rel_usecs; /* Relative microseconds */
109   guint32      abs_secs;  /* Absolute seconds */
110   guint32      abs_usecs; /* Absolute microseconds */
111   guint32      del_secs;  /* Delta seconds */
112   guint32      del_usecs; /* Delta microseconds */
113   long         file_off;  /* File offset */
114   column_info *cinfo;     /* Column formatting information */
115   int          lnk_t;     /* Per-packet encapsulation/data-link type */
116   gboolean     passed_dfilter; /* TRUE = display, FALSE = no display */
117 } frame_data;
118
119 typedef struct _packet_info {
120   char *srcip;
121   int ip_src;
122   char *destip;
123   int ipproto;
124   int srcport;
125   int destport;
126   int match_port;
127   int iplen;
128   int iphdrlen;
129   int payload;
130 } packet_info;
131
132 /* Struct for the match_strval function */
133
134 typedef struct _value_string {
135   guint32  value;
136   gchar   *strptr;
137 } value_string;
138
139 /* Many of the structs and definitions below and in packet-*.c files
140  * were taken from include files in the Linux distribution. */
141
142 typedef struct tcp_extra_data {
143   int match_port;
144   int sport;
145   int dport;
146 } tcp_extra_data;
147
148 /* Tree types.  Each dissect_* routine should have one for each
149    add_subtree() call. */
150
151 enum {
152         ETT_NONE,
153         ETT_FRAME,
154         ETT_IEEE8023,
155         ETT_ETHER2,
156         ETT_LLC,
157         ETT_TOKEN_RING,
158         ETT_TOKEN_RING_AC,
159         ETT_TOKEN_RING_FC,
160         ETT_TR_IERR_CNT,
161         ETT_TR_NERR_CNT,
162         ETT_TR_MAC,
163         ETT_PPP,
164         ETT_ARP,
165         ETT_FDDI,
166         ETT_NULL,
167         ETT_IP,
168         ETT_IP_OPTIONS,
169         ETT_IP_OPTION_SEC,
170         ETT_IP_OPTION_ROUTE,
171         ETT_IP_OPTION_TIMESTAMP,
172         ETT_IP_TOS,
173         ETT_IP_OFF,
174         ETT_UDP,
175         ETT_TCP,
176         ETT_TCP_OPTIONS,
177         ETT_TCP_OPTION_SACK,
178         ETT_TCP_FLAGS,
179         ETT_ICMP,
180         ETT_IGMP,
181         ETT_IPX,
182         ETT_SPX,
183         ETT_NCP,
184         ETT_NCP_REQUEST_FIELDS,
185         ETT_NCP_REPLY_FIELDS,
186         ETT_DNS,
187         ETT_DNS_FLAGS,
188         ETT_DNS_QRY,
189         ETT_DNS_QD,
190         ETT_DNS_ANS,
191         ETT_DNS_RR,
192         ETT_ISAKMP,
193         ETT_ISAKMP_FLAGS,
194         ETT_ISAKMP_PAYLOAD,
195         ETT_RIP,
196         ETT_RIP_VEC,
197         ETT_OSPF,
198         ETT_OSPF_HDR,
199         ETT_OSPF_HELLO,
200         ETT_OSPF_DESC,
201         ETT_OSPF_LSR,
202         ETT_OSPF_LSA_UPD,
203         ETT_OSPF_LSA,
204         ETT_LPD,
205         ETT_RAW,
206         ETT_BOOTP,
207         ETT_BOOTP_OPTION,
208         ETT_IPv6,
209         ETT_CLNP,
210         ETT_COTP,
211         ETT_VINES_FRP,
212         ETT_VINES,
213         ETT_VINES_ARP,
214         ETT_VINES_ICP,
215         ETT_VINES_IPC,
216         ETT_VINES_RTP,
217         ETT_VINES_SPP,
218         ETT_IPXRIP,
219         ETT_IPXSAP,
220         ETT_IPXSAP_SERVER,
221         ETT_NBNS,
222         ETT_NBNS_FLAGS,
223         ETT_NBNS_NB_FLAGS,
224         ETT_NBNS_NAME_FLAGS,
225         ETT_NBNS_QRY,
226         ETT_NBNS_QD,
227         ETT_NBNS_ANS,
228         ETT_NBNS_RR,
229         ETT_NBIPX,
230         ETT_AARP,
231         ETT_GIOP,
232         ETT_NBDGM,
233         ETT_CDP,
234         ETT_HTTP,
235         ETT_TFTP,
236         ETT_AH,
237         ETT_ESP,
238         ETT_ICMPv6,
239         ETT_ICMPv6OPT,
240         ETT_ICMPv6FLAG,
241         ETT_POP,
242         ETT_FTP,
243         ETT_TELNET,
244         ETT_TELNET_SUBOPT,
245         ETT_NNTP,
246         ETT_SNMP,
247         ETT_NBSS,
248         ETT_NBSS_FLAGS,
249         ETT_SMB,
250         ETT_SMB_FLAGS,
251         ETT_SMB_FLAGS2,
252         ETT_SMB_DIALECTS,
253         ETT_SMB_MODE,
254         ETT_SMB_CAPABILITIES,
255         ETT_SMB_RAWMODE,
256         ETT_SMB_AFLAGS,
257         ETT_PPTP,
258         ETT_GRE,
259         ETT_GRE_FLAGS,
260         ETT_PPPOED,
261         ETT_PPPOED_TAGS,
262         ETT_PPPOES,
263         ETT_LCP,
264         ETT_IPCP,
265         ETT_RSVP,
266         ETT_RSVP_UNKNOWN_CLASS,
267         ETT_RSVP_HDR,
268         ETT_RSVP_SESSION,
269         ETT_RSVP_SGROUP,
270         ETT_RSVP_HOP,
271         ETT_RSVP_INTEGRITY,
272         ETT_RSVP_TIME_VALUES,
273         ETT_RSVP_ERROR,
274         ETT_RSVP_SCOPE,
275         ETT_RSVP_STYLE,
276         ETT_RSVP_FLOWSPEC,
277         ETT_RSVP_FILTER_SPEC,
278         ETT_RSVP_SENDER_TEMPLATE,
279         ETT_RSVP_SENDER_TSPEC,
280         ETT_RSVP_ADSPEC,
281         ETT_RSVP_POLICY,
282         ETT_RSVP_CONFIRM,
283         ETT_RSVP_ADSPEC_SUBTREE1,
284         ETT_RSVP_ADSPEC_SUBTREE2,
285         ETT_RSVP_ADSPEC_SUBTREE3,
286         ETT_RTSP,
287         ETT_SDP,
288         ETT_RADIUS,
289         ETT_RADIUS_AVP,
290         NUM_TREE_TYPES  /* last item number plus one */
291 };
292
293 /* The version of pcap.h that comes with some systems is missing these
294  * #defines.
295  */
296
297 #ifndef DLT_RAW
298 #define DLT_RAW 12
299 #endif
300
301 #ifndef DLT_SLIP_BSDOS
302 #define DLT_SLIP_BSDOS 13
303 #endif
304
305 #ifndef DLT_PPP_BSDOS
306 #define DLT_PPP_BSDOS 14
307 #endif
308
309
310 /* Utility routines used by packet*.c */
311 gchar*     ether_to_str(const guint8 *);
312 gchar*     ip_to_str(const guint8 *);
313 gchar*     abs_time_to_str(struct timeval*);
314 gchar*     time_secs_to_str(guint32);
315 gchar*     bytes_to_str(const guint8 *, int);
316 const u_char *find_line_end(const u_char *data, const u_char *dataend,
317     const u_char **eol);
318 int        get_token_len(const u_char *linep, const u_char *lineend,
319     const u_char **next_token);
320 gchar*     format_text(const u_char *line, int len);
321 gchar*     val_to_str(guint32, const value_string *, const char *);
322 gchar*     match_strval(guint32, const value_string*);
323 const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
324   const char *truedesc, const char *falsedesc);
325 const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
326   const value_string *tab, const char *fmt);
327 const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
328   const char *fmt);
329 gint       check_col(frame_data *, gint);
330 void       col_add_cls_time(frame_data *);
331 #if __GNUC__ == 2
332 void       col_add_fstr(frame_data *, gint, gchar *, ...)
333     __attribute__((format (printf, 3, 4)));
334 void       col_append_fstr(frame_data *, gint, gchar *, ...)
335     __attribute__((format (printf, 3, 4)));
336 #else
337 void       col_add_fstr(frame_data *, gint, gchar *, ...);
338 void       col_append_fstr(frame_data *, gint, gchar *, ...);
339 #endif
340 void       col_add_str(frame_data *, gint, const gchar *);
341 void       col_append_str(frame_data *, gint, gchar *);
342
343
344 void dissect_packet(const u_char *, frame_data *, proto_tree *);
345 /*
346  * Routines in packet-*.c
347  * Routines should take three args: packet data *, cap_len, packet_counts *
348  * They should never modify the packet data.
349  */
350 void capture_eth(const u_char *, guint32, packet_counts *);
351 void capture_fddi(const u_char *, guint32, packet_counts *);
352 void capture_null(const u_char *, guint32, packet_counts *);
353 void capture_ppp(const u_char *, guint32, packet_counts *);
354 void capture_raw(const u_char *, guint32, packet_counts *);
355 void capture_tr(const u_char *, guint32, packet_counts *);
356
357 /*
358  * Routines in packet-*.c
359  * Routines should take four args: packet data *, offset, cap_len,
360  * packet_counts *
361  * They should never modify the packet data.
362  */
363 void capture_llc(const u_char *, int, guint32, packet_counts *);
364 void capture_ip(const u_char *, int, guint32, packet_counts *);
365
366 /*
367  * Routines in packet-*.c
368  * Routines should take three args: packet data *, frame_data *, tree *
369  * They should never modify the packet data.
370  */
371 void dissect_eth(const u_char *, frame_data *, proto_tree *);
372 void dissect_fddi(const u_char *, frame_data *, proto_tree *);
373 void dissect_null(const u_char *, frame_data *, proto_tree *);
374 void dissect_ppp(const u_char *, frame_data *, proto_tree *);
375 void dissect_raw(const u_char *, frame_data *, proto_tree *);
376 void dissect_tr(const u_char *, frame_data *, proto_tree *);
377
378 /*
379  * Routines in packet-*.c
380  * Routines should take four args: packet data *, offset, frame_data *,
381  * tree *
382  * They should never modify the packet data.
383  */
384 int dissect_ah(const u_char *, int, frame_data *, proto_tree *);
385 void dissect_aarp(const u_char *, int, frame_data *, proto_tree *);
386 void dissect_arp(const u_char *, int, frame_data *, proto_tree *);
387 void dissect_bootp(const u_char *, int, frame_data *, proto_tree *);
388 void dissect_cdp(const u_char *, int, frame_data *, proto_tree *);
389 void dissect_data(const u_char *, int, frame_data *, proto_tree *);
390 void dissect_ddp(const u_char *, int, frame_data *, proto_tree *);
391 void dissect_dns(const u_char *, int, frame_data *, proto_tree *);
392 void dissect_esp(const u_char *, int, frame_data *, proto_tree *);
393 void dissect_giop(const u_char *, int, frame_data *, proto_tree *);
394 void dissect_http(const u_char *, int, frame_data *, proto_tree *);
395 void dissect_icmp(const u_char *, int, frame_data *, proto_tree *);
396 void dissect_icmpv6(const u_char *, int, frame_data *, proto_tree *);
397 void dissect_igmp(const u_char *, int, frame_data *, proto_tree *);
398 void dissect_ip(const u_char *, int, frame_data *, proto_tree *);
399 void dissect_ipv6(const u_char *, int, frame_data *, proto_tree *);
400 void dissect_ipx(const u_char *, int, frame_data *, proto_tree *);
401 void dissect_llc(const u_char *, int, frame_data *, proto_tree *);
402 void dissect_lpd(const u_char *, int, frame_data *, proto_tree *);
403 void dissect_nbdgm(const u_char *, int, frame_data *, proto_tree *, int);
404 void dissect_nbipx_ns(const u_char *, int, frame_data *, proto_tree *, int);
405 void dissect_nbns(const u_char *, int, frame_data *, proto_tree *);
406 void dissect_ncp(const u_char *, int, frame_data *, proto_tree *, int);
407 void dissect_nwlink_dg(const u_char *, int, frame_data *, proto_tree *, int);
408 void dissect_osi(const u_char *, int, frame_data *, proto_tree *);
409 void dissect_ospf(const u_char *, int, frame_data *, proto_tree *);
410 void dissect_ospf_hello(const u_char *, int, frame_data *, proto_tree *);
411 void dissect_pppoed(const u_char *, int, frame_data *, proto_tree *);
412 void dissect_pppoes(const u_char *, int, frame_data *, proto_tree *);
413 void dissect_isakmp(const u_char *, int, frame_data *, proto_tree *);
414 void dissect_rip(const u_char *, int, frame_data *, proto_tree *);
415 void dissect_rsvp(const u_char *, int, frame_data *, proto_tree *);
416 void dissect_rtsp(const u_char *, int, frame_data *, proto_tree *);
417 void dissect_sdp(const u_char *, int, frame_data *, proto_tree *);
418 void dissect_snmp(const u_char *, int, frame_data *, proto_tree *);
419 void dissect_tcp(const u_char *, int, frame_data *, proto_tree *);
420 void dissect_tftp(const u_char *, int, frame_data *, proto_tree *);
421 void dissect_trmac(const u_char *, int, frame_data *, proto_tree *);
422 void dissect_udp(const u_char *, int, frame_data *, proto_tree *);
423 void dissect_vines(const u_char *, int, frame_data *, proto_tree *);
424 void dissect_vines_arp(const u_char *, int, frame_data *, proto_tree *);
425 void dissect_vines_frp(const u_char *, int, frame_data *, proto_tree *);
426 void dissect_vines_icp(const u_char *, int, frame_data *, proto_tree *);
427 void dissect_vines_ipc(const u_char *, int, frame_data *, proto_tree *);
428 void dissect_vines_rtp(const u_char *, int, frame_data *, proto_tree *);
429 void dissect_vines_spp(const u_char *, int, frame_data *, proto_tree *);
430 void dissect_payload_ppp(const u_char *, int, frame_data *, proto_tree *);
431
432 void dissect_ftp(const u_char *, int, frame_data *, proto_tree *, int);
433 void dissect_ftpdata(const u_char *, int, frame_data *, proto_tree *, int);
434 void dissect_nbss(const u_char *, int, frame_data *, proto_tree *, int);
435 void dissect_nntp(const u_char *, int, frame_data *, proto_tree *, int);
436 void dissect_pop(const u_char *, int, frame_data *, proto_tree *, int);
437 void dissect_smb(const u_char *, int, frame_data *, proto_tree *, int);
438 void dissect_telnet(const u_char *, int, frame_data *, proto_tree *, int);
439 void dissect_pptp(const u_char *, int, frame_data *, proto_tree *);
440 void dissect_gre(const u_char *, int, frame_data *, proto_tree *);
441
442 void init_dissect_udp(void);
443
444 /* These functions are in ethertype.c */
445 void capture_ethertype(guint16 etype, int offset,
446                 const u_char *pd, guint32 cap_len, packet_counts *ld);
447 void ethertype(guint16 etype, int offset,
448                 const u_char *pd, frame_data *fd, proto_tree *tree,
449                 proto_tree *fh_tree, int item_id);
450 extern const value_string etype_vals[];
451
452 /* These functions are in packet-arp.c */
453 gchar *arphrdaddr_to_str(guint8 *ad, int ad_len, guint16 type);
454 gchar *arphrdtype_to_str(guint16 hwtype, const char *fmt);
455
456 /*
457  * All of the possible columns in summary listing.
458  *
459  * NOTE: The SRC and DST entries MUST remain in this order, or else you
460  * need to fix the offset #defines before get_column_format!
461  */
462 enum {
463   COL_NUMBER,         /* Packet list item number */
464   COL_CLS_TIME,       /* Command line-specified time (default relative) */
465   COL_REL_TIME,       /* Relative time */
466   COL_ABS_TIME,       /* Absolute time */
467   COL_DELTA_TIME,     /* Delta time */
468   COL_DEF_SRC,        /* Source address */
469   COL_RES_SRC,        /* Resolved source */
470   COL_UNRES_SRC,      /* Unresolved source */
471   COL_DEF_DL_SRC,     /* Data link layer source address */
472   COL_RES_DL_SRC,     /* Resolved DL source */
473   COL_UNRES_DL_SRC,   /* Unresolved DL source */
474   COL_DEF_NET_SRC,    /* Network layer source address */
475   COL_RES_NET_SRC,    /* Resolved net source */
476   COL_UNRES_NET_SRC,  /* Unresolved net source */
477   COL_DEF_DST,        /* Destination address */
478   COL_RES_DST,        /* Resolved dest */
479   COL_UNRES_DST,      /* Unresolved dest */
480   COL_DEF_DL_DST,     /* Data link layer dest address */
481   COL_RES_DL_DST,     /* Resolved DL dest */
482   COL_UNRES_DL_DST,   /* Unresolved DL dest */
483   COL_DEF_NET_DST,    /* Network layer dest address */
484   COL_RES_NET_DST,    /* Resolved net dest */
485   COL_UNRES_NET_DST,  /* Unresolved net dest */
486   COL_DEF_SRC_PORT,   /* Source port */
487   COL_RES_SRC_PORT,   /* Resolved source port */
488   COL_UNRES_SRC_PORT, /* Unresolved source port */
489   COL_DEF_DST_PORT,   /* Destination port */
490   COL_RES_DST_PORT,   /* Resolved dest port */
491   COL_UNRES_DST_PORT, /* Unresolved dest port */
492   COL_PROTOCOL,       /* Protocol */
493   COL_INFO,           /* Description */
494   NUM_COL_FMTS        /* Should always be last */
495 };
496
497 #endif /* packet.h */