Un-comment "AC_CONFIG_SUBDIRS()", so that it'll run "configure" in the
[obnox/wireshark/wip.git] / packet.h
1 /* packet.h
2  * Definitions for packet disassembly structures and routines
3  *
4  * $Id: packet.h,v 1.23 1998/11/03 07:45:10 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 /* 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.
33  */
34
35 #define pntohs(p)  ((guint16)                       \
36                     ((guint16)*((guint8 *)p+0)<<8|  \
37                      (guint16)*((guint8 *)p+1)<<0))
38
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)
43
44 #define pletohs(p) ((guint16)                       \
45                     ((guint16)*((guint8 *)p+1)<<8|  \
46                      (guint16)*((guint8 *)p+0)<<0))
47
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)
52
53
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.
57  */
58 #define END_OF_FRAME    (fd->cap_len - offset)
59
60 #define IEEE_802_3_MAX_LEN 1500
61 #define BYTE_VIEW_WIDTH    16
62
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 */
70 } frame_data;
71
72 typedef struct _packet_info {
73   char *srcip;
74   int ip_src;
75   char *destip;
76   int ipproto;
77   int srcport;
78   int destport;
79   int iplen;
80   int iphdrlen;
81 } packet_info;
82
83 /* Struct for the match_strval function */
84
85 typedef struct _value_string {
86   guint32  value;
87   gchar   *strptr;
88 } value_string;
89
90 /* Many of the structs and definitions below were taken from include files
91  * in the Linux distribution. */
92
93 /* ARP / RARP structs and definitions */
94
95 #ifndef ARPOP_REQUEST
96 #define ARPOP_REQUEST  1       /* ARP request.  */
97 #endif
98 #ifndef ARPOP_REPLY
99 #define ARPOP_REPLY    2       /* ARP reply.  */
100 #endif
101 /* Some OSes have different names, or don't define these at all */
102 #ifndef ARPOP_RREQUEST
103 #define ARPOP_RREQUEST 3       /* RARP request.  */
104 #endif
105 #ifndef ARPOP_RREPLY
106 #define ARPOP_RREPLY   4       /* RARP reply.  */
107 #endif
108
109 /* ICMP structs and definitions */
110
111 typedef struct _e_icmp {
112   guint8  icmp_type;
113   guint8  icmp_code;
114   guint16 icmp_cksum;
115   union {
116     struct {  /* Address mask request/reply */
117       guint16 id;
118       guint16 seq;
119       guint32 sn_mask;
120     } am;
121     struct {  /* Timestap request/reply */
122       guint16 id;
123       guint16 seq;
124       guint32 orig;
125       guint32 recv;
126       guint32 xmit;
127     } ts;
128     guint32 zero;  /* Unreachable */
129   } opt;
130 } e_icmp;
131
132 #define ICMP_ECHOREPLY     0
133 #define ICMP_UNREACH       3
134 #define ICMP_SOURCEQUENCH  4
135 #define ICMP_REDIRECT      5
136 #define ICMP_ECHO          8
137 #define ICMP_TIMXCEED     11
138 #define ICMP_PARAMPROB    12
139 #define ICMP_TSTAMP       13
140 #define ICMP_TSTAMPREPLY  14
141 #define ICMP_IREQ         15
142 #define ICMP_IREQREPLY    16
143 #define ICMP_MASKREQ      17
144 #define ICMP_MASKREPLY    18
145
146 /* IGMP structs and definitions */
147
148 typedef struct _e_igmp {
149 #if BYTE_ORDER == BIG_ENDIAN
150   guint8  igmp_v:4;
151   guint8  igmp_t:4;
152 #else /* Little endian */
153   guint8  igmp_t:4;
154   guint8  igmp_v:4;
155 #endif
156   guint8  igmp_unused;
157   guint16 igmp_cksum;
158   guint32 igmp_gaddr;
159 } e_igmp;
160
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
169
170 /* IP structs and definitions */
171
172 typedef struct _e_ip {
173 #if BYTE_ORDER == BIG_ENDIAN
174   guint8  ip_v:4;
175   guint8  ip_hl:4;
176 #else /* Little endian */
177   guint8  ip_hl:4;
178   guint8  ip_v:4;
179 #endif
180   guint8  ip_tos;
181   guint16 ip_len;
182   guint16 ip_id;
183   guint16 ip_off;
184   guint8  ip_ttl;
185   guint8  ip_p;
186   guint16 ip_sum;
187   guint32 ip_src;
188   guint32 ip_dst;
189 } e_ip;
190
191 /* IP flags. */
192 #define IP_CE           0x8000          /* Flag: "Congestion"           */
193 #define IP_DF           0x4000          /* Flag: "Don't Fragment"       */
194 #define IP_MF           0x2000          /* Flag: "More Fragments"       */
195 #define IP_OFFSET       0x1FFF          /* "Fragment Offset" part       */
196
197 #define IPTOS_TOS_MASK    0x1E
198 #define IPTOS_TOS(tos)    ((tos) & IPTOS_TOS_MASK)
199 #define IPTOS_NONE        0x00
200 #define IPTOS_LOWCOST     0x02
201 #define IPTOS_RELIABILITY 0x04
202 #define IPTOS_THROUGHPUT  0x08
203 #define IPTOS_LOWDELAY    0x10
204 #define IPTOS_SECURITY    0x1E
205
206 #define IPTOS_PREC_MASK         0xE0
207 #define IPTOS_PREC(tos)         ((tos)&IPTOS_PREC_MASK)
208 #define IPTOS_PREC_NETCONTROL           0xe0
209 #define IPTOS_PREC_INTERNETCONTROL      0xc0
210 #define IPTOS_PREC_CRITIC_ECP           0xa0
211 #define IPTOS_PREC_FLASHOVERRIDE        0x80
212 #define IPTOS_PREC_FLASH                0x60
213 #define IPTOS_PREC_IMMEDIATE            0x40
214 #define IPTOS_PREC_PRIORITY             0x20
215 #define IPTOS_PREC_ROUTINE              0x00
216
217 /* IP options */
218 #define IPOPT_COPY              0x80
219
220 #define IPOPT_CONTROL           0x00
221 #define IPOPT_RESERVED1         0x20
222 #define IPOPT_MEASUREMENT       0x40
223 #define IPOPT_RESERVED2         0x60
224
225 #define IPOPT_END       (0 |IPOPT_CONTROL)
226 #define IPOPT_NOOP      (1 |IPOPT_CONTROL)
227 #define IPOPT_SEC       (2 |IPOPT_CONTROL|IPOPT_COPY)
228 #define IPOPT_LSRR      (3 |IPOPT_CONTROL|IPOPT_COPY)
229 #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT)
230 #define IPOPT_RR        (7 |IPOPT_CONTROL)
231 #define IPOPT_SID       (8 |IPOPT_CONTROL|IPOPT_COPY)
232 #define IPOPT_SSRR      (9 |IPOPT_CONTROL|IPOPT_COPY)
233 #define IPOPT_RA        (20|IPOPT_CONTROL|IPOPT_COPY)
234
235 /* IP option lengths */
236 #define IPOLEN_SEC      11
237 #define IPOLEN_LSRR_MIN 3
238 #define IPOLEN_TIMESTAMP_MIN 5
239 #define IPOLEN_RR_MIN   3
240 #define IPOLEN_SID      4
241 #define IPOLEN_SSRR_MIN 3
242
243 #define IPSEC_UNCLASSIFIED      0x0000
244 #define IPSEC_CONFIDENTIAL      0xF135
245 #define IPSEC_EFTO              0x789A
246 #define IPSEC_MMMM              0xBC4D
247 #define IPSEC_RESTRICTED        0xAF13
248 #define IPSEC_SECRET            0xD788
249 #define IPSEC_TOPSECRET         0x6BC5
250 #define IPSEC_RESERVED1         0x35E2
251 #define IPSEC_RESERVED2         0x9AF1
252 #define IPSEC_RESERVED3         0x4D78
253 #define IPSEC_RESERVED4         0x24BD
254 #define IPSEC_RESERVED5         0x135E
255 #define IPSEC_RESERVED6         0x89AF
256 #define IPSEC_RESERVED7         0xC4D6
257 #define IPSEC_RESERVED8         0xE26B
258
259 #define IPOPT_TS_TSONLY         0               /* timestamps only */
260 #define IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
261 #define IPOPT_TS_PRESPEC        3               /* specified modules only */
262
263 #define IP_PROTO_ICMP  1
264 #define IP_PROTO_IGMP  2
265 #define IP_PROTO_TCP   6
266 #define IP_PROTO_UDP  17
267 #define IP_PROTO_OSPF 89
268
269 /* Null/loopback structs and definitions */
270
271 typedef struct _e_nullhdr {
272   guint8  null_next;
273   guint8  null_len;
274   guint16 null_family;
275 } e_nullhdr;
276
277 /* PPP structs and definitions */
278
279 typedef struct _e_ppphdr {
280   guint8  ppp_addr;
281   guint8  ppp_ctl;
282   guint16 ppp_prot;
283 } e_ppphdr;
284
285 /* TCP structs and definitions */
286
287 typedef struct _e_tcphdr {
288   guint16 th_sport;
289   guint16 th_dport;
290   guint32 th_seq;
291   guint32 th_ack;
292 #if BYTE_ORDER == LITTLE_ENDIAN
293   guint8  th_x2:4;
294   guint8  th_off:4;
295 #else
296   guint8  th_off:4;
297   guint8  th_x2:4;
298 #endif
299   guint8  th_flags;
300 #define TH_FIN  0x01
301 #define TH_SYN  0x02
302 #define TH_RST  0x04
303 #define TH_PUSH 0x08
304 #define TH_ACK  0x10
305 #define TH_URG  0x20
306   guint16 th_win;
307   guint16 th_sum;
308   guint16 th_urp;
309 } e_tcphdr;
310
311 /*
312  *      TCP option
313  */
314  
315 #define TCPOPT_NOP              1       /* Padding */
316 #define TCPOPT_EOL              0       /* End of options */
317 #define TCPOPT_MSS              2       /* Segment size negotiating */
318 #define TCPOPT_WINDOW           3       /* Window scaling */
319 #define TCPOPT_SACK_PERM        4       /* SACK Permitted */
320 #define TCPOPT_SACK             5       /* SACK Block */
321 #define TCPOPT_ECHO             6
322 #define TCPOPT_ECHOREPLY        7
323 #define TCPOPT_TIMESTAMP        8       /* Better RTT estimations/PAWS */
324 #define TCPOPT_CC               11
325 #define TCPOPT_CCNEW            12
326 #define TCPOPT_CCECHO           13
327
328 /*
329  *     TCP option lengths
330  */
331
332 #define TCPOLEN_MSS            4
333 #define TCPOLEN_WINDOW         3
334 #define TCPOLEN_SACK_PERM      2
335 #define TCPOLEN_SACK_MIN       2
336 #define TCPOLEN_ECHO           6
337 #define TCPOLEN_ECHOREPLY      6
338 #define TCPOLEN_TIMESTAMP      10
339 #define TCPOLEN_CC             6
340 #define TCPOLEN_CCNEW          6
341 #define TCPOLEN_CCECHO         6
342
343 /* UDP structs and definitions */
344
345 typedef struct _e_udphdr {
346   guint16 uh_sport;
347   guint16 uh_dport;
348   guint16 uh_ulen;
349   guint16 uh_sum;
350 } e_udphdr;
351
352 /* UDP Ports -> should go in packet-udp.h */
353
354 #define UDP_PORT_DNS     53
355 #define UDP_PORT_BOOTPS  67
356 #define UDP_PORT_IPX    213
357 #define UDP_PORT_NBNS   137
358 #define UDP_PORT_RIP    520
359
360 /* TCP Ports */
361
362 #define TCP_PORT_PRINTER 515
363
364 /* Tree types.  Each dissect_* routine should have one for each
365    add_subtree() call. */
366
367 enum {
368         ETT_FRAME,
369         ETT_IEEE8023,
370         ETT_ETHER2,
371         ETT_LLC,
372         ETT_TOKEN_RING,
373         ETT_TR_IERR_CNT,
374         ETT_TR_NERR_CNT,
375         ETT_TR_MAC,
376         ETT_PPP,
377         ETT_ARP,
378         ETT_FDDI,
379         ETT_NULL,
380         ETT_IP,
381         ETT_IP_OPTIONS,
382         ETT_IP_OPTION_SEC,
383         ETT_IP_OPTION_ROUTE,
384         ETT_IP_OPTION_TIMESTAMP,
385         ETT_UDP,
386         ETT_TCP,
387         ETT_TCP_OPTIONS,
388         ETT_TCP_OPTION_SACK,
389         ETT_ICMP,
390         ETT_IGMP,
391         ETT_IPX,
392         ETT_SPX,
393         ETT_NCP,
394         ETT_DNS,
395         ETT_DNS_QRY,
396         ETT_DNS_QD,
397         ETT_DNS_ANS,
398         ETT_DNS_RR,
399         ETT_RIP,
400         ETT_RIP_VEC,
401         ETT_OSPF,
402         ETT_OSPF_HDR,
403         ETT_OSPF_HELLO,
404         ETT_OSPF_DESC,
405         ETT_OSPF_LSR,
406         ETT_OSPF_LSA_UPD,
407         ETT_OSPF_LSA,
408         ETT_LPD,
409         ETT_RAW,
410         ETT_BOOTP,
411         ETT_BOOTP_OPTION,
412         ETT_IPv6,
413         ETT_CLNP,
414         ETT_COTP,
415         ETT_VINES,
416         ETT_VSPP,
417         ETT_IPXRIP,
418         ETT_IPXSAP,
419         ETT_IPXSAP_SERVER,
420         ETT_NBNS,
421         ETT_NBNS_QRY,
422         ETT_NBNS_QD,
423         ETT_NBNS_ANS,
424         ETT_NBNS_RR,
425         ETT_NBIPX,
426         ETT_AARP,
427         NUM_TREE_TYPES  /* last item number plus one */
428 };
429
430 /* The version of pcap.h that comes with some systems is missing these
431  * #defines.
432  */
433
434 #ifndef DLT_RAW
435 #define DLT_RAW 12
436 #endif
437
438 #ifndef DLT_SLIP_BSDOS
439 #define DLT_SLIP_BSDOS 13
440 #endif
441
442 #ifndef DLT_PPP_BSDOS
443 #define DLT_PPP_BSDOS 14
444 #endif
445
446 typedef enum {
447   NO_LENGTH,            /* option has no data, hence no length */
448   FIXED_LENGTH,         /* option always has the same length */
449   VARIABLE_LENGTH       /* option is variable-length - optlen is minimum */
450 } opt_len_type;
451
452 /* Member of table of IP or TCP options. */
453 typedef struct {
454   int   optcode;        /* code for option */
455   char *name;           /* name of option */
456   opt_len_type len_type; /* type of option length field */
457   int   optlen;         /* value length should be (minimum if VARIABLE) */
458   void  (*dissect)(GtkWidget *, const char *, const u_char *, int, guint);
459                         /* routine to dissect option */
460 } ip_tcp_opt;
461
462 /* Routine to dissect IP or TCP options. */
463 void       dissect_ip_tcp_options(GtkWidget *, const u_char *, int, guint,
464     ip_tcp_opt *, int, int);
465
466 /* Utility routines used by packet*.c */
467 gchar*     ether_to_str(guint8 *);
468 gchar*     ip_to_str(guint8 *);
469 void       packet_hex_print(GtkText *, guint8 *, gint, gint, gint);
470 #define E_TREEINFO_START_KEY "tree_info_start"
471 #define E_TREEINFO_LEN_KEY   "tree_info_len"
472 #if __GNUC__ == 2
473 GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...)
474     __attribute__((format (printf, 4, 5)));
475 #else
476 GtkWidget* add_item_to_tree(GtkWidget *, gint, gint, gchar *, ...);
477 #endif
478 gchar*     val_to_str(guint32, const value_string *, const char *);
479 gchar*     match_strval(guint32, const value_string*);
480
481 /* Routines in packet.c */
482
483 void dissect_packet(const u_char *, guint32 ts_secs, guint32 ts_usecs,
484   frame_data *, GtkTree *);
485 void add_subtree(GtkWidget *, GtkWidget*, gint);
486 void expand_tree(GtkWidget *, gpointer);
487 void collapse_tree(GtkWidget *, gpointer);
488
489 /*
490  * Routines in packet-*.c
491  * Routines should take three args: packet data *, frame_data *, tree *
492  * They should never modify the packet data.
493  */
494 void dissect_eth(const u_char *, frame_data *, GtkTree *);
495 void dissect_fddi(const u_char *, frame_data *, GtkTree *);
496 void dissect_null(const u_char *, frame_data *, GtkTree *);
497 void dissect_ppp(const u_char *, frame_data *, GtkTree *);
498 void dissect_raw(const u_char *, frame_data *, GtkTree *);
499 void dissect_tr(const u_char *, frame_data *, GtkTree *);
500
501 /*
502  * Routines in packet-*.c
503  * Routines should take four args: packet data *, offset, frame_data *,
504  * tree *
505  * They should never modify the packet data.
506  */
507 void dissect_aarp(const u_char *, int, frame_data *, GtkTree *);
508 void dissect_arp(const u_char *, int, frame_data *, GtkTree *);
509 void dissect_bootp(const u_char *, int, frame_data *, GtkTree *);
510 void dissect_data(const u_char *, int, frame_data *, GtkTree *);
511 void dissect_ddp(const u_char *, int, frame_data *, GtkTree *);
512 void dissect_dns(const u_char *, int, frame_data *, GtkTree *);
513 void dissect_icmp(const u_char *, int, frame_data *, GtkTree *);
514 void dissect_igmp(const u_char *, int, frame_data *, GtkTree *);
515 void dissect_ip(const u_char *, int, frame_data *, GtkTree *);
516 void dissect_ipv6(const u_char *, int, frame_data *, GtkTree *);
517 void dissect_ipx(const u_char *, int, frame_data *, GtkTree *);
518 void dissect_llc(const u_char *, int, frame_data *, GtkTree *);
519 void dissect_lpd(const u_char *, int, frame_data *, GtkTree *);
520 void dissect_nbipx_ns(const u_char *, int, frame_data *, GtkTree *);
521 void dissect_nbns(const u_char *, int, frame_data *, GtkTree *);
522 void dissect_ncp(const u_char *, int, frame_data *, GtkTree *);
523 void dissect_nwlink_dg(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 *);
533
534 /* These functions are in ethertype.c */
535 gchar *ethertype_to_str(guint16 etype, const char *fmt);
536 void ethertype(guint16 etype, int offset,
537                 const u_char *pd, frame_data *fd, GtkTree *tree,
538                 GtkWidget *fh_tree);
539
540 #endif /* packet.h */