Move #include <time.h> into wtap-int.h instead of requiring it in
[obnox/wireshark/wip.git] / wiretap / wtap-int.h
1 /* wtap-int.h
2  *
3  * $Id: wtap-int.h,v 1.7 2000/08/25 21:25:43 gram Exp $
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
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_INT_H__
25 #define __WTAP_INT_H__
26
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
29 #endif
30
31 #ifdef HAVE_SYS_TIME_H
32 #include <sys/time.h>
33 #endif
34
35 #ifdef HAVE_WINSOCK_H
36 #include <winsock.h>
37 #endif
38
39 #include <glib.h>
40 #include <stdio.h>
41 #include <time.h>
42
43 #ifdef HAVE_LIBZ
44 #include "zlib.h"
45 #define FILE_T  gzFile
46 #else /* No zLib */
47 #define FILE_T  FILE *
48 #endif /* HAVE_LIBZ */
49
50 #include "wtap.h"
51
52 /* Information for a compressed Sniffer data stream. */
53 typedef struct {
54         unsigned char *buf;     /* buffer into which we uncompress data */
55         size_t  nbytes;         /* number of bytes of data in that buffer */
56         int     nextout;        /* offset in that buffer of stream's current position */
57         long    comp_offset;    /* current offset in compressed data stream */
58         long    uncomp_offset;  /* current offset in uncompressed data stream */
59 } ngsniffer_comp_stream_t;
60
61 typedef struct {
62         double  timeunit;
63         time_t  start;
64         int     is_atm;
65         ngsniffer_comp_stream_t seq;    /* sequential access */
66         ngsniffer_comp_stream_t rand;   /* random access */
67         GList   *first_blob;            /* list element for first blob */
68         GList   *last_blob;             /* list element for last blob */
69         GList   *current_blob;          /* list element for current blob */
70 } ngsniffer_t;
71
72 typedef struct {
73         gboolean byte_swapped;
74         int bchannel_prot[2];   /* For the V.120 heuristic */
75 } i4btrace_t;
76
77 typedef struct {
78         gboolean is_hpux_11;
79 } nettl_t;
80
81 typedef struct {
82         time_t  start;
83 } lanalyzer_t;
84
85 typedef struct {
86         gboolean byte_swapped;
87         guint16 version_major;
88         guint16 version_minor;
89 } libpcap_t;
90
91 typedef struct {
92         time_t  start_secs;
93         guint32 start_usecs;
94         guint8  version_major;
95         guint32 *frame_table;
96         int     frame_table_size;
97         int     current_frame;
98 } netmon_t;
99
100 typedef struct {
101         time_t  start_time;
102         double  timeunit;
103         double  start_timestamp;
104         int     wrapped;
105         int     end_offset;
106         int     version_major;
107 } netxray_t;
108
109 typedef struct {
110         time_t inittime;
111         int adjusted;
112         int seek_add;
113 } ascend_t;
114
115 typedef struct {
116         gboolean byteswapped;
117 } csids_t;
118
119 typedef int (*subtype_read_func)(struct wtap*, int*);
120 typedef int (*subtype_seek_read_func)(struct wtap*, int, union wtap_pseudo_header*,
121                                         guint8*, int);
122 struct wtap {
123         FILE_T                  fh;
124         int                     fd;           /* File descriptor for cap file */
125         FILE_T                  random_fh;    /* Secondary FILE_T for random access */
126         int                     file_type;
127         int                     snapshot_length;
128         struct Buffer           *frame_buffer;
129         struct wtap_pkthdr      phdr;
130         union wtap_pseudo_header pseudo_header;
131
132         long                    data_offset;
133
134         union {
135                 libpcap_t               *pcap;
136                 lanalyzer_t             *lanalyzer;
137                 ngsniffer_t             *ngsniffer;
138                 i4btrace_t              *i4btrace;
139                 nettl_t                 *nettl;
140                 netmon_t                *netmon;
141                 netxray_t               *netxray;
142                 ascend_t                *ascend;
143                 csids_t                 *csids;
144         } capture;
145
146         subtype_read_func       subtype_read;
147         subtype_seek_read_func  subtype_seek_read;
148         void                    (*subtype_sequential_close)(struct wtap*);
149         void                    (*subtype_close)(struct wtap*);
150         int                     file_encap;     /* per-file, for those
151                                                    file formats that have
152                                                    per-file encapsulation
153                                                    types */
154 };
155
156 struct wtap_dumper;
157
158 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
159                 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
160                 const u_char*, int*);
161 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
162
163 typedef struct {
164         gboolean first_frame;
165         time_t start;
166 } ngsniffer_dump_t;
167
168 typedef struct {
169         gboolean first_frame;
170         struct timeval start;
171         guint32 nframes;
172 } netxray_dump_t;
173
174 typedef struct {
175         gboolean got_first_record_time;
176         struct timeval first_record_time;
177         guint32 frame_table_offset;
178         guint32 *frame_table;
179         int     frame_table_index;
180         int     frame_table_size;
181 } netmon_dump_t;
182
183 struct wtap_dumper {
184         FILE*                   fh;
185         int                     file_type;
186         int                     snaplen;
187         int                     encap;
188
189         union {
190                 void                    *opaque;
191                 ngsniffer_dump_t        *ngsniffer;
192                 netmon_dump_t           *netmon;
193                 netxray_dump_t          *netxray;
194         } dump;
195
196         subtype_write_func      subtype_write;
197         subtype_close_func      subtype_close;
198 };
199
200
201 /* Macros to byte-swap 32-bit and 16-bit quantities. */
202 #define BSWAP32(x) \
203         ((((x)&0xFF000000)>>24) | \
204          (((x)&0x00FF0000)>>8) | \
205          (((x)&0x0000FF00)<<8) | \
206          (((x)&0x000000FF)<<24))
207 #define BSWAP16(x) \
208          ((((x)&0xFF00)>>8) | \
209           (((x)&0x00FF)<<8))
210
211 /* Turn host-byte-order values into little-endian values. */
212 #ifdef WORDS_BIGENDIAN
213 #define htoles(s) ((guint16)                       \
214                     ((guint16)((s) & 0x00FF)<<8|  \
215                      (guint16)((s) & 0xFF00)>>8))
216
217 #define htolel(l) ((guint32)((l) & 0x000000FF)<<24|  \
218                    (guint32)((l) & 0x0000FF00)<<8|  \
219                    (guint32)((l) & 0x00FF0000)>>8|   \
220                    (guint32)((l) & 0xFF000000)>>24)
221 #else
222 #define htoles(s)       (s)
223 #define htolel(l)       (l)
224 #endif
225
226 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
227  * byte array, returns the value of the two or four bytes at the pointer.
228  * The pletoh[sl] versions return the little-endian representation.
229  */
230
231 #ifndef pntohs
232 #define pntohs(p)  ((guint16)                       \
233                     ((guint16)*((guint8 *)p+0)<<8|  \
234                      (guint16)*((guint8 *)p+1)<<0))
235 #endif
236
237 #ifndef pntohl
238 #define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
239                     (guint32)*((guint8 *)p+1)<<16|  \
240                     (guint32)*((guint8 *)p+2)<<8|   \
241                     (guint32)*((guint8 *)p+3)<<0)
242 #endif
243
244 #ifndef phtons
245 #define phtons(p)  ((guint16)                       \
246                     ((guint16)*((guint8 *)p+0)<<8|  \
247                      (guint16)*((guint8 *)p+1)<<0))
248 #endif
249
250 #ifndef phtonl
251 #define phtonl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
252                     (guint32)*((guint8 *)p+1)<<16|  \
253                     (guint32)*((guint8 *)p+2)<<8|   \
254                     (guint32)*((guint8 *)p+3)<<0)
255 #endif
256
257 #ifndef pletohs
258 #define pletohs(p) ((guint16)                       \
259                     ((guint16)*((guint8 *)p+1)<<8|  \
260                      (guint16)*((guint8 *)p+0)<<0))
261 #endif
262
263 #ifndef pletohl
264 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
265                     (guint32)*((guint8 *)p+2)<<16|  \
266                     (guint32)*((guint8 *)p+1)<<8|   \
267                     (guint32)*((guint8 *)p+0)<<0)
268 #endif
269
270 #endif /* __WTAP_INT_H__ */