2 * Definitions for packet disassembly structures and routines
4 * $Id: packet.h,v 1.6 1998/09/21 16:16:00 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.
35 #if BYTE_ORDER == LITTLE_ENDIAN
36 #define pntohs(p) ((guint16) \
37 ((guint16)*((guint8 *)p+0)<<8| \
38 (guint16)*((guint8 *)p+1)<<0))
40 #define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
41 (guint32)*((guint8 *)p+1)<<16| \
42 (guint32)*((guint8 *)p+2)<<8| \
43 (guint32)*((guint8 *)p+3)<<0)
44 #else /* BIG_ENDIAN */
45 #define pntohs(p) ((guint16) \
46 ((guint16)*((guint8 *)p+1)<<8| \
47 (guint16)*((guint8 *)p+0)<<0))
49 #define pntohl(p) ((guint32)*((guint8 *)p+3)<<24| \
50 (guint32)*((guint8 *)p+2)<<16| \
51 (guint32)*((guint8 *)p+1)<<8| \
52 (guint32)*((guint8 *)p+0)<<0)
53 #endif /* LITTLE_ENDIAN */
55 #define IEEE_802_3_MAX_LEN 1500
56 #define BYTE_VIEW_WIDTH 16
58 typedef struct _frame_data {
59 guint32 pkt_len; /* Packet length */
60 guint32 cap_len; /* Amount actually captured */
61 guint32 secs; /* Seconds */
62 guint32 usecs; /* Microseconds */
63 long file_off; /* File offset */
64 gchar *win_info[5]; /* Packet list text */
67 typedef struct _packet_info {
78 /* Many of the structs and definitions below were taken from include files
79 * in the Linux distribution. */
81 /* ARP / RARP structs and definitions */
83 typedef struct _e_ether_arp {
96 #define ARPOP_REQUEST 1 /* ARP request. */
99 #define ARPOP_REPLY 2 /* ARP reply. */
101 /* Some OSes have different names, or don't define these at all */
102 #ifndef ARPOP_RREQUEST
103 #define ARPOP_RREQUEST 3 /* RARP request. */
106 #define ARPOP_RREPLY 4 /* RARP reply. */
109 /* ICMP structs and definitions */
111 typedef struct _e_icmp {
116 struct { /* Address mask request/reply */
121 struct { /* Timestap request/reply */
128 guint32 zero; /* Unreachable */
132 #define ICMP_ECHOREPLY 0
133 #define ICMP_UNREACH 3
134 #define ICMP_SOURCEQUENCH 4
135 #define ICMP_REDIRECT 5
137 #define ICMP_TIMXCEED 11
138 #define ICMP_PARAMPROB 12
139 #define ICMP_TSTAMP 13
140 #define ICMP_TSTAMPREPLY 14
142 #define ICMP_IREQREPLY 16
143 #define ICMP_MASKREQ 17
144 #define ICMP_MASKREPLY 18
146 /* IGMP structs and definitions */
148 typedef struct _e_igmp {
149 #if BYTE_ORDER == BIG_ENDIAN
152 #else /* Little endian */
161 #define IGMP_M_QRY 0x01
162 #define IGMP_V1_M_RPT 0x02
163 #define IGMP_V2_LV_GRP 0x07
164 #define IGMP_DVMRP 0x03
165 #define IGMP_PIM 0x04
166 #define IGMP_V2_M_RPT 0x06
167 #define IGMP_MTRC_RESP 0x1e
168 #define IGMP_MTRC 0x1f
170 /* IP structs and definitions */
172 typedef struct _e_ip {
173 #if BYTE_ORDER == BIG_ENDIAN
176 #else /* Little endian */
191 #define IPTOS_TOS_MASK 0x1E
192 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
193 #define IPTOS_NONE 0x00
194 #define IPTOS_LOWDELAY 0x10
195 #define IPTOS_THROUGHPUT 0x08
196 #define IPTOS_RELIABILITY 0x04
197 #define IPTOS_LOWCOST 0x02
199 #define IP_PROTO_ICMP 1
200 #define IP_PROTO_IGMP 2
201 #define IP_PROTO_TCP 6
202 #define IP_PROTO_UDP 17
203 #define IP_PROTO_OSPF 89
205 /* PPP structs and definitions */
207 typedef struct _e_ppphdr {
214 /* TCP structs and definitions */
216 typedef struct _e_tcphdr {
221 #if BYTE_ORDER == LITTLE_ENDIAN
240 /* UDP structs and definitions */
242 typedef struct _e_udphdr {
249 /* UDP Ports -> should go in packet-udp.h */
251 #define UDP_PORT_DNS 53
252 #define UDP_PORT_BOOTPS 67
253 #define UDP_PORT_IPX 213
254 #define UDP_PORT_RIP 520
258 #define TCP_PORT_PRINTER 515
260 /* Tree types. Each dissect_* routine should have one for each
261 add_subtree() call. */
263 #define ETT_IEEE8023 0
266 #define ETT_TOKEN_RING 3
267 #define ETT_TR_IERR_CNT 4
268 #define ETT_TR_NERR_CNT 5
281 #define ETT_DNS_ANS 18
282 #define ETT_DNS_QRY 19
284 #define ETT_RIP_VEC 21
286 #define ETT_OSPF_HDR 23
287 #define ETT_OSPF_HELLO 24
288 #define ETT_OSPF_DESC 25
289 #define ETT_OSPF_LSR 26
290 #define ETT_OSPF_LSA_UPD 27
291 #define ETT_OSPF_LSA 28
295 #define ETT_BOOTP_OPTION 32
302 /* Should be the last item number plus one */
303 #define NUM_TREE_TYPES 38
305 /* The version of pcap.h that comes with some systems is missing these
313 #ifndef DLT_SLIP_BSDOS
314 #define DLT_SLIP_BSDOS 13
317 #ifndef DLT_PPP_BSDOS
318 #define DLT_PPP_BSDOS 14
321 /* Utility routines used by packet*.c */
322 gchar* ether_to_str(guint8 *);
323 gchar* ip_to_str(guint8 *);
324 void packet_hex_print(GtkText *, guint8 *, gint, gint, gint);
325 GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...);
326 void decode_start_len(GtkTreeItem *, gint*, gint*);
328 /* Routines in packet.c */
329 void dissect_packet(const u_char *, frame_data *, GtkTree *);
330 void add_subtree(GtkWidget *, GtkWidget*, gint);
331 void expand_tree(GtkWidget *, gpointer);
332 void collapse_tree(GtkWidget *, gpointer);
335 * Routines in packet-*.c
336 * Routines should take three args: packet data *, frame_data *, tree *
337 * They should never modify the packet data.
339 void dissect_eth(const u_char *, frame_data *, GtkTree *);
340 void dissect_ppp(const u_char *, frame_data *, GtkTree *);
341 void dissect_raw(const u_char *, frame_data *, GtkTree *);
342 void dissect_tr(const u_char *, frame_data *, GtkTree *);
345 * Routines in packet-*.c
346 * Routines should take four args: packet data *, offset, frame_data *,
348 * They should never modify the packet data.
350 void dissect_arp(const u_char *, int, frame_data *, GtkTree *);
351 void dissect_bootp(const u_char *, int, frame_data *, GtkTree *);
352 void dissect_data(const u_char *, int, frame_data *, GtkTree *);
353 void dissect_dns(const u_char *, int, frame_data *, GtkTree *);
354 void dissect_icmp(const u_char *, int, frame_data *, GtkTree *);
355 void dissect_igmp(const u_char *, int, frame_data *, GtkTree *);
356 void dissect_ip(const u_char *, int, frame_data *, GtkTree *);
357 void dissect_ipv6(const u_char *, int, frame_data *, GtkTree *);
358 void dissect_ipx(const u_char *, int, frame_data *, GtkTree *);
359 void dissect_llc(const u_char *, int, frame_data *, GtkTree *);
360 void dissect_lpd(const u_char *, int, frame_data *, GtkTree *);
361 void dissect_osi(const u_char *, int, frame_data *, GtkTree *);
362 void dissect_ospf(const u_char *, int, frame_data *, GtkTree *);
363 void dissect_ospf_hello(const u_char *, int, frame_data *, GtkTree *);
364 void dissect_tcp(const u_char *, int, frame_data *, GtkTree *);
365 void dissect_trmac(const u_char *, int, frame_data *, GtkTree *);
366 void dissect_udp(const u_char *, int, frame_data *, GtkTree *);
367 void dissect_vines(const u_char *, int, frame_data *, GtkTree *);
368 void dissect_vspp(const u_char *, int, frame_data *, GtkTree *);
370 /* This function is in ethertype.c */
371 void ethertype(guint16 etype, int offset,
372 const u_char *pd, frame_data *fd, GtkTree *tree,
375 #endif /* packet.h */