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
34 #ifdef HAVE_WINSOCK2_H
43 #endif /* HAVE_LIBZ */
47 /* Information for a compressed Sniffer data stream. */
49 unsigned char *buf; /* buffer into which we uncompress data */
50 size_t nbytes; /* number of bytes of data in that buffer */
51 int nextout; /* offset in that buffer of stream's current position */
52 gint64 comp_offset; /* current offset in compressed data stream */
53 gint64 uncomp_offset; /* current offset in uncompressed data stream */
54 } ngsniffer_comp_stream_t;
57 char *sdate; /* Packet start date */
58 gboolean tcp_formatted; /* TCP/IP data formated Y/N */
59 int format; /* Trace format type */
67 guint network; /* network type */
68 ngsniffer_comp_stream_t seq; /* sequential access */
69 ngsniffer_comp_stream_t rand; /* random access */
70 GList *first_blob; /* list element for first blob */
71 GList *last_blob; /* list element for last blob */
72 GList *current_blob; /* list element for current blob */
76 gboolean byte_swapped;
94 gboolean byte_swapped;
95 swapped_type_t lengths_swapped;
96 guint16 version_major;
97 guint16 version_minor;
101 gboolean byte_swapped;
102 guint16 version_major;
103 guint16 version_minor;
110 guint8 version_major;
111 guint32 *frame_table;
112 guint32 frame_table_size;
118 double ticks_per_sec;
119 double start_timestamp;
125 gboolean fcs_valid; /* if packets have valid FCS at the end */
126 guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */
132 gint64 next_packet_seek_start;
136 gboolean byteswapped;
140 struct timeval reference_time;
147 typedef struct _k12_t k12_t;
152 } catapult_dct2000_t;
155 struct wtap_nstime now;
159 typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
160 typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, union wtap_pseudo_header*,
161 guint8*, int, int *, char **);
164 int fd; /* File descriptor for cap file */
165 FILE_T random_fh; /* Secondary FILE_T for random access */
168 struct Buffer *frame_buffer;
169 struct wtap_pkthdr phdr;
170 union wtap_pseudo_header pseudo_header;
176 lanalyzer_t *lanalyzer;
177 ngsniffer_t *ngsniffer;
179 i4btrace_t *i4btrace;
185 etherpeek_t *etherpeek;
186 airopeek9_t *airopeek9;
188 catapult_dct2000_t *catapult_dct2000;
194 subtype_read_func subtype_read;
195 subtype_seek_read_func subtype_seek_read;
196 void (*subtype_sequential_close)(struct wtap*);
197 void (*subtype_close)(struct wtap*);
198 int file_encap; /* per-file, for those
199 file formats that have
200 per-file encapsulation
202 int tsprecision; /* timestamp precision of the lower 32bits
203 * e.g. WTAP_FILE_TSPREC_USEC */
208 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
209 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
210 const guchar*, int*);
211 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
214 gboolean first_frame;
219 gboolean first_frame;
220 struct wtap_nstime start;
225 gboolean got_first_record_time;
226 struct wtap_nstime first_record_time;
227 guint32 frame_table_offset;
228 guint32 *frame_table;
229 guint frame_table_index;
230 guint frame_table_size;
238 guint64 packet_count;
244 guint32 num_of_records;
249 gboolean first_packet_written;
250 struct wtap_nstime start_time;
263 ngsniffer_dump_t *ngsniffer;
264 netmon_dump_t *netmon;
265 netxray_dump_t *netxray;
266 _5views_dump_t *_5views;
267 niobserver_dump_t *niobserver;
269 dct2000_dump_t *dct2000;
272 subtype_write_func subtype_write;
273 subtype_close_func subtype_close;
275 int tsprecision; /* timestamp precision of the lower 32bits
276 * e.g. WTAP_FILE_TSPREC_USEC */
279 extern size_t wtap_dump_file_write(wtap_dumper *wdh, const void *buf, unsigned bufsize);
280 extern int wtap_dump_file_ferror(wtap_dumper *wdh);
282 extern gint wtap_num_file_types;
284 /* Macros to byte-swap 64-bit, 32-bit and 16-bit quantities. */
286 ((((x)&G_GINT64_CONSTANT(0xFF00000000000000U))>>56) | \
287 (((x)&G_GINT64_CONSTANT(0x00FF000000000000U))>>40) | \
288 (((x)&G_GINT64_CONSTANT(0x0000FF0000000000U))>>24) | \
289 (((x)&G_GINT64_CONSTANT(0x000000FF00000000U))>>8) | \
290 (((x)&G_GINT64_CONSTANT(0x00000000FF000000U))<<8) | \
291 (((x)&G_GINT64_CONSTANT(0x0000000000FF0000U))<<24) | \
292 (((x)&G_GINT64_CONSTANT(0x000000000000FF00U))<<40) | \
293 (((x)&G_GINT64_CONSTANT(0x00000000000000FFU))<<56))
295 ((((x)&0xFF000000)>>24) | \
296 (((x)&0x00FF0000)>>8) | \
297 (((x)&0x0000FF00)<<8) | \
298 (((x)&0x000000FF)<<24))
300 ((((x)&0xFF00)>>8) | \
303 /* Macros to byte-swap possibly-unaligned 32-bit and 16-bit quantities;
304 * they take a pointer to the quantity, and byte-swap it in place.
306 #define PBSWAP32(p) \
316 #define PBSWAP16(p) \
324 /* Turn host-byte-order values into little-endian values. */
325 #define htoles(s) GUINT16_TO_LE(s)
326 #define htolel(l) GUINT32_TO_LE(l)
327 #define htolell(ll) GUINT64_TO_LE(ll)
329 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
330 * byte array, returns the value of the two or four bytes at the pointer.
331 * The pletoh[sl] versions return the little-endian representation.
332 * We also provide pntohll and pletohll, which extract 64-bit integral
335 * These will work regardless of the byte alignment of the pointer.
339 #define pntohs(p) ((guint16) \
340 ((guint16)*((const guint8 *)(p)+0)<<8| \
341 (guint16)*((const guint8 *)(p)+1)<<0))
345 #define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
346 (guint32)*((const guint8 *)(p)+1)<<8| \
347 (guint32)*((const guint8 *)(p)+2)<<0)
351 #define pntohl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
352 (guint32)*((const guint8 *)(p)+1)<<16| \
353 (guint32)*((const guint8 *)(p)+2)<<8| \
354 (guint32)*((const guint8 *)(p)+3)<<0)
358 #define pntohll(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
359 (guint64)*((const guint8 *)(p)+1)<<48| \
360 (guint64)*((const guint8 *)(p)+2)<<40| \
361 (guint64)*((const guint8 *)(p)+3)<<32| \
362 (guint64)*((const guint8 *)(p)+4)<<24| \
363 (guint64)*((const guint8 *)(p)+5)<<16| \
364 (guint64)*((const guint8 *)(p)+6)<<8| \
365 (guint64)*((const guint8 *)(p)+7)<<0)
370 #define pletohs(p) ((guint16) \
371 ((guint16)*((const guint8 *)(p)+1)<<8| \
372 (guint16)*((const guint8 *)(p)+0)<<0))
376 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
377 (guint32)*((const guint8 *)(p)+1)<<8| \
378 (guint32)*((const guint8 *)(p)+0)<<0)
383 #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
384 (guint32)*((const guint8 *)(p)+2)<<16| \
385 (guint32)*((const guint8 *)(p)+1)<<8| \
386 (guint32)*((const guint8 *)(p)+0)<<0)
391 #define pletohll(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
392 (guint64)*((const guint8 *)(p)+6)<<48| \
393 (guint64)*((const guint8 *)(p)+5)<<40| \
394 (guint64)*((const guint8 *)(p)+4)<<32| \
395 (guint64)*((const guint8 *)(p)+3)<<24| \
396 (guint64)*((const guint8 *)(p)+2)<<16| \
397 (guint64)*((const guint8 *)(p)+1)<<8| \
398 (guint64)*((const guint8 *)(p)+0)<<0)
401 /* Pointer routines to put items out in a particular byte order.
402 * These will work regardless of the byte alignment of the pointer.
406 #define phtons(p, v) \
408 (p)[0] = (guint8)((v) >> 8); \
409 (p)[1] = (guint8)((v) >> 0); \
414 #define phtonl(p, v) \
416 (p)[0] = (guint8)((v) >> 24); \
417 (p)[1] = (guint8)((v) >> 16); \
418 (p)[2] = (guint8)((v) >> 8); \
419 (p)[3] = (guint8)((v) >> 0); \
424 #define phtonll(p, v) \
426 (p)[0] = (guint8)((v) >> 56); \
427 (p)[1] = (guint8)((v) >> 48); \
428 (p)[2] = (guint8)((v) >> 40); \
429 (p)[3] = (guint8)((v) >> 32); \
430 (p)[4] = (guint8)((v) >> 24); \
431 (p)[5] = (guint8)((v) >> 16); \
432 (p)[6] = (guint8)((v) >> 8); \
433 (p)[7] = (guint8)((v) >> 0); \
438 #define pletonll(p, v) \
440 (p)[0] = (guint8)((v) >> 0); \
441 (p)[1] = (guint8)((v) >> 8); \
442 (p)[2] = (guint8)((v) >> 16); \
443 (p)[3] = (guint8)((v) >> 24); \
444 (p)[4] = (guint8)((v) >> 32); \
445 (p)[5] = (guint8)((v) >> 40); \
446 (p)[6] = (guint8)((v) >> 48); \
447 (p)[7] = (guint8)((v) >> 56); \
451 #define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \
455 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
456 if (_bytes_read != (int) (num_bytes)) { \
457 *(err) = file_error((fh)); \
463 #define wtap_file_read_expected_bytes(target, num_bytes, fh, err) \
467 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
468 if (_bytes_read != (int) (num_bytes)) { \
469 *(err) = file_error((fh)); \
470 if (*(err) == 0 && _bytes_read > 0) { \
471 *(err) = WTAP_ERR_SHORT_READ; \
478 /* glib doesn't have g_ptr_array_len of all things!*/
479 #ifndef g_ptr_array_len
480 #define g_ptr_array_len(a) ((a)->len)
483 #endif /* __WTAP_INT_H__ */