3 * $Id: wtap-int.h,v 1.43 2004/01/05 17:33:28 ulfl Exp $
6 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
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.
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.
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.
23 #ifndef __WTAP_INT_H__
24 #define __WTAP_INT_H__
26 #ifdef HAVE_SYS_TIME_H
35 #ifdef HAVE_WINSOCK2_H
42 #endif /* HAVE_LIBZ */
46 /* Information for a compressed Sniffer data stream. */
48 unsigned char *buf; /* buffer into which we uncompress data */
49 size_t nbytes; /* number of bytes of data in that buffer */
50 int nextout; /* offset in that buffer of stream's current position */
51 long comp_offset; /* current offset in compressed data stream */
52 long uncomp_offset; /* current offset in uncompressed data stream */
53 } ngsniffer_comp_stream_t;
61 ngsniffer_comp_stream_t seq; /* sequential access */
62 ngsniffer_comp_stream_t rand; /* random access */
63 GList *first_blob; /* list element for first blob */
64 GList *last_blob; /* list element for last blob */
65 GList *current_blob; /* list element for current blob */
69 gboolean byte_swapped;
87 gboolean byte_swapped;
88 swapped_type_t lengths_swapped;
89 guint16 version_major;
90 guint16 version_minor;
98 guint32 frame_table_size;
105 double start_timestamp;
109 gboolean fcs_valid; /* if packets have valid FCS at the end */
110 guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */
116 long next_packet_seek_start;
120 gboolean byteswapped;
124 struct timeval reference_time;
133 typedef gboolean (*subtype_read_func)(struct wtap*, int*, long*);
134 typedef gboolean (*subtype_seek_read_func)(struct wtap*, long, union wtap_pseudo_header*,
135 guint8*, int, int *);
138 int fd; /* File descriptor for cap file */
139 FILE_T random_fh; /* Secondary FILE_T for random access */
142 struct Buffer *frame_buffer;
143 struct wtap_pkthdr phdr;
144 union wtap_pseudo_header pseudo_header;
150 lanalyzer_t *lanalyzer;
151 ngsniffer_t *ngsniffer;
152 i4btrace_t *i4btrace;
158 etherpeek_t *etherpeek;
163 subtype_read_func subtype_read;
164 subtype_seek_read_func subtype_seek_read;
165 void (*subtype_sequential_close)(struct wtap*);
166 void (*subtype_close)(struct wtap*);
167 int file_encap; /* per-file, for those
168 file formats that have
169 per-file encapsulation
175 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
176 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
177 const guchar*, int*);
178 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
181 gboolean first_frame;
186 gboolean first_frame;
187 struct timeval start;
192 gboolean got_first_record_time;
193 struct timeval first_record_time;
194 guint32 frame_table_offset;
195 guint32 *frame_table;
196 guint frame_table_index;
197 guint frame_table_size;
205 guint64 packet_count;
218 ngsniffer_dump_t *ngsniffer;
219 netmon_dump_t *netmon;
220 netxray_dump_t *netxray;
221 _5views_dump_t *_5views;
222 niobserver_dump_t *niobserver;
225 subtype_write_func subtype_write;
226 subtype_close_func subtype_close;
230 /* Macros to byte-swap 32-bit and 16-bit quantities. */
232 ((((x)&0xFF000000)>>24) | \
233 (((x)&0x00FF0000)>>8) | \
234 (((x)&0x0000FF00)<<8) | \
235 (((x)&0x000000FF)<<24))
237 ((((x)&0xFF00)>>8) | \
240 /* Turn host-byte-order values into little-endian values. */
241 #define htoles(s) GUINT16_TO_LE(s)
242 #define htolel(l) GUINT32_TO_LE(l)
244 #define htolell(ll) GUINT64_TO_LE(ll)
245 #endif /* G_HAVE_GINT64 */
247 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
248 * byte array, returns the value of the two or four bytes at the pointer.
249 * The pletoh[sl] versions return the little-endian representation.
251 * If G_HAVE_GINT64 is defined, so we can use "gint64" and "guint64" to
252 * refer to 64-bit integral quantities, we also provide pntohll and
253 * phtolell, which extract 64-bit integral quantities.
257 #define pntohs(p) ((guint16) \
258 ((guint16)*((const guint8 *)(p)+0)<<8| \
259 (guint16)*((const guint8 *)(p)+1)<<0))
263 #define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
264 (guint32)*((const guint8 *)(p)+1)<<8| \
265 (guint32)*((const guint8 *)(p)+2)<<0)
269 #define pntohl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
270 (guint32)*((const guint8 *)(p)+1)<<16| \
271 (guint32)*((const guint8 *)(p)+2)<<8| \
272 (guint32)*((const guint8 *)(p)+3)<<0)
277 #define pntohll(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
278 (guint64)*((const guint8 *)(p)+1)<<48| \
279 (guint64)*((const guint8 *)(p)+2)<<40| \
280 (guint64)*((const guint8 *)(p)+3)<<32| \
281 (guint64)*((const guint8 *)(p)+4)<<24| \
282 (guint64)*((const guint8 *)(p)+5)<<16| \
283 (guint64)*((const guint8 *)(p)+6)<<8| \
284 (guint64)*((const guint8 *)(p)+7)<<0)
290 #define phtons(p) ((guint16) \
291 ((guint16)*((const guint8 *)(p)+0)<<8| \
292 (guint16)*((const guint8 *)(p)+1)<<0))
296 #define phtonl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
297 (guint32)*((const guint8 *)(p)+1)<<16| \
298 (guint32)*((const guint8 *)(p)+2)<<8| \
299 (guint32)*((const guint8 *)(p)+3)<<0)
303 #define pletohs(p) ((guint16) \
304 ((guint16)*((const guint8 *)(p)+1)<<8| \
305 (guint16)*((const guint8 *)(p)+0)<<0))
309 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
310 (guint32)*((const guint8 *)(p)+1)<<8| \
311 (guint32)*((const guint8 *)(p)+0)<<0)
316 #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
317 (guint32)*((const guint8 *)(p)+2)<<16| \
318 (guint32)*((const guint8 *)(p)+1)<<8| \
319 (guint32)*((const guint8 *)(p)+0)<<0)
325 #define pletohll(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
326 (guint64)*((const guint8 *)(p)+6)<<48| \
327 (guint64)*((const guint8 *)(p)+5)<<40| \
328 (guint64)*((const guint8 *)(p)+4)<<32| \
329 (guint64)*((const guint8 *)(p)+3)<<24| \
330 (guint64)*((const guint8 *)(p)+2)<<16| \
331 (guint64)*((const guint8 *)(p)+1)<<8| \
332 (guint64)*((const guint8 *)(p)+0)<<0)
336 #define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \
340 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
341 if (_bytes_read != (int) (num_bytes)) { \
342 *(err) = file_error((fh)); \
348 #define wtap_file_read_expected_bytes(target, num_bytes, fh, err) \
352 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
353 if (_bytes_read != (int) (num_bytes)) { \
354 *(err) = file_error((fh)); \
355 if (*(err) == 0 && _bytes_read > 0) { \
356 *(err) = WTAP_ERR_SHORT_READ; \
363 /* glib doesn't have g_ptr_array_len of all things!*/
364 #ifndef g_ptr_array_len
365 #define g_ptr_array_len(a) ((a)->len)
368 #endif /* __WTAP_INT_H__ */