2 * Definitions for packet disassembly structures and routines
4 * $Id: packet.h,v 1.122 1999/10/29 01:04:18 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.
31 #include "wiretap/wtap.h"
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.
43 #define pntohs(p) ((guint16) \
44 ((guint16)*((guint8 *)p+0)<<8| \
45 (guint16)*((guint8 *)p+1)<<0))
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)
52 #define pletohs(p) ((guint16) \
53 ((guint16)*((guint8 *)p+1)<<8| \
54 (guint16)*((guint8 *)p+0)<<0))
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)
62 #define hi_nibble(b) ((b & 0xf0) >> 4)
63 #define lo_nibble(b) (b & 0x0f)
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])
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.
74 #define END_OF_FRAME (pi.captured_len - offset)
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)
80 /* Check whether there's any data at all starting at "offset". */
81 #define IS_DATA_IN_FRAME(offset) ((offset) < pi.captured_len)
83 /* To pass one of two strings, singular or plural */
84 #define plurality(d,s,p) ((d) == 1 ? (s) : (p))
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 */
95 #define COL_MAX_LEN 256
96 #define COL_MAX_INFO_LEN 4096
98 typedef struct _packet_counts {
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
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 guint32 num; /* Frame number */
118 guint32 pkt_len; /* Packet length */
119 guint32 cap_len; /* Amount actually captured */
120 guint32 rel_secs; /* Relative seconds */
121 guint32 rel_usecs; /* Relative microseconds */
122 guint32 abs_secs; /* Absolute seconds */
123 guint32 abs_usecs; /* Absolute microseconds */
124 guint32 del_secs; /* Delta seconds */
125 guint32 del_usecs; /* Delta microseconds */
126 long file_off; /* File offset */
127 column_info *cinfo; /* Column formatting information */
128 gint row; /* Row number for this packet in the display */
129 int lnk_t; /* Per-packet encapsulation/data-link type */
130 gboolean passed_dfilter; /* TRUE = display, FALSE = no display */
131 union pseudo_header pseudo_header; /* "pseudo-header" from wiretap */
134 /* Types of addresses Ethereal knows about. */
136 AT_NONE, /* no link-layer address */
137 AT_ETHER, /* MAC (Ethernet, 802.x, FDDI) address */
142 AT_ATALK, /* Appletalk DDP */
143 AT_VINES /* Banyan Vines */
146 typedef struct _address {
147 address_type type; /* type of address */
148 int len; /* length of address, in bytes */
149 const guint8 *data; /* bytes that constitute address */
152 #define SET_ADDRESS(addr, addr_type, addr_len, addr_data) { \
153 (addr)->type = (addr_type); \
154 (addr)->len = (addr_len); \
155 (addr)->data = (addr_data); \
158 /* Types of port numbers Ethereal knows about. */
160 PT_NONE, /* no port number */
165 typedef struct _packet_info {
168 address dl_src; /* link-layer source address */
169 address dl_dst; /* link-layer destination address */
170 address net_src; /* network-layer source address */
171 address net_dst; /* network-layer destination address */
172 address src; /* source address (net if present, DL otherwise )*/
173 address dst; /* destination address (net if present, DL otherwise )*/
175 port_type ptype; /* type of the following two port numbers */
176 guint32 srcport; /* source port */
177 guint32 destport; /* destination port */
183 extern packet_info pi;
185 /* Struct for the match_strval function */
187 typedef struct _value_string {
192 /* Struct for boolean enumerations */
193 typedef struct true_false_string {
199 /* Many of the structs and definitions below and in packet-*.c files
200 * were taken from include files in the Linux distribution. */
202 typedef struct tcp_extra_data {
208 /* Tree types. Each dissect_* routine should have one for each
209 add_subtree() call. */
232 ETT_IP_OPTION_TIMESTAMP,
245 ETT_NCP_REQUEST_FIELDS,
246 ETT_NCP_REPLY_FIELDS,
305 ETT_NBIPX_NAME_TYPE_FLAGS,
342 ETT_SMB_CAPABILITIES,
345 ETT_SMB_DESIREDACCESS,
348 ETT_SMB_OPENFUNCTION,
349 ETT_SMB_FILEATTRIBUTES,
365 ETT_LCP_ASYNC_MAP_OPT,
366 ETT_LCP_AUTHPROT_OPT,
367 ETT_LCP_QUALPROT_OPT,
368 ETT_LCP_MAGICNUM_OPT,
369 ETT_LCP_FCS_ALTERNATIVES_OPT,
370 ETT_LCP_NUMBERED_MODE_OPT,
371 ETT_LCP_CALLBACK_OPT,
372 ETT_LCP_MULTILINK_EP_DISC_OPT,
373 ETT_LCP_INTERNATIONALIZATION_OPT,
376 ETT_IPCP_IPADDRS_OPT,
377 ETT_IPCP_COMPRESSPROT_OPT,
379 ETT_RSVP_UNKNOWN_CLASS,
385 ETT_RSVP_TIME_VALUES,
390 ETT_RSVP_FILTER_SPEC,
391 ETT_RSVP_SENDER_TEMPLATE,
392 ETT_RSVP_SENDER_TSPEC,
396 ETT_RSVP_ADSPEC_SUBTREE1,
397 ETT_RSVP_ADSPEC_SUBTREE2,
398 ETT_RSVP_ADSPEC_SUBTREE3,
408 ETT_ATM_LANE_LC_FLAGS,
409 ETT_ATM_LANE_LC_LAN_DEST,
410 ETT_ATM_LANE_LC_LAN_DEST_RD,
439 NUM_TREE_TYPES /* last item number plus one */
442 /* TRUE if subtrees of an item of the specified type are to be expanded. */
443 extern gboolean tree_is_expanded[NUM_TREE_TYPES];
445 /* Utility routines used by packet*.c */
446 gchar* ether_to_str(const guint8 *);
447 gchar* ip_to_str(const guint8 *);
449 gchar* ip6_to_str(struct e_in6_addr *);
450 gchar* ipx_addr_to_str(guint32, const guint8 *);
451 gchar* abs_time_to_str(struct timeval*);
452 gchar* rel_time_to_str(struct timeval*);
453 gchar* time_secs_to_str(guint32);
454 gchar* bytes_to_str(const guint8 *, int);
455 const u_char *find_line_end(const u_char *data, const u_char *dataend,
457 int get_token_len(const u_char *linep, const u_char *lineend,
458 const u_char **next_token);
459 gchar* format_text(const u_char *line, int len);
460 gchar* val_to_str(guint32, const value_string *, const char *);
461 gchar* match_strval(guint32, const value_string*);
462 char * decode_bitfield_value(char *buf, guint32 val, guint32 mask, int width);
463 const char *decode_boolean_bitfield(guint32 val, guint32 mask, int width,
464 const char *truedesc, const char *falsedesc);
465 const char *decode_enumerated_bitfield(guint32 val, guint32 mask, int width,
466 const value_string *tab, const char *fmt);
467 const char *decode_numeric_bitfield(guint32 val, guint32 mask, int width,
469 gint check_col(frame_data *, gint);
471 void col_add_fstr(frame_data *, gint, gchar *, ...)
472 __attribute__((format (printf, 3, 4)));
473 void col_append_fstr(frame_data *, gint, gchar *, ...)
474 __attribute__((format (printf, 3, 4)));
476 void col_add_fstr(frame_data *, gint, gchar *, ...);
477 void col_append_fstr(frame_data *, gint, gchar *, ...);
479 void col_add_str(frame_data *, gint, const gchar *);
480 void col_append_str(frame_data *, gint, gchar *);
482 void blank_packetinfo(void);
484 void afs_init_protocol(void);
485 void rpc_init_protocol(void);
486 void smb_init_protocol(void);
488 void dissect_packet(const u_char *, frame_data *, proto_tree *);
491 * Routines in packet-*.c
492 * Routines should take three args: packet data *, cap_len, packet_counts *
493 * They should never modify the packet data.
495 void capture_clip(const u_char *, guint32, packet_counts *);
496 void capture_eth(const u_char *, guint32, packet_counts *);
497 void capture_fddi(const u_char *, guint32, packet_counts *);
498 void capture_null(const u_char *, guint32, packet_counts *);
499 void capture_ppp(const u_char *, guint32, packet_counts *);
500 void capture_raw(const u_char *, guint32, packet_counts *);
501 void capture_tr(const u_char *, guint32, packet_counts *);
504 * Routines in packet-*.c
505 * Routines should take four args: packet data *, offset, cap_len,
507 * They should never modify the packet data.
509 void capture_netbios(const u_char *, int, guint32, packet_counts *);
510 void capture_llc(const u_char *, int, guint32, packet_counts *);
511 void capture_ip(const u_char *, int, guint32, packet_counts *);
514 * Routines in packet-*.c
515 * Routines should take three args: packet data *, frame_data *, tree *
516 * They should never modify the packet data.
518 void dissect_ascend(const u_char *, frame_data *, proto_tree *);
519 void dissect_atm(const u_char *, frame_data *, proto_tree *);
520 void dissect_clip(const u_char *, frame_data *, proto_tree *);
521 void dissect_lapb(const u_char *, frame_data *, proto_tree *);
522 void dissect_null(const u_char *, frame_data *, proto_tree *);
523 void dissect_ppp(const u_char *, frame_data *, proto_tree *);
524 void dissect_raw(const u_char *, frame_data *, proto_tree *);
527 * Routines in packet-*.c
528 * Routines should take four args: packet data *, frame_data *, tree *,
530 * They should never modify the packet data.
532 void dissect_fddi(const u_char *, frame_data *, proto_tree *, gboolean);
534 typedef void (*DissectFunc) (const u_char*, int, frame_data*, proto_tree*);
537 * Routines in packet-*.c
538 * Routines should take four args: packet data *, offset, frame_data *,
540 * They should never modify the packet data.
542 int dissect_ah(const u_char *, int, frame_data *, proto_tree *);
543 void dissect_aarp(const u_char *, int, frame_data *, proto_tree *);
544 void dissect_afs(const u_char *, int, frame_data *, proto_tree *);
545 void dissect_arp(const u_char *, int, frame_data *, proto_tree *);
546 void dissect_bgp(const u_char *, int, frame_data *, proto_tree *);
547 void dissect_bootp(const u_char *, int, frame_data *, proto_tree *);
548 void dissect_bpdu(const u_char *, int, frame_data *, proto_tree *);
549 void dissect_cdp(const u_char *, int, frame_data *, proto_tree *);
550 void dissect_cotp(const u_char *, int, frame_data *, proto_tree *);
551 void dissect_data(const u_char *, int, frame_data *, proto_tree *);
552 void dissect_ddp(const u_char *, int, frame_data *, proto_tree *);
553 void dissect_dns(const u_char *, int, frame_data *, proto_tree *);
554 void dissect_esp(const u_char *, int, frame_data *, proto_tree *);
555 void dissect_eth(const u_char *, int, frame_data *, proto_tree *);
556 void dissect_ftp(const u_char *, int, frame_data *, proto_tree *);
557 void dissect_ftpdata(const u_char *, int, frame_data *, proto_tree *);
558 void dissect_giop(const u_char *, int, frame_data *, proto_tree *);
559 void dissect_http(const u_char *, int, frame_data *, proto_tree *);
560 void dissect_icmp(const u_char *, int, frame_data *, proto_tree *);
561 void dissect_icmpv6(const u_char *, int, frame_data *, proto_tree *);
562 void dissect_igmp(const u_char *, int, frame_data *, proto_tree *);
563 void dissect_ip(const u_char *, int, frame_data *, proto_tree *);
564 void dissect_ipcomp(const u_char *, int, frame_data *, proto_tree *);
565 void dissect_ipp(const u_char *, int, frame_data *, proto_tree *);
566 void dissect_ipv6(const u_char *, int, frame_data *, proto_tree *);
567 void dissect_ipx(const u_char *, int, frame_data *, proto_tree *);
568 void dissect_llc(const u_char *, int, frame_data *, proto_tree *);
569 void dissect_lpd(const u_char *, int, frame_data *, proto_tree *);
570 void dissect_nbdgm(const u_char *, int, frame_data *, proto_tree *);
571 void dissect_netbios(const u_char *, int, frame_data *, proto_tree *);
572 void dissect_nbipx(const u_char *, int, frame_data *, proto_tree *);
573 void dissect_nbns(const u_char *, int, frame_data *, proto_tree *);
574 void dissect_nbss(const u_char *, int, frame_data *, proto_tree *);
575 void dissect_ncp(const u_char *, int, frame_data *, proto_tree *);
576 void dissect_nntp(const u_char *, int, frame_data *, proto_tree *);
577 void dissect_ntp(const u_char *, int, frame_data *, proto_tree *);
578 void dissect_nwlink_dg(const u_char *, int, frame_data *, proto_tree *);
579 void dissect_osi(const u_char *, int, frame_data *, proto_tree *);
580 void dissect_ospf(const u_char *, int, frame_data *, proto_tree *);
581 void dissect_ospf_hello(const u_char *, int, frame_data *, proto_tree *);
582 void dissect_pim(const u_char *, int, frame_data *, proto_tree *);
583 void dissect_pop(const u_char *, int, frame_data *, proto_tree *);
584 void dissect_pppoed(const u_char *, int, frame_data *, proto_tree *);
585 void dissect_pppoes(const u_char *, int, frame_data *, proto_tree *);
586 void dissect_icp(const u_char *,int, frame_data *, proto_tree *);
587 void dissect_icq(const u_char *,int, frame_data *, proto_tree *);
588 void dissect_isakmp(const u_char *, int, frame_data *, proto_tree *);
589 void dissect_pim(const u_char *, int, frame_data *, proto_tree *);
590 void dissect_radius(const u_char *, int, frame_data *, proto_tree *);
591 void dissect_rip(const u_char *, int, frame_data *, proto_tree *);
592 void dissect_ripng(const u_char *, int, frame_data *, proto_tree *);
593 void dissect_rsvp(const u_char *, int, frame_data *, proto_tree *);
594 void dissect_rtsp(const u_char *, int, frame_data *, proto_tree *);
595 void dissect_rx(const u_char *, int, frame_data *, proto_tree *);
596 void dissect_sdp(const u_char *, int, frame_data *, proto_tree *);
597 void dissect_sna(const u_char *, int, frame_data *, proto_tree *);
598 void dissect_snmp(const u_char *, int, frame_data *, proto_tree *);
599 void dissect_tcp(const u_char *, int, frame_data *, proto_tree *);
600 void dissect_telnet(const u_char *, int, frame_data *, proto_tree *);
601 void dissect_tftp(const u_char *, int, frame_data *, proto_tree *);
602 void dissect_tr(const u_char *, int, frame_data *, proto_tree *);
603 void dissect_trmac(const u_char *, int, frame_data *, proto_tree *);
604 void dissect_udp(const u_char *, int, frame_data *, proto_tree *);
605 void dissect_vines(const u_char *, int, frame_data *, proto_tree *);
606 void dissect_vines_arp(const u_char *, int, frame_data *, proto_tree *);
607 void dissect_vines_frp(const u_char *, int, frame_data *, proto_tree *);
608 void dissect_vines_icp(const u_char *, int, frame_data *, proto_tree *);
609 void dissect_vines_ipc(const u_char *, int, frame_data *, proto_tree *);
610 void dissect_vines_rtp(const u_char *, int, frame_data *, proto_tree *);
611 void dissect_vines_spp(const u_char *, int, frame_data *, proto_tree *);
612 void dissect_vlan(const u_char *, int, frame_data *, proto_tree *);
613 void dissect_payload_ppp(const u_char *, int, frame_data *, proto_tree *);
614 void dissect_x25(const u_char *, int, frame_data *, proto_tree *);
615 void dissect_yhoo(const u_char *, int, frame_data *, proto_tree *);
617 void dissect_smb(const u_char *, int, frame_data *, proto_tree *, int);
618 void dissect_pptp(const u_char *, int, frame_data *, proto_tree *);
619 void dissect_gre(const u_char *, int, frame_data *, proto_tree *);
621 void dissect_rpc(const u_char *, int, frame_data *, proto_tree *, guint32, void*);
623 void init_dissect_rpc(void);
624 void init_dissect_udp(void);
625 void init_dissect_x25(void);
627 /* These functions are in ethertype.c */
628 void capture_ethertype(guint16 etype, int offset,
629 const u_char *pd, guint32 cap_len, packet_counts *ld);
630 void ethertype(guint16 etype, int offset,
631 const u_char *pd, frame_data *fd, proto_tree *tree,
632 proto_tree *fh_tree, int item_id);
633 extern const value_string etype_vals[];
635 /* These functions are in packet-arp.c */
636 gchar *arphrdaddr_to_str(guint8 *ad, int ad_len, guint16 type);
637 gchar *arphrdtype_to_str(guint16 hwtype, const char *fmt);
640 extern const char *ipprotostr(int proto);
643 * All of the possible columns in summary listing.
645 * NOTE: The SRC and DST entries MUST remain in this order, or else you
646 * need to fix the offset #defines before get_column_format!
649 COL_NUMBER, /* Packet list item number */
650 COL_CLS_TIME, /* Command line-specified time (default relative) */
651 COL_REL_TIME, /* Relative time */
652 COL_ABS_TIME, /* Absolute time */
653 COL_DELTA_TIME, /* Delta time */
654 COL_DEF_SRC, /* Source address */
655 COL_RES_SRC, /* Resolved source */
656 COL_UNRES_SRC, /* Unresolved source */
657 COL_DEF_DL_SRC, /* Data link layer source address */
658 COL_RES_DL_SRC, /* Resolved DL source */
659 COL_UNRES_DL_SRC, /* Unresolved DL source */
660 COL_DEF_NET_SRC, /* Network layer source address */
661 COL_RES_NET_SRC, /* Resolved net source */
662 COL_UNRES_NET_SRC, /* Unresolved net source */
663 COL_DEF_DST, /* Destination address */
664 COL_RES_DST, /* Resolved dest */
665 COL_UNRES_DST, /* Unresolved dest */
666 COL_DEF_DL_DST, /* Data link layer dest address */
667 COL_RES_DL_DST, /* Resolved DL dest */
668 COL_UNRES_DL_DST, /* Unresolved DL dest */
669 COL_DEF_NET_DST, /* Network layer dest address */
670 COL_RES_NET_DST, /* Resolved net dest */
671 COL_UNRES_NET_DST, /* Unresolved net dest */
672 COL_DEF_SRC_PORT, /* Source port */
673 COL_RES_SRC_PORT, /* Resolved source port */
674 COL_UNRES_SRC_PORT, /* Unresolved source port */
675 COL_DEF_DST_PORT, /* Destination port */
676 COL_RES_DST_PORT, /* Resolved dest port */
677 COL_UNRES_DST_PORT, /* Unresolved dest port */
678 COL_PROTOCOL, /* Protocol */
679 COL_INFO, /* Description */
680 COL_PACKET_LENGTH, /* Packet length in bytes */
681 NUM_COL_FMTS /* Should always be last */
684 #endif /* packet.h */