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 gint64 comp_offset; /* current offset in compressed data stream */
52 gint64 uncomp_offset; /* current offset in uncompressed data stream */
53 } ngsniffer_comp_stream_t;
56 guint8 *sdate; /* Packet start date */
57 gboolean tcp_formatted; /* TCP/IP data formated Y/N */
58 int format; /* Trace format type */
66 guint network; /* network type */
67 ngsniffer_comp_stream_t seq; /* sequential access */
68 ngsniffer_comp_stream_t rand; /* random access */
69 GList *first_blob; /* list element for first blob */
70 GList *last_blob; /* list element for last blob */
71 GList *current_blob; /* list element for current blob */
75 gboolean byte_swapped;
93 gboolean byte_swapped;
94 swapped_type_t lengths_swapped;
95 guint16 version_major;
96 guint16 version_minor;
102 guint8 version_major;
103 guint32 *frame_table;
104 guint32 frame_table_size;
111 double start_timestamp;
117 gboolean fcs_valid; /* if packets have valid FCS at the end */
118 guint isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */
124 gint64 next_packet_seek_start;
128 gboolean byteswapped;
132 struct timeval reference_time;
145 typedef struct _k12_t k12_t;
150 } catapult_dct2000_t;
153 struct wtap_nstime now;
157 typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
158 typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, union wtap_pseudo_header*,
159 guint8*, int, int *, char **);
162 int fd; /* File descriptor for cap file */
163 FILE_T random_fh; /* Secondary FILE_T for random access */
166 struct Buffer *frame_buffer;
167 struct wtap_pkthdr phdr;
168 union wtap_pseudo_header pseudo_header;
174 lanalyzer_t *lanalyzer;
175 ngsniffer_t *ngsniffer;
177 i4btrace_t *i4btrace;
183 etherpeek_t *etherpeek;
184 airopeek9_t *airopeek9;
187 catapult_dct2000_t *catapult_dct2000;
192 subtype_read_func subtype_read;
193 subtype_seek_read_func subtype_seek_read;
194 void (*subtype_sequential_close)(struct wtap*);
195 void (*subtype_close)(struct wtap*);
196 int file_encap; /* per-file, for those
197 file formats that have
198 per-file encapsulation
200 int tsprecision; /* timestamp precision of the lower 32bits
201 * e.g. WTAP_FILE_TSPREC_USEC */
206 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
207 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
208 const guchar*, int*);
209 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
212 gboolean first_frame;
217 gboolean first_frame;
218 struct wtap_nstime start;
223 gboolean got_first_record_time;
224 struct wtap_nstime first_record_time;
225 guint32 frame_table_offset;
226 guint32 *frame_table;
227 guint frame_table_index;
228 guint frame_table_size;
236 guint64 packet_count;
242 guint32 num_of_records;
247 gboolean first_packet_written;
248 struct wtap_nstime start_time;
261 ngsniffer_dump_t *ngsniffer;
262 netmon_dump_t *netmon;
263 netxray_dump_t *netxray;
264 _5views_dump_t *_5views;
265 niobserver_dump_t *niobserver;
267 dct2000_dump_t *dct2000;
270 subtype_write_func subtype_write;
271 subtype_close_func subtype_close;
273 int tsprecision; /* timestamp precision of the lower 32bits
274 * e.g. WTAP_FILE_TSPREC_USEC */
277 extern size_t wtap_dump_file_write(wtap_dumper *wdh, const void *buf, unsigned bufsize);
278 extern int wtap_dump_file_ferror(wtap_dumper *wdh);
280 extern gint wtap_num_file_types;
282 /* Macros to byte-swap 32-bit and 16-bit quantities. */
284 ((((x)&0xFF000000)>>24) | \
285 (((x)&0x00FF0000)>>8) | \
286 (((x)&0x0000FF00)<<8) | \
287 (((x)&0x000000FF)<<24))
289 ((((x)&0xFF00)>>8) | \
292 /* Macros to byte-swap possibly-unaligned 32-bit and 16-bit quantities;
293 * they take a pointer to the quantity, and byte-swap it in place.
295 #define PBSWAP32(p) \
305 #define PBSWAP16(p) \
313 /* Turn host-byte-order values into little-endian values. */
314 #define htoles(s) GUINT16_TO_LE(s)
315 #define htolel(l) GUINT32_TO_LE(l)
316 #define htolell(ll) GUINT64_TO_LE(ll)
318 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
319 * byte array, returns the value of the two or four bytes at the pointer.
320 * The pletoh[sl] versions return the little-endian representation.
321 * We also provide pntohll and pletohll, which extract 64-bit integral
324 * These will work regardless of the byte alignment of the pointer.
328 #define pntohs(p) ((guint16) \
329 ((guint16)*((const guint8 *)(p)+0)<<8| \
330 (guint16)*((const guint8 *)(p)+1)<<0))
334 #define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
335 (guint32)*((const guint8 *)(p)+1)<<8| \
336 (guint32)*((const guint8 *)(p)+2)<<0)
340 #define pntohl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
341 (guint32)*((const guint8 *)(p)+1)<<16| \
342 (guint32)*((const guint8 *)(p)+2)<<8| \
343 (guint32)*((const guint8 *)(p)+3)<<0)
347 #define pntohll(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
348 (guint64)*((const guint8 *)(p)+1)<<48| \
349 (guint64)*((const guint8 *)(p)+2)<<40| \
350 (guint64)*((const guint8 *)(p)+3)<<32| \
351 (guint64)*((const guint8 *)(p)+4)<<24| \
352 (guint64)*((const guint8 *)(p)+5)<<16| \
353 (guint64)*((const guint8 *)(p)+6)<<8| \
354 (guint64)*((const guint8 *)(p)+7)<<0)
359 #define pletohs(p) ((guint16) \
360 ((guint16)*((const guint8 *)(p)+1)<<8| \
361 (guint16)*((const guint8 *)(p)+0)<<0))
365 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
366 (guint32)*((const guint8 *)(p)+1)<<8| \
367 (guint32)*((const guint8 *)(p)+0)<<0)
372 #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
373 (guint32)*((const guint8 *)(p)+2)<<16| \
374 (guint32)*((const guint8 *)(p)+1)<<8| \
375 (guint32)*((const guint8 *)(p)+0)<<0)
380 #define pletohll(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
381 (guint64)*((const guint8 *)(p)+6)<<48| \
382 (guint64)*((const guint8 *)(p)+5)<<40| \
383 (guint64)*((const guint8 *)(p)+4)<<32| \
384 (guint64)*((const guint8 *)(p)+3)<<24| \
385 (guint64)*((const guint8 *)(p)+2)<<16| \
386 (guint64)*((const guint8 *)(p)+1)<<8| \
387 (guint64)*((const guint8 *)(p)+0)<<0)
390 /* Pointer routines to put items out in a particular byte order.
391 * These will work regardless of the byte alignment of the pointer.
395 #define phtons(p, v) \
403 #define phtonl(p, v) \
405 (p)[0] = ((v) >> 24); \
406 (p)[1] = ((v) >> 16); \
407 (p)[2] = ((v) >> 8); \
412 #define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \
416 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
417 if (_bytes_read != (int) (num_bytes)) { \
418 *(err) = file_error((fh)); \
424 #define wtap_file_read_expected_bytes(target, num_bytes, fh, err) \
428 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
429 if (_bytes_read != (int) (num_bytes)) { \
430 *(err) = file_error((fh)); \
431 if (*(err) == 0 && _bytes_read > 0) { \
432 *(err) = WTAP_ERR_SHORT_READ; \
439 /* glib doesn't have g_ptr_array_len of all things!*/
440 #ifndef g_ptr_array_len
441 #define g_ptr_array_len(a) ((a)->len)
444 #endif /* __WTAP_INT_H__ */