Created a new protocol tree implementation and a new display filter
[metze/wireshark/wip.git] / wiretap / wtap.h
1 /* wtap.h
2  *
3  * $Id: wtap.h,v 1.19 1999/07/07 22:52:57 gram Exp $
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
7  * 
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23
24 #ifndef __WTAP_H__
25 #define __WTAP_H__
26
27 /* Encapsulation types. Choose names that truly reflect
28  * what is contained in the packet trace file. */
29 #define WTAP_ENCAP_NONE                         0
30 #define WTAP_ENCAP_ETHERNET                     1
31 #define WTAP_ENCAP_TR                           2
32 #define WTAP_ENCAP_SLIP                         3
33 #define WTAP_ENCAP_PPP                          4
34 #define WTAP_ENCAP_FDDI                         5
35 #define WTAP_ENCAP_RAW_IP                       6
36 #define WTAP_ENCAP_ARCNET                       7
37 #define WTAP_ENCAP_ATM_RFC1483                  8
38
39 /* last WTAP_ENCAP_ value + 1 */
40 #define WTAP_NUM_ENCAP_TYPES                    9
41
42 /* File types that can be read by wiretap */
43 #define WTAP_FILE_UNKNOWN                       0
44 #define WTAP_FILE_WTAP                          1
45 #define WTAP_FILE_PCAP                          2
46 #define WTAP_FILE_LANALYZER                     3
47 #define WTAP_FILE_NGSNIFFER                     4
48 #define WTAP_FILE_SNOOP                         6
49 #define WTAP_FILE_IPTRACE                       7
50 #define WTAP_FILE_NETMON                        8
51 #define WTAP_FILE_NETXRAY                       9
52
53 /* Filter types that wiretap can create. An 'offline' filter is really
54  * a BPF filter, but it is treated specially because wiretap might not know
55  * in advance the datalink type(s) needed.
56  */
57 #define WTAP_FILTER_NONE                        0
58 #define WTAP_FILTER_OFFLINE                     1
59 #define WTAP_FILTER_BPF                         2
60
61 #include <sys/types.h>
62 #include <sys/time.h>
63 #include <glib.h>
64 #include <stdio.h>
65
66 typedef struct {
67         double  timeunit;
68         time_t  start;
69         guint16 pkt_len;
70         guint16 size;
71         guint16 true_size;
72         double  t;
73         int     is_atm;
74 } ngsniffer_t;
75
76 typedef struct {
77         guint16 pkt_len;
78         guint32 totpktt;
79         time_t  start;
80 } lanalyzer_t;
81
82 typedef struct {
83         int     byte_swapped;
84         guint16 version_major;
85         guint16 version_minor;
86 } libpcap_t;
87
88 typedef struct {
89         time_t  start_secs;
90         guint32 start_usecs;
91         guint8  version_major;
92         int     end_offset;
93 } netmon_t;
94
95 typedef struct {
96         time_t  start_time;
97         double  timeunit;
98         double  start_timestamp;
99         int     wrapped;
100         int     end_offset;
101         int     version_major;
102 } netxray_t;
103
104 struct wtap_pkthdr {
105         struct timeval ts;
106         guint32 caplen;
107         guint32 len;
108         int pkt_encap;
109 };
110
111 typedef void (*wtap_handler)(u_char*, const struct wtap_pkthdr*,
112                 int, const u_char *);
113
114 struct wtap;
115 struct bpf_instruction;
116 struct Buffer;
117
118 typedef int (*subtype_func)(struct wtap*);
119 typedef struct wtap {
120         FILE*                   fh;
121         int                     file_type;
122         int                     snapshot_length;
123         struct Buffer           *frame_buffer;
124         struct wtap_pkthdr      phdr;
125
126         union {
127                 libpcap_t               *pcap;
128                 lanalyzer_t             *lanalyzer;
129                 ngsniffer_t             *ngsniffer;
130                 netmon_t                *netmon;
131                 netxray_t               *netxray;
132         } capture;
133
134         subtype_func            subtype_read;
135         int                     file_encap;     /* per-file, for those
136                                                    file formats that have
137                                                    per-file encapsulation
138                                                    types */
139 } wtap;
140
141
142 wtap* wtap_open_offline(char *filename);
143 void wtap_loop(wtap *wth, int, wtap_handler, u_char*);
144
145 FILE* wtap_file(wtap *wth);
146 int wtap_snapshot_length(wtap *wth); /* per file */
147 int wtap_file_type(wtap *wth);
148 void wtap_close(wtap *wth);
149
150
151 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
152  * byte array, returns the value of the two or four bytes at the pointer.
153  * The pletoh[sl] versions return the little-endian representation.
154  */
155
156 #ifndef pntohs
157 #define pntohs(p)  ((guint16)                       \
158                     ((guint16)*((guint8 *)p+0)<<8|  \
159                      (guint16)*((guint8 *)p+1)<<0))
160 #endif
161
162 #ifndef pntohl
163 #define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
164                     (guint32)*((guint8 *)p+1)<<16|  \
165                     (guint32)*((guint8 *)p+2)<<8|   \
166                     (guint32)*((guint8 *)p+3)<<0)
167 #endif
168
169 #ifndef phtons
170 #define phtons(p)  ((guint16)                       \
171                     ((guint16)*((guint8 *)p+0)<<8|  \
172                      (guint16)*((guint8 *)p+1)<<0))
173 #endif
174
175 #ifndef phtonl
176 #define phtonl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
177                     (guint32)*((guint8 *)p+1)<<16|  \
178                     (guint32)*((guint8 *)p+2)<<8|   \
179                     (guint32)*((guint8 *)p+3)<<0)
180 #endif
181
182 #ifndef pletohs
183 #define pletohs(p) ((guint16)                       \
184                     ((guint16)*((guint8 *)p+1)<<8|  \
185                      (guint16)*((guint8 *)p+0)<<0))
186 #endif
187
188 #ifndef plethol
189 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
190                     (guint32)*((guint8 *)p+2)<<16|  \
191                     (guint32)*((guint8 *)p+1)<<8|   \
192                     (guint32)*((guint8 *)p+0)<<0)
193 #endif
194
195 #endif /* __WTAP_H__ */