2 * Definitions for packet disassembly structures and routines
4 * $Id: packet.h,v 1.79 1999/08/04 04:37:45 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
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.
39 #define pntohs(p) ((guint16) \
40 ((guint16)*((guint8 *)p+0)<<8| \
41 (guint16)*((guint8 *)p+1)<<0))
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)
48 #define pletohs(p) ((guint16) \
49 ((guint16)*((guint8 *)p+1)<<8| \
50 (guint16)*((guint8 *)p+0)<<0))
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)
58 #define hi_nibble(b) ((b & 0xf0) >> 4)
59 #define lo_nibble(b) (b & 0x0f)
63 #define LITTLE_ENDIAN 4321
64 #define BIG_ENDIAN 1234
65 #ifdef WORDS_BIGENDIAN
66 #define BYTE_ORDER BIG_ENDIAN
68 #define BYTE_ORDER LITTLE_ENDIAN
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])
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.
80 #define END_OF_FRAME (fd->cap_len - offset)
82 /* To pass one of two strings, singular or plural */
83 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
85 typedef struct _column_info {
86 gint num_cols; /* Number of columns */
87 gint *col_fmt; /* Format of column */
88 gboolean **fmt_matx; /* Specifies which formats apply to a column */
89 gint *col_width; /* Column widths to use during a "-S" capture */
90 gchar **col_data; /* Column data */
93 #define COL_MAX_LEN 256
95 typedef struct _packet_counts {
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 guint8 flags; /* for ENCAP_LAPB : 1st bit means From DCE */
120 typedef struct _packet_info {
132 /* Struct for the match_strval function */
134 typedef struct _value_string {
139 /* Many of the structs and definitions below and in packet-*.c files
140 * were taken from include files in the Linux distribution. */
142 typedef struct tcp_extra_data {
148 /* Tree types. Each dissect_* routine should have one for each
149 add_subtree() call. */
171 ETT_IP_OPTION_TIMESTAMP,
184 ETT_NCP_REQUEST_FIELDS,
185 ETT_NCP_REPLY_FIELDS,
255 ETT_SMB_CAPABILITIES,
258 ETT_SMB_DESIREDACCESS,
261 ETT_SMB_OPENFUNCTION,
262 ETT_SMB_FILEATTRIBUTES,
274 ETT_RSVP_UNKNOWN_CLASS,
280 ETT_RSVP_TIME_VALUES,
285 ETT_RSVP_FILTER_SPEC,
286 ETT_RSVP_SENDER_TEMPLATE,
287 ETT_RSVP_SENDER_TSPEC,
291 ETT_RSVP_ADSPEC_SUBTREE1,
292 ETT_RSVP_ADSPEC_SUBTREE2,
293 ETT_RSVP_ADSPEC_SUBTREE3,
301 NUM_TREE_TYPES /* last item number plus one */
304 /* The version of pcap.h that comes with some systems is missing these
312 #ifndef DLT_SLIP_BSDOS
313 #define DLT_SLIP_BSDOS 13
316 #ifndef DLT_PPP_BSDOS
317 #define DLT_PPP_BSDOS 14
321 /* Utility routines used by packet*.c */
322 gchar* ether_to_str(const guint8 *);
323 gchar* ip_to_str(const guint8 *);
324 gchar* abs_time_to_str(struct timeval*);
325 gchar* time_secs_to_str(guint32);
326 gchar* bytes_to_str(const guint8 *, int);
327 const u_char *find_line_end(const u_char *data, const u_char *dataend,
329 int get_token_len(const u_char *linep, const u_char *lineend,
330 const u_char **next_token);
331 gchar* format_text(const u_char *line, int len);
332 gchar* val_to_str(guint32, const value_string *, const char *);
333 gchar* match_strval(guint32, const value_string*);
334 const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
335 const char *truedesc, const char *falsedesc);
336 const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
337 const value_string *tab, const char *fmt);
338 const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
340 gint check_col(frame_data *, gint);
341 void col_add_cls_time(frame_data *);
343 void col_add_fstr(frame_data *, gint, gchar *, ...)
344 __attribute__((format (printf, 3, 4)));
345 void col_append_fstr(frame_data *, gint, gchar *, ...)
346 __attribute__((format (printf, 3, 4)));
348 void col_add_fstr(frame_data *, gint, gchar *, ...);
349 void col_append_fstr(frame_data *, gint, gchar *, ...);
351 void col_add_str(frame_data *, gint, const gchar *);
352 void col_append_str(frame_data *, gint, gchar *);
355 void dissect_packet(const u_char *, frame_data *, proto_tree *);
357 * Routines in packet-*.c
358 * Routines should take three args: packet data *, cap_len, packet_counts *
359 * They should never modify the packet data.
361 void capture_clip(const u_char *, guint32, packet_counts *);
362 void capture_eth(const u_char *, guint32, packet_counts *);
363 void capture_fddi(const u_char *, guint32, packet_counts *);
364 void capture_null(const u_char *, guint32, packet_counts *);
365 void capture_ppp(const u_char *, guint32, packet_counts *);
366 void capture_raw(const u_char *, guint32, packet_counts *);
367 void capture_tr(const u_char *, guint32, packet_counts *);
370 * Routines in packet-*.c
371 * Routines should take four args: packet data *, offset, cap_len,
373 * They should never modify the packet data.
375 void capture_llc(const u_char *, int, guint32, packet_counts *);
376 void capture_ip(const u_char *, int, guint32, packet_counts *);
379 * Routines in packet-*.c
380 * Routines should take three args: packet data *, frame_data *, tree *
381 * They should never modify the packet data.
383 void dissect_clip(const u_char *, frame_data *, proto_tree *);
384 void dissect_eth(const u_char *, frame_data *, proto_tree *);
385 void dissect_fddi(const u_char *, frame_data *, proto_tree *);
386 void dissect_lapb(const u_char *, frame_data *, proto_tree *);
387 void dissect_null(const u_char *, frame_data *, proto_tree *);
388 void dissect_ppp(const u_char *, frame_data *, proto_tree *);
389 void dissect_raw(const u_char *, frame_data *, proto_tree *);
390 void dissect_tr(const u_char *, frame_data *, proto_tree *);
393 * Routines in packet-*.c
394 * Routines should take four args: packet data *, offset, frame_data *,
396 * They should never modify the packet data.
398 int dissect_ah(const u_char *, int, frame_data *, proto_tree *);
399 void dissect_aarp(const u_char *, int, frame_data *, proto_tree *);
400 void dissect_arp(const u_char *, int, frame_data *, proto_tree *);
401 void dissect_bootp(const u_char *, int, frame_data *, proto_tree *);
402 void dissect_cdp(const u_char *, int, frame_data *, proto_tree *);
403 void dissect_cotp(const u_char *, int, frame_data *, proto_tree *);
404 void dissect_data(const u_char *, int, frame_data *, proto_tree *);
405 void dissect_ddp(const u_char *, int, frame_data *, proto_tree *);
406 void dissect_dns(const u_char *, int, frame_data *, proto_tree *);
407 void dissect_esp(const u_char *, int, frame_data *, proto_tree *);
408 void dissect_giop(const u_char *, int, frame_data *, proto_tree *);
409 void dissect_http(const u_char *, int, frame_data *, proto_tree *);
410 void dissect_icmp(const u_char *, int, frame_data *, proto_tree *);
411 void dissect_icmpv6(const u_char *, int, frame_data *, proto_tree *);
412 void dissect_igmp(const u_char *, int, frame_data *, proto_tree *);
413 void dissect_ip(const u_char *, int, frame_data *, proto_tree *);
414 void dissect_ipv6(const u_char *, int, frame_data *, proto_tree *);
415 void dissect_ipx(const u_char *, int, frame_data *, proto_tree *);
416 void dissect_llc(const u_char *, int, frame_data *, proto_tree *);
417 void dissect_lpd(const u_char *, int, frame_data *, proto_tree *);
418 void dissect_nbdgm(const u_char *, int, frame_data *, proto_tree *, int);
419 void dissect_nbipx_ns(const u_char *, int, frame_data *, proto_tree *, int);
420 void dissect_nbns(const u_char *, int, frame_data *, proto_tree *);
421 void dissect_ncp(const u_char *, int, frame_data *, proto_tree *, int);
422 void dissect_nwlink_dg(const u_char *, int, frame_data *, proto_tree *, int);
423 void dissect_osi(const u_char *, int, frame_data *, proto_tree *);
424 void dissect_ospf(const u_char *, int, frame_data *, proto_tree *);
425 void dissect_ospf_hello(const u_char *, int, frame_data *, proto_tree *);
426 void dissect_pppoed(const u_char *, int, frame_data *, proto_tree *);
427 void dissect_pppoes(const u_char *, int, frame_data *, proto_tree *);
428 void dissect_isakmp(const u_char *, int, frame_data *, proto_tree *);
429 void dissect_radius(const u_char *, int, frame_data *, proto_tree *);
430 void dissect_rip(const u_char *, int, frame_data *, proto_tree *);
431 void dissect_rsvp(const u_char *, int, frame_data *, proto_tree *);
432 void dissect_rtsp(const u_char *, int, frame_data *, proto_tree *);
433 void dissect_sdp(const u_char *, int, frame_data *, proto_tree *);
434 void dissect_snmp(const u_char *, int, frame_data *, proto_tree *);
435 void dissect_tcp(const u_char *, int, frame_data *, proto_tree *);
436 void dissect_tftp(const u_char *, int, frame_data *, proto_tree *);
437 void dissect_trmac(const u_char *, int, frame_data *, proto_tree *);
438 void dissect_udp(const u_char *, int, frame_data *, proto_tree *);
439 void dissect_vines(const u_char *, int, frame_data *, proto_tree *);
440 void dissect_vines_arp(const u_char *, int, frame_data *, proto_tree *);
441 void dissect_vines_frp(const u_char *, int, frame_data *, proto_tree *);
442 void dissect_vines_icp(const u_char *, int, frame_data *, proto_tree *);
443 void dissect_vines_ipc(const u_char *, int, frame_data *, proto_tree *);
444 void dissect_vines_rtp(const u_char *, int, frame_data *, proto_tree *);
445 void dissect_vines_spp(const u_char *, int, frame_data *, proto_tree *);
446 void dissect_payload_ppp(const u_char *, int, frame_data *, proto_tree *);
447 void dissect_x25(const u_char *, int, frame_data *, proto_tree *);
449 void dissect_ftp(const u_char *, int, frame_data *, proto_tree *, int);
450 void dissect_ftpdata(const u_char *, int, frame_data *, proto_tree *, int);
451 void dissect_nbss(const u_char *, int, frame_data *, proto_tree *, int);
452 void dissect_nntp(const u_char *, int, frame_data *, proto_tree *, int);
453 void dissect_pop(const u_char *, int, frame_data *, proto_tree *, int);
454 void dissect_smb(const u_char *, int, frame_data *, proto_tree *, int);
455 void dissect_telnet(const u_char *, int, frame_data *, proto_tree *, int);
456 void dissect_pptp(const u_char *, int, frame_data *, proto_tree *);
457 void dissect_gre(const u_char *, int, frame_data *, proto_tree *);
459 void init_dissect_udp(void);
460 void init_dissect_x25(void);
462 /* These functions are in ethertype.c */
463 void capture_ethertype(guint16 etype, int offset,
464 const u_char *pd, guint32 cap_len, packet_counts *ld);
465 void ethertype(guint16 etype, int offset,
466 const u_char *pd, frame_data *fd, proto_tree *tree,
467 proto_tree *fh_tree, int item_id);
468 extern const value_string etype_vals[];
470 /* These functions are in packet-arp.c */
471 gchar *arphrdaddr_to_str(guint8 *ad, int ad_len, guint16 type);
472 gchar *arphrdtype_to_str(guint16 hwtype, const char *fmt);
475 * All of the possible columns in summary listing.
477 * NOTE: The SRC and DST entries MUST remain in this order, or else you
478 * need to fix the offset #defines before get_column_format!
481 COL_NUMBER, /* Packet list item number */
482 COL_CLS_TIME, /* Command line-specified time (default relative) */
483 COL_REL_TIME, /* Relative time */
484 COL_ABS_TIME, /* Absolute time */
485 COL_DELTA_TIME, /* Delta time */
486 COL_DEF_SRC, /* Source address */
487 COL_RES_SRC, /* Resolved source */
488 COL_UNRES_SRC, /* Unresolved source */
489 COL_DEF_DL_SRC, /* Data link layer source address */
490 COL_RES_DL_SRC, /* Resolved DL source */
491 COL_UNRES_DL_SRC, /* Unresolved DL source */
492 COL_DEF_NET_SRC, /* Network layer source address */
493 COL_RES_NET_SRC, /* Resolved net source */
494 COL_UNRES_NET_SRC, /* Unresolved net source */
495 COL_DEF_DST, /* Destination address */
496 COL_RES_DST, /* Resolved dest */
497 COL_UNRES_DST, /* Unresolved dest */
498 COL_DEF_DL_DST, /* Data link layer dest address */
499 COL_RES_DL_DST, /* Resolved DL dest */
500 COL_UNRES_DL_DST, /* Unresolved DL dest */
501 COL_DEF_NET_DST, /* Network layer dest address */
502 COL_RES_NET_DST, /* Resolved net dest */
503 COL_UNRES_NET_DST, /* Unresolved net dest */
504 COL_DEF_SRC_PORT, /* Source port */
505 COL_RES_SRC_PORT, /* Resolved source port */
506 COL_UNRES_SRC_PORT, /* Unresolved source port */
507 COL_DEF_DST_PORT, /* Destination port */
508 COL_RES_DST_PORT, /* Resolved dest port */
509 COL_UNRES_DST_PORT, /* Unresolved dest port */
510 COL_PROTOCOL, /* Protocol */
511 COL_INFO, /* Description */
512 COL_PACKET_LENGTH, /* Packet length in bytes */
513 NUM_COL_FMTS /* Should always be last */
516 #endif /* packet.h */