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;
152 typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
153 typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, union wtap_pseudo_header*,
154 guint8*, int, int *, char **);
157 int fd; /* File descriptor for cap file */
158 FILE_T random_fh; /* Secondary FILE_T for random access */
161 struct Buffer *frame_buffer;
162 struct wtap_pkthdr phdr;
163 union wtap_pseudo_header pseudo_header;
169 lanalyzer_t *lanalyzer;
170 ngsniffer_t *ngsniffer;
172 i4btrace_t *i4btrace;
178 etherpeek_t *etherpeek;
179 airopeek9_t *airopeek9;
182 catapult_dct2000_t* catapult_dct2000;
186 subtype_read_func subtype_read;
187 subtype_seek_read_func subtype_seek_read;
188 void (*subtype_sequential_close)(struct wtap*);
189 void (*subtype_close)(struct wtap*);
190 int file_encap; /* per-file, for those
191 file formats that have
192 per-file encapsulation
194 int tsprecision; /* timestamp precision of the lower 32bits
195 * e.g. WTAP_FILE_TSPREC_USEC */
200 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
201 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
202 const guchar*, int*);
203 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
206 gboolean first_frame;
211 gboolean first_frame;
212 struct wtap_nstime start;
217 gboolean got_first_record_time;
218 struct wtap_nstime first_record_time;
219 guint32 frame_table_offset;
220 guint32 *frame_table;
221 guint frame_table_index;
222 guint frame_table_size;
230 guint64 packet_count;
236 guint32 num_of_records;
241 gboolean first_packet_written;
242 struct wtap_nstime start_time;
255 ngsniffer_dump_t *ngsniffer;
256 netmon_dump_t *netmon;
257 netxray_dump_t *netxray;
258 _5views_dump_t *_5views;
259 niobserver_dump_t *niobserver;
261 dct2000_dump_t *dct2000;
264 subtype_write_func subtype_write;
265 subtype_close_func subtype_close;
267 int tsprecision; /* timestamp precision of the lower 32bits
268 * e.g. WTAP_FILE_TSPREC_USEC */
271 extern size_t wtap_dump_file_write(wtap_dumper *wdh, const void *buf, unsigned bufsize);
272 extern int wtap_dump_file_ferror(wtap_dumper *wdh);
274 /* Macros to byte-swap 32-bit and 16-bit quantities. */
276 ((((x)&0xFF000000)>>24) | \
277 (((x)&0x00FF0000)>>8) | \
278 (((x)&0x0000FF00)<<8) | \
279 (((x)&0x000000FF)<<24))
281 ((((x)&0xFF00)>>8) | \
284 /* Turn host-byte-order values into little-endian values. */
285 #define htoles(s) GUINT16_TO_LE(s)
286 #define htolel(l) GUINT32_TO_LE(l)
287 #define htolell(ll) GUINT64_TO_LE(ll)
289 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
290 * byte array, returns the value of the two or four bytes at the pointer.
291 * The pletoh[sl] versions return the little-endian representation.
292 * We also provide pntohll and phtolell, which extract 64-bit integral
297 #define pntohs(p) ((guint16) \
298 ((guint16)*((const guint8 *)(p)+0)<<8| \
299 (guint16)*((const guint8 *)(p)+1)<<0))
303 #define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
304 (guint32)*((const guint8 *)(p)+1)<<8| \
305 (guint32)*((const guint8 *)(p)+2)<<0)
309 #define pntohl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
310 (guint32)*((const guint8 *)(p)+1)<<16| \
311 (guint32)*((const guint8 *)(p)+2)<<8| \
312 (guint32)*((const guint8 *)(p)+3)<<0)
316 #define pntohll(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
317 (guint64)*((const guint8 *)(p)+1)<<48| \
318 (guint64)*((const guint8 *)(p)+2)<<40| \
319 (guint64)*((const guint8 *)(p)+3)<<32| \
320 (guint64)*((const guint8 *)(p)+4)<<24| \
321 (guint64)*((const guint8 *)(p)+5)<<16| \
322 (guint64)*((const guint8 *)(p)+6)<<8| \
323 (guint64)*((const guint8 *)(p)+7)<<0)
328 #define phtons(p) ((guint16) \
329 ((guint16)*((const guint8 *)(p)+0)<<8| \
330 (guint16)*((const guint8 *)(p)+1)<<0))
334 #define phtonl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
335 (guint32)*((const guint8 *)(p)+1)<<16| \
336 (guint32)*((const guint8 *)(p)+2)<<8| \
337 (guint32)*((const guint8 *)(p)+3)<<0)
341 #define pletohs(p) ((guint16) \
342 ((guint16)*((const guint8 *)(p)+1)<<8| \
343 (guint16)*((const guint8 *)(p)+0)<<0))
347 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
348 (guint32)*((const guint8 *)(p)+1)<<8| \
349 (guint32)*((const guint8 *)(p)+0)<<0)
354 #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
355 (guint32)*((const guint8 *)(p)+2)<<16| \
356 (guint32)*((const guint8 *)(p)+1)<<8| \
357 (guint32)*((const guint8 *)(p)+0)<<0)
362 #define pletohll(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
363 (guint64)*((const guint8 *)(p)+6)<<48| \
364 (guint64)*((const guint8 *)(p)+5)<<40| \
365 (guint64)*((const guint8 *)(p)+4)<<32| \
366 (guint64)*((const guint8 *)(p)+3)<<24| \
367 (guint64)*((const guint8 *)(p)+2)<<16| \
368 (guint64)*((const guint8 *)(p)+1)<<8| \
369 (guint64)*((const guint8 *)(p)+0)<<0)
372 #define wtap_file_read_unknown_bytes(target, num_bytes, fh, err) \
376 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
377 if (_bytes_read != (int) (num_bytes)) { \
378 *(err) = file_error((fh)); \
384 #define wtap_file_read_expected_bytes(target, num_bytes, fh, err) \
388 _bytes_read = file_read((target), 1, (num_bytes), (fh)); \
389 if (_bytes_read != (int) (num_bytes)) { \
390 *(err) = file_error((fh)); \
391 if (*(err) == 0 && _bytes_read > 0) { \
392 *(err) = WTAP_ERR_SHORT_READ; \
399 /* glib doesn't have g_ptr_array_len of all things!*/
400 #ifndef g_ptr_array_len
401 #define g_ptr_array_len(a) ((a)->len)
404 #endif /* __WTAP_INT_H__ */