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;
105 GArray *interface_data;
106 guint number_of_interfaces;
112 guint8 version_major;
113 guint32 *frame_table;
114 guint32 frame_table_size;
120 double ticks_per_sec;
121 double start_timestamp;
127 gboolean fcs_valid; /* if packets have valid FCS at the end */
128 guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */
134 gint64 next_packet_seek_start;
138 gboolean byteswapped;
142 struct timeval reference_time;
149 typedef struct _k12_t k12_t;
154 } catapult_dct2000_t;
157 struct wtap_nstime now;
163 gint32 nstrace_buf_offset;
164 gint32 nstrace_buflen;
165 /* Performance Monitor Time variables */
166 guint32 nspm_curtime; /* current time since 1970 */
167 guint64 nspm_curtimemsec; /* current time in mili second */
168 guint64 nspm_curtimelastmsec; /* nspm_curtime last update time in milisec */
169 guint64 nsg_creltime;
174 typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
175 typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, union wtap_pseudo_header*,
176 guint8*, int, int *, char **);
179 int fd; /* File descriptor for cap file */
180 FILE_T random_fh; /* Secondary FILE_T for random access */
183 struct Buffer *frame_buffer;
184 struct wtap_pkthdr phdr;
185 union wtap_pseudo_header pseudo_header;
191 lanalyzer_t *lanalyzer;
192 ngsniffer_t *ngsniffer;
194 i4btrace_t *i4btrace;
200 etherpeek_t *etherpeek;
201 airopeek9_t *airopeek9;
203 catapult_dct2000_t *catapult_dct2000;
210 subtype_read_func subtype_read;
211 subtype_seek_read_func subtype_seek_read;
212 void (*subtype_sequential_close)(struct wtap*);
213 void (*subtype_close)(struct wtap*);
214 int file_encap; /* per-file, for those
215 file formats that have
216 per-file encapsulation
218 int tsprecision; /* timestamp precision of the lower 32bits
219 * e.g. WTAP_FILE_TSPREC_USEC */
224 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
225 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
226 const guchar*, int*);
227 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
230 gboolean first_frame;
235 gboolean first_frame;
236 struct wtap_nstime start;
241 gboolean got_first_record_time;
242 struct wtap_nstime first_record_time;
243 guint32 frame_table_offset;
244 guint32 *frame_table;
245 guint frame_table_index;
246 guint frame_table_size;
260 guint64 packet_count;
266 guint32 num_of_records;
271 gboolean first_packet_written;
272 struct wtap_nstime start_time;
276 GArray *interface_data;
277 guint number_of_interfaces;
290 ngsniffer_dump_t *ngsniffer;
291 netmon_dump_t *netmon;
292 netxray_dump_t *netxray;
293 _5views_dump_t *_5views;
294 niobserver_dump_t *niobserver;
296 dct2000_dump_t *dct2000;
297 nstrace_dump_t *nstr;
298 pcapng_dump_t *pcapng;
301 subtype_write_func subtype_write;
302 subtype_close_func subtype_close;
304 int tsprecision; /* timestamp precision of the lower 32bits
305 * e.g. WTAP_FILE_TSPREC_USEC */
308 extern gboolean wtap_dump_file_write_all(wtap_dumper *wdh, const void *buf, unsigned bufsize, int *err);
309 extern size_t wtap_dump_file_write(wtap_dumper *wdh, const void *buf, size_t bufsize);
310 extern int wtap_dump_file_ferror(wtap_dumper *wdh);
312 extern gint wtap_num_file_types;
314 /* Macros to byte-swap 64-bit, 32-bit and 16-bit quantities. */
316 ((((x)&G_GINT64_CONSTANT(0xFF00000000000000U))>>56) | \
317 (((x)&G_GINT64_CONSTANT(0x00FF000000000000U))>>40) | \
318 (((x)&G_GINT64_CONSTANT(0x0000FF0000000000U))>>24) | \
319 (((x)&G_GINT64_CONSTANT(0x000000FF00000000U))>>8) | \
320 (((x)&G_GINT64_CONSTANT(0x00000000FF000000U))<<8) | \
321 (((x)&G_GINT64_CONSTANT(0x0000000000FF0000U))<<24) | \
322 (((x)&G_GINT64_CONSTANT(0x000000000000FF00U))<<40) | \
323 (((x)&G_GINT64_CONSTANT(0x00000000000000FFU))<<56))
325 ((((x)&0xFF000000)>>24) | \
326 (((x)&0x00FF0000)>>8) | \
327 (((x)&0x0000FF00)<<8) | \
328 (((x)&0x000000FF)<<24))
330 ((((x)&0xFF00)>>8) | \
333 /* Macros to byte-swap possibly-unaligned 32-bit and 16-bit quantities;
334 * they take a pointer to the quantity, and byte-swap it in place.
336 #define PBSWAP32(p) \
346 #define PBSWAP16(p) \
354 /* Turn host-byte-order values into little-endian values. */
355 #define htoles(s) GUINT16_TO_LE(s)
356 #define htolel(l) GUINT32_TO_LE(l)
357 #define htolell(ll) GUINT64_TO_LE(ll)
359 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
360 * byte array, returns the value of the two or four bytes at the pointer.
361 * The pletoh[sl] versions return the little-endian representation.
362 * We also provide pntohll and pletohll, which extract 64-bit integral
365 * These will work regardless of the byte alignment of the pointer.
369 #define pntohs(p) ((guint16) \
370 ((guint16)*((const guint8 *)(p)+0)<<8| \
371 (guint16)*((const guint8 *)(p)+1)<<0))
375 #define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
376 (guint32)*((const guint8 *)(p)+1)<<8| \
377 (guint32)*((const guint8 *)(p)+2)<<0)
381 #define pntohl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
382 (guint32)*((const guint8 *)(p)+1)<<16| \
383 (guint32)*((const guint8 *)(p)+2)<<8| \
384 (guint32)*((const guint8 *)(p)+3)<<0)
388 #define pntohll(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
389 (guint64)*((const guint8 *)(p)+1)<<48| \
390 (guint64)*((const guint8 *)(p)+2)<<40| \
391 (guint64)*((const guint8 *)(p)+3)<<32| \
392 (guint64)*((const guint8 *)(p)+4)<<24| \
393 (guint64)*((const guint8 *)(p)+5)<<16| \
394 (guint64)*((const guint8 *)(p)+6)<<8| \
395 (guint64)*((const guint8 *)(p)+7)<<0)
400 #define pletohs(p) ((guint16) \
401 ((guint16)*((const guint8 *)(p)+1)<<8| \
402 (guint16)*((const guint8 *)(p)+0)<<0))
406 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
407 (guint32)*((const guint8 *)(p)+1)<<8| \
408 (guint32)*((const guint8 *)(p)+0)<<0)
413 #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
414 (guint32)*((const guint8 *)(p)+2)<<16| \
415 (guint32)*((const guint8 *)(p)+1)<<8| \
416 (guint32)*((const guint8 *)(p)+0)<<0)
421 #define pletohll(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
422 (guint64)*((const guint8 *)(p)+6)<<48| \
423 (guint64)*((const guint8 *)(p)+5)<<40| \
424 (guint64)*((const guint8 *)(p)+4)<<32| \
425 (guint64)*((const guint8 *)(p)+3)<<24| \
426 (guint64)*((const guint8 *)(p)+2)<<16| \
427 (guint64)*((const guint8 *)(p)+1)<<8| \
428 (guint64)*((const guint8 *)(p)+0)<<0)
431 /* Pointer routines to put items out in a particular byte order.
432 * These will work regardless of the byte alignment of the pointer.
436 #define phtons(p, v) \
438 (p)[0] = (guint8)((v) >> 8); \
439 (p)[1] = (guint8)((v) >> 0); \
444 #define phtonl(p, v) \
446 (p)[0] = (guint8)((v) >> 24); \
447 (p)[1] = (guint8)((v) >> 16); \
448 (p)[2] = (guint8)((v) >> 8); \
449 (p)[3] = (guint8)((v) >> 0); \
454 #define phtonll(p, v) \
456 (p)[0] = (guint8)((v) >> 56); \
457 (p)[1] = (guint8)((v) >> 48); \
458 (p)[2] = (guint8)((v) >> 40); \
459 (p)[3] = (guint8)((v) >> 32); \
460 (p)[4] = (guint8)((v) >> 24); \
461 (p)[5] = (guint8)((v) >> 16); \
462 (p)[6] = (guint8)((v) >> 8); \
463 (p)[7] = (guint8)((v) >> 0); \
468 #define pletonll(p, v) \
470 (p)[0] = (guint8)((v) >> 0); \
471 (p)[1] = (guint8)((v) >> 8); \
472 (p)[2] = (guint8)((v) >> 16); \
473 (p)[3] = (guint8)((v) >> 24); \
474 (p)[4] = (guint8)((v) >> 32); \
475 (p)[5] = (guint8)((v) >> 40); \
476 (p)[6] = (guint8)((v) >> 48); \
477 (p)[7] = (guint8)((v) >> 56); \
481 #define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \
485 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
486 if (_bytes_read != (int) (num_bytes)) { \
487 *(err) = file_error((fh)); \
493 #define wtap_file_read_expected_bytes(target, num_bytes, fh, err) \
497 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
498 if (_bytes_read != (int) (num_bytes)) { \
499 *(err) = file_error((fh)); \
500 if (*(err) == 0 && _bytes_read > 0) { \
501 *(err) = WTAP_ERR_SHORT_READ; \
508 /* glib doesn't have g_ptr_array_len of all things!*/
509 #ifndef g_ptr_array_len
510 #define g_ptr_array_len(a) ((a)->len)
513 #endif /* __WTAP_INT_H__ */