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