2 * Definitions for packet disassembly structures and routines
4 * $Id: packet.h,v 1.14 1998/10/14 04:09:14 gram 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.
30 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
31 * byte array, returns the value of the two or four bytes at the pointer.
32 * The pletoh[sl] versions return the little-endian representation.
35 #define pntohs(p) ((guint16) \
36 ((guint16)*((guint8 *)p+0)<<8| \
37 (guint16)*((guint8 *)p+1)<<0))
39 #define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
40 (guint32)*((guint8 *)p+1)<<16| \
41 (guint32)*((guint8 *)p+2)<<8| \
42 (guint32)*((guint8 *)p+3)<<0)
44 #define pletohs(p) ((guint16) \
45 ((guint16)*((guint8 *)p+1)<<8| \
46 (guint16)*((guint8 *)p+0)<<0))
48 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
49 (guint32)*((guint8 *)p+2)<<16| \
50 (guint32)*((guint8 *)p+1)<<8| \
51 (guint32)*((guint8 *)p+0)<<0)
54 /* Useful when highlighting regions inside a dissect_*() function. With this
55 * macro, you can highlight from the start of the packet to the end of the
56 * frame. See dissect_data() for an example.
58 #define END_OF_FRAME (fd->cap_len - offset)
60 #define IEEE_802_3_MAX_LEN 1500
61 #define BYTE_VIEW_WIDTH 16
63 typedef struct _frame_data {
64 guint32 pkt_len; /* Packet length */
65 guint32 cap_len; /* Amount actually captured */
66 guint32 secs; /* Seconds */
67 guint32 usecs; /* Microseconds */
68 long file_off; /* File offset */
69 gchar *win_info[NUM_COLS]; /* Text for packet summary list fields */
72 typedef struct _packet_info {
83 /* Struct for the match_strval function */
85 typedef struct _value_string {
90 /* Many of the structs and definitions below were taken from include files
91 * in the Linux distribution. */
93 /* ARP / RARP structs and definitions */
95 typedef struct _e_ether_arp {
107 #ifndef ARPOP_REQUEST
108 #define ARPOP_REQUEST 1 /* ARP request. */
111 #define ARPOP_REPLY 2 /* ARP reply. */
113 /* Some OSes have different names, or don't define these at all */
114 #ifndef ARPOP_RREQUEST
115 #define ARPOP_RREQUEST 3 /* RARP request. */
118 #define ARPOP_RREPLY 4 /* RARP reply. */
121 /* ICMP structs and definitions */
123 typedef struct _e_icmp {
128 struct { /* Address mask request/reply */
133 struct { /* Timestap request/reply */
140 guint32 zero; /* Unreachable */
144 #define ICMP_ECHOREPLY 0
145 #define ICMP_UNREACH 3
146 #define ICMP_SOURCEQUENCH 4
147 #define ICMP_REDIRECT 5
149 #define ICMP_TIMXCEED 11
150 #define ICMP_PARAMPROB 12
151 #define ICMP_TSTAMP 13
152 #define ICMP_TSTAMPREPLY 14
154 #define ICMP_IREQREPLY 16
155 #define ICMP_MASKREQ 17
156 #define ICMP_MASKREPLY 18
158 /* IGMP structs and definitions */
160 typedef struct _e_igmp {
161 #if BYTE_ORDER == BIG_ENDIAN
164 #else /* Little endian */
173 #define IGMP_M_QRY 0x01
174 #define IGMP_V1_M_RPT 0x02
175 #define IGMP_V2_LV_GRP 0x07
176 #define IGMP_DVMRP 0x03
177 #define IGMP_PIM 0x04
178 #define IGMP_V2_M_RPT 0x06
179 #define IGMP_MTRC_RESP 0x1e
180 #define IGMP_MTRC 0x1f
182 /* IP structs and definitions */
184 typedef struct _e_ip {
185 #if BYTE_ORDER == BIG_ENDIAN
188 #else /* Little endian */
204 #define IP_CE 0x8000 /* Flag: "Congestion" */
205 #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
206 #define IP_MF 0x2000 /* Flag: "More Fragments" */
207 #define IP_OFFSET 0x1FFF /* "Fragment Offset" part */
209 #define IPTOS_TOS_MASK 0x1E
210 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
211 #define IPTOS_NONE 0x00
212 #define IPTOS_LOWDELAY 0x10
213 #define IPTOS_THROUGHPUT 0x08
214 #define IPTOS_RELIABILITY 0x04
215 #define IPTOS_LOWCOST 0x02
217 #define IPTOS_PREC_MASK 0xE0
218 #define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK)
219 #define IPTOS_PREC_NETCONTROL 0xe0
220 #define IPTOS_PREC_INTERNETCONTROL 0xc0
221 #define IPTOS_PREC_CRITIC_ECP 0xa0
222 #define IPTOS_PREC_FLASHOVERRIDE 0x80
223 #define IPTOS_PREC_FLASH 0x60
224 #define IPTOS_PREC_IMMEDIATE 0x40
225 #define IPTOS_PREC_PRIORITY 0x20
226 #define IPTOS_PREC_ROUTINE 0x00
229 #define IPOPT_COPY 0x80
231 #define IPOPT_CONTROL 0x00
232 #define IPOPT_RESERVED1 0x20
233 #define IPOPT_MEASUREMENT 0x40
234 #define IPOPT_RESERVED2 0x60
236 #define IPOPT_END (0 |IPOPT_CONTROL)
237 #define IPOPT_NOOP (1 |IPOPT_CONTROL)
238 #define IPOPT_SEC (2 |IPOPT_CONTROL|IPOPT_COPY)
239 #define IPOPT_LSRR (3 |IPOPT_CONTROL|IPOPT_COPY)
240 #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT)
241 #define IPOPT_RR (7 |IPOPT_CONTROL)
242 #define IPOPT_SID (8 |IPOPT_CONTROL|IPOPT_COPY)
243 #define IPOPT_SSRR (9 |IPOPT_CONTROL|IPOPT_COPY)
244 #define IPOPT_RA (20|IPOPT_CONTROL|IPOPT_COPY)
246 /* IP option lengths */
247 #define IPOLEN_SEC 11
248 #define IPOLEN_LSRR_MIN 3
249 #define IPOLEN_TIMESTAMP_MIN 5
250 #define IPOLEN_RR_MIN 3
252 #define IPOLEN_SSRR_MIN 3
254 #define IPSEC_UNCLASSIFIED 0x0000
255 #define IPSEC_CONFIDENTIAL 0xF135
256 #define IPSEC_EFTO 0x789A
257 #define IPSEC_MMMM 0xBC4D
258 #define IPSEC_RESTRICTED 0xAF13
259 #define IPSEC_SECRET 0xD788
260 #define IPSEC_TOPSECRET 0x6BC5
261 #define IPSEC_RESERVED1 0x35E2
262 #define IPSEC_RESERVED2 0x9AF1
263 #define IPSEC_RESERVED3 0x4D78
264 #define IPSEC_RESERVED4 0x24BD
265 #define IPSEC_RESERVED5 0x135E
266 #define IPSEC_RESERVED6 0x89AF
267 #define IPSEC_RESERVED7 0xC4D6
268 #define IPSEC_RESERVED8 0xE26B
270 #define IPOPT_TS_TSONLY 0 /* timestamps only */
271 #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
272 #define IPOPT_TS_PRESPEC 3 /* specified modules only */
274 #define IP_PROTO_ICMP 1
275 #define IP_PROTO_IGMP 2
276 #define IP_PROTO_TCP 6
277 #define IP_PROTO_UDP 17
278 #define IP_PROTO_OSPF 89
280 /* Null/loopback structs and definitions */
282 typedef struct _e_nullhdr {
288 /* PPP structs and definitions */
290 typedef struct _e_ppphdr {
296 /* TCP structs and definitions */
298 typedef struct _e_tcphdr {
303 #if BYTE_ORDER == LITTLE_ENDIAN
326 #define TCPOPT_NOP 1 /* Padding */
327 #define TCPOPT_EOL 0 /* End of options */
328 #define TCPOPT_MSS 2 /* Segment size negotiating */
329 #define TCPOPT_WINDOW 3 /* Window scaling */
330 #define TCPOPT_SACK_PERM 4 /* SACK Permitted */
331 #define TCPOPT_SACK 5 /* SACK Block */
332 #define TCPOPT_ECHO 6
333 #define TCPOPT_ECHOREPLY 7
334 #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
336 #define TCPOPT_CCNEW 12
337 #define TCPOPT_CCECHO 13
343 #define TCPOLEN_MSS 4
344 #define TCPOLEN_WINDOW 3
345 #define TCPOLEN_SACK_PERM 2
346 #define TCPOLEN_SACK_MIN 2
347 #define TCPOLEN_ECHO 6
348 #define TCPOLEN_ECHOREPLY 6
349 #define TCPOLEN_TIMESTAMP 10
351 #define TCPOLEN_CCNEW 6
352 #define TCPOLEN_CCECHO 6
354 /* UDP structs and definitions */
356 typedef struct _e_udphdr {
363 /* UDP Ports -> should go in packet-udp.h */
365 #define UDP_PORT_DNS 53
366 #define UDP_PORT_BOOTPS 67
367 #define UDP_PORT_IPX 213
368 #define UDP_PORT_NBNS 137
369 #define UDP_PORT_RIP 520
373 #define TCP_PORT_PRINTER 515
375 /* Tree types. Each dissect_* routine should have one for each
376 add_subtree() call. */
395 ETT_IP_OPTION_TIMESTAMP,
431 NUM_TREE_TYPES /* last item number plus one */
434 /* The version of pcap.h that comes with some systems is missing these
442 #ifndef DLT_SLIP_BSDOS
443 #define DLT_SLIP_BSDOS 13
446 #ifndef DLT_PPP_BSDOS
447 #define DLT_PPP_BSDOS 14
451 NO_LENGTH, /* option has no data, hence no length */
452 FIXED_LENGTH, /* option always has the same length */
453 VARIABLE_LENGTH /* option is variable-length - optlen is minimum */
456 /* Member of table of IP or TCP options. */
458 int optcode; /* code for option */
459 char *name; /* name of option */
460 opt_len_type len_type; /* type of option length field */
461 int optlen; /* value length should be (minimum if VARIABLE) */
462 void (*dissect)(GtkWidget *, const char *, const u_char *, int, guint);
463 /* routine to dissect option */
466 /* Routine to dissect IP or TCP options. */
467 void dissect_ip_tcp_options(GtkWidget *, const u_char *, int, guint,
468 ip_tcp_opt *, int, int);
470 /* Utility routines used by packet*.c */
471 gchar* ether_to_str(guint8 *);
472 gchar* ip_to_str(guint8 *);
473 void packet_hex_print(GtkText *, guint8 *, gint, gint, gint);
474 #define E_TREEINFO_START_KEY "tree_info_start"
475 #define E_TREEINFO_LEN_KEY "tree_info_len"
477 GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...)
478 __attribute__((format (printf, 4, 5)));
480 GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...);
482 gchar* match_strval(guint32, value_string*, gint);
484 /* Routines in packet.c */
486 void dissect_packet(const u_char *, guint32 ts_secs, guint32 ts_usecs,
487 frame_data *, GtkTree *);
488 void add_subtree(GtkWidget *, GtkWidget*, gint);
489 void expand_tree(GtkWidget *, gpointer);
490 void collapse_tree(GtkWidget *, gpointer);
493 * Routines in packet-*.c
494 * Routines should take three args: packet data *, frame_data *, tree *
495 * They should never modify the packet data.
497 void dissect_eth(const u_char *, frame_data *, GtkTree *);
498 void dissect_fddi(const u_char *, frame_data *, GtkTree *);
499 void dissect_null(const u_char *, frame_data *, GtkTree *);
500 void dissect_ppp(const u_char *, frame_data *, GtkTree *);
501 void dissect_raw(const u_char *, frame_data *, GtkTree *);
502 void dissect_tr(const u_char *, frame_data *, GtkTree *);
505 * Routines in packet-*.c
506 * Routines should take four args: packet data *, offset, frame_data *,
508 * They should never modify the packet data.
510 void dissect_arp(const u_char *, int, frame_data *, GtkTree *);
511 void dissect_bootp(const u_char *, int, frame_data *, GtkTree *);
512 void dissect_data(const u_char *, int, frame_data *, GtkTree *);
513 void dissect_dns(const u_char *, int, frame_data *, GtkTree *);
514 void dissect_icmp(const u_char *, int, frame_data *, GtkTree *);
515 void dissect_igmp(const u_char *, int, frame_data *, GtkTree *);
516 void dissect_ip(const u_char *, int, frame_data *, GtkTree *);
517 void dissect_ipv6(const u_char *, int, frame_data *, GtkTree *);
518 void dissect_ipx(const u_char *, int, frame_data *, GtkTree *);
519 void dissect_llc(const u_char *, int, frame_data *, GtkTree *);
520 void dissect_lpd(const u_char *, int, frame_data *, GtkTree *);
521 void dissect_nbipx(const u_char *, int, frame_data *, GtkTree *);
522 void dissect_nbns(const u_char *, int, frame_data *, GtkTree *);
523 void dissect_ncp(const u_char *, int, frame_data *, GtkTree *);
524 void dissect_osi(const u_char *, int, frame_data *, GtkTree *);
525 void dissect_ospf(const u_char *, int, frame_data *, GtkTree *);
526 void dissect_ospf_hello(const u_char *, int, frame_data *, GtkTree *);
527 void dissect_rip(const u_char *, int, frame_data *, GtkTree *);
528 void dissect_tcp(const u_char *, int, frame_data *, GtkTree *);
529 void dissect_trmac(const u_char *, int, frame_data *, GtkTree *);
530 void dissect_udp(const u_char *, int, frame_data *, GtkTree *);
531 void dissect_vines(const u_char *, int, frame_data *, GtkTree *);
532 void dissect_vspp(const u_char *, int, frame_data *, GtkTree *);
534 /* This function is in ethertype.c */
535 void ethertype(guint16 etype, int offset,
536 const u_char *pd, frame_data *fd, GtkTree *tree,
539 #endif /* packet.h */