4 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef __WTAP_INT_H__
22 #define __WTAP_INT_H__
31 #include <wsutil/file_util.h>
34 #include "wtap_opttypes.h"
37 int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err);
39 typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
40 typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64,
41 struct wtap_pkthdr *, Buffer *buf,
45 * Struct holding data of the currently read file.
49 FILE_T random_fh; /**< Secondary FILE_T for random access */
50 gboolean ispipe; /**< TRUE if the file is a pipe */
51 int file_type_subtype;
52 guint snapshot_length;
53 struct Buffer *frame_buffer;
54 struct wtap_pkthdr phdr;
56 GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/
57 GArray *nrb_hdrs; /**< holds the Name Res Block's comment/custom_opts, or NULL */
59 void *priv; /* this one holds per-file state and is free'd automatically by wtap_close() */
60 void *wslua_data; /* this one holds wslua state info and is not free'd */
62 subtype_read_func subtype_read;
63 subtype_seek_read_func subtype_seek_read;
64 void (*subtype_sequential_close)(struct wtap*);
65 void (*subtype_close)(struct wtap*);
66 int file_encap; /* per-file, for those
67 * file formats that have
68 * per-file encapsulation
69 * types rather than per-packet
72 int file_tsprec; /* per-file timestamp precision
73 * of the fractional part of
74 * the time stamp, for those
75 * file formats that have
77 * precision rather than
78 * per-packet timestamp
80 * e.g. WTAP_TSPREC_USEC
82 wtap_new_ipv4_callback_t add_new_ipv4;
83 wtap_new_ipv6_callback_t add_new_ipv6;
90 * This could either be a FILE * or a gzFile.
92 typedef void *WFILE_T;
94 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
95 const struct wtap_pkthdr*,
96 const guint8*, int*, gchar**);
97 typedef gboolean (*subtype_finish_func)(struct wtap_dumper*, int*);
101 int file_type_subtype;
105 gboolean needs_reload; /* TRUE if the file requires re-loading after saving with wtap */
108 void *priv; /* this one holds per-file state and is free'd automatically by wtap_dump_close() */
109 void *wslua_data; /* this one holds wslua state info and is not free'd */
111 subtype_write_func subtype_write; /* write out a record */
112 subtype_finish_func subtype_finish; /* write out information to finish writing file */
114 addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */
116 GArray *nrb_hdrs; /**< name resolution comment/custom_opt, or NULL */
117 GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?) NULL if not present.*/
120 WS_DLL_PUBLIC gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf,
121 size_t bufsize, int *err);
122 WS_DLL_PUBLIC gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err);
123 WS_DLL_PUBLIC gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err);
126 extern gint wtap_num_file_types;
128 #include <wsutil/pint.h>
130 /* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
131 * they take a pointer to the quantity, and byte-swap it in place.
133 #define PBSWAP64(p) \
149 #define PBSWAP32(p) \
159 #define PBSWAP16(p) \
168 /* Pointer routines to put items out in a particular byte order.
169 * These will work regardless of the byte alignment of the pointer.
173 #define phtons(p, v) \
175 (p)[0] = (guint8)((v) >> 8); \
176 (p)[1] = (guint8)((v) >> 0); \
181 #define phton24(p, v) \
183 (p)[0] = (guint8)((v) >> 16); \
184 (p)[1] = (guint8)((v) >> 8); \
185 (p)[2] = (guint8)((v) >> 0); \
190 #define phtonl(p, v) \
192 (p)[0] = (guint8)((v) >> 24); \
193 (p)[1] = (guint8)((v) >> 16); \
194 (p)[2] = (guint8)((v) >> 8); \
195 (p)[3] = (guint8)((v) >> 0); \
200 #define phtonll(p, v) \
202 (p)[0] = (guint8)((v) >> 56); \
203 (p)[1] = (guint8)((v) >> 48); \
204 (p)[2] = (guint8)((v) >> 40); \
205 (p)[3] = (guint8)((v) >> 32); \
206 (p)[4] = (guint8)((v) >> 24); \
207 (p)[5] = (guint8)((v) >> 16); \
208 (p)[6] = (guint8)((v) >> 8); \
209 (p)[7] = (guint8)((v) >> 0); \
214 #define phtole8(p, v) \
216 (p)[0] = (guint8)((v) >> 0); \
221 #define phtoles(p, v) \
223 (p)[0] = (guint8)((v) >> 0); \
224 (p)[1] = (guint8)((v) >> 8); \
229 #define phtole24(p, v) \
231 (p)[0] = (guint8)((v) >> 0); \
232 (p)[1] = (guint8)((v) >> 8); \
233 (p)[2] = (guint8)((v) >> 16); \
238 #define phtolel(p, v) \
240 (p)[0] = (guint8)((v) >> 0); \
241 (p)[1] = (guint8)((v) >> 8); \
242 (p)[2] = (guint8)((v) >> 16); \
243 (p)[3] = (guint8)((v) >> 24); \
248 #define phtolell(p, v) \
250 (p)[0] = (guint8)((v) >> 0); \
251 (p)[1] = (guint8)((v) >> 8); \
252 (p)[2] = (guint8)((v) >> 16); \
253 (p)[3] = (guint8)((v) >> 24); \
254 (p)[4] = (guint8)((v) >> 32); \
255 (p)[5] = (guint8)((v) >> 40); \
256 (p)[6] = (guint8)((v) >> 48); \
257 (p)[7] = (guint8)((v) >> 56); \
261 /* glib doesn't have g_ptr_array_len of all things!*/
262 #ifndef g_ptr_array_len
263 #define g_ptr_array_len(a) ((a)->len)
267 * Table of extensions for compressed file types we support.
268 * Last pointer in the list is null.
270 extern const char *compressed_file_extension_table[];
273 * Read a given number of bytes from a file into a buffer or, if
274 * buf is NULL, just discard them.
276 * If we succeed, return TRUE.
278 * If we get an EOF, return FALSE with *err set to 0, reporting this
281 * If we get fewer bytes than the specified number, return FALSE with
282 * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
285 * If we get a read error, return FALSE with *err and *err_info set
290 wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err,
294 * Read a given number of bytes from a file into a buffer or, if
295 * buf is NULL, just discard them.
297 * If we succeed, return TRUE.
299 * If we get fewer bytes than the specified number, including getting
300 * an EOF, return FALSE with *err set to WTAP_ERR_SHORT_READ, reporting
301 * this as a short read error.
303 * If we get a read error, return FALSE with *err and *err_info set
308 wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
312 * Read packet data into a Buffer, growing the buffer as necessary.
314 * This returns an error on a short read, even if the short read hit
315 * the EOF immediately. (The assumption is that each packet has a
316 * header followed by raw packet data, and that we've already read the
317 * header, so if we get an EOF trying to read the packet data, the file
318 * has been cut short, even if the read didn't read any data at all.)
322 wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
325 #endif /* __WTAP_INT_H__ */
333 * indent-tabs-mode: t
336 * ex: set shiftwidth=8 tabstop=8 noexpandtab:
337 * :indentSize=8:tabSize=8:noTabs=false: