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__
27 #ifdef HAVE_WINSOCK2_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 int file_type_subtype;
51 guint snapshot_length;
52 struct Buffer *frame_buffer;
53 struct wtap_pkthdr phdr;
54 wtap_optionblock_t shb_hdr;
55 GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/
56 wtap_optionblock_t nrb_hdr; /**< holds the Name Res Block's comment/custom_opts, or NULL */
58 void *priv; /* this one holds per-file state and is free'd automatically by wtap_close() */
59 void *wslua_data; /* this one holds wslua state info and is not free'd */
61 subtype_read_func subtype_read;
62 subtype_seek_read_func subtype_seek_read;
63 void (*subtype_sequential_close)(struct wtap*);
64 void (*subtype_close)(struct wtap*);
65 int file_encap; /* per-file, for those
66 * file formats that have
67 * per-file encapsulation
68 * types rather than per-packet
71 int file_tsprec; /* per-file timestamp precision
72 * of the fractional part of
73 * the time stamp, for those
74 * file formats that have
76 * precision rather than
77 * per-packet timestamp
79 * e.g. WTAP_TSPREC_USEC
81 wtap_new_ipv4_callback_t add_new_ipv4;
82 wtap_new_ipv6_callback_t add_new_ipv6;
89 * This could either be a FILE * or a gzFile.
91 typedef void *WFILE_T;
93 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
94 const struct wtap_pkthdr*,
95 const guint8*, int*, gchar**);
96 typedef gboolean (*subtype_finish_func)(struct wtap_dumper*, int*);
100 gboolean is_stdout; /* TRUE if we're writing to the standard output */
101 int file_type_subtype;
107 void *priv; /* this one holds per-file state and is free'd automatically by wtap_dump_close() */
108 void *wslua_data; /* this one holds wslua state info and is not free'd */
110 subtype_write_func subtype_write; /* write out a record */
111 subtype_finish_func subtype_finish; /* write out information to finish writing file */
113 int tsprecision; /**< timestamp precision of the lower 32bits
114 * e.g. WTAP_TSPREC_USEC
116 addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */
117 wtap_optionblock_t shb_hdr;
118 wtap_optionblock_t nrb_hdr; /**< name resolution comment/custom_opt, or NULL */
119 GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?) NULL if not present.*/
122 WS_DLL_PUBLIC gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf,
123 size_t bufsize, int *err);
124 WS_DLL_PUBLIC gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err);
125 WS_DLL_PUBLIC gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err);
128 extern gint wtap_num_file_types;
130 #include <wsutil/pint.h>
132 /* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
133 * they take a pointer to the quantity, and byte-swap it in place.
135 #define PBSWAP64(p) \
151 #define PBSWAP32(p) \
161 #define PBSWAP16(p) \
170 /* Pointer routines to put items out in a particular byte order.
171 * These will work regardless of the byte alignment of the pointer.
175 #define phtons(p, v) \
177 (p)[0] = (guint8)((v) >> 8); \
178 (p)[1] = (guint8)((v) >> 0); \
183 #define phton24(p, v) \
185 (p)[0] = (guint8)((v) >> 16); \
186 (p)[1] = (guint8)((v) >> 8); \
187 (p)[2] = (guint8)((v) >> 0); \
192 #define phtonl(p, v) \
194 (p)[0] = (guint8)((v) >> 24); \
195 (p)[1] = (guint8)((v) >> 16); \
196 (p)[2] = (guint8)((v) >> 8); \
197 (p)[3] = (guint8)((v) >> 0); \
202 #define phtonll(p, v) \
204 (p)[0] = (guint8)((v) >> 56); \
205 (p)[1] = (guint8)((v) >> 48); \
206 (p)[2] = (guint8)((v) >> 40); \
207 (p)[3] = (guint8)((v) >> 32); \
208 (p)[4] = (guint8)((v) >> 24); \
209 (p)[5] = (guint8)((v) >> 16); \
210 (p)[6] = (guint8)((v) >> 8); \
211 (p)[7] = (guint8)((v) >> 0); \
216 #define phtoles(p, v) \
218 (p)[0] = (guint8)((v) >> 0); \
219 (p)[1] = (guint8)((v) >> 8); \
224 #define phtolel(p, v) \
226 (p)[0] = (guint8)((v) >> 0); \
227 (p)[1] = (guint8)((v) >> 8); \
228 (p)[2] = (guint8)((v) >> 16); \
229 (p)[3] = (guint8)((v) >> 24); \
234 #define phtolell(p, v) \
236 (p)[0] = (guint8)((v) >> 0); \
237 (p)[1] = (guint8)((v) >> 8); \
238 (p)[2] = (guint8)((v) >> 16); \
239 (p)[3] = (guint8)((v) >> 24); \
240 (p)[4] = (guint8)((v) >> 32); \
241 (p)[5] = (guint8)((v) >> 40); \
242 (p)[6] = (guint8)((v) >> 48); \
243 (p)[7] = (guint8)((v) >> 56); \
247 /* glib doesn't have g_ptr_array_len of all things!*/
248 #ifndef g_ptr_array_len
249 #define g_ptr_array_len(a) ((a)->len)
253 * Table of extensions for compressed file types we support.
254 * Last pointer in the list is null.
256 extern const char *compressed_file_extension_table[];
259 * Read a given number of bytes from a file.
261 * If we succeed, return TRUE.
263 * If we get an EOF, return FALSE with *err set to 0, reporting this
266 * If we get fewer bytes than the specified number, return FALSE with
267 * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
270 * If we get a read error, return FALSE with *err and *err_info set
275 wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err,
279 * Read a given number of bytes from a file.
281 * If we succeed, return TRUE.
283 * If we get fewer bytes than the specified number, including getting
284 * an EOF, return FALSE with *err set to WTAP_ERR_SHORT_READ, reporting
285 * this as a short read error.
287 * If we get a read error, return FALSE with *err and *err_info set
292 wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
296 * Read packet data into a Buffer, growing the buffer as necessary.
298 * This returns an error on a short read, even if the short read hit
299 * the EOF immediately. (The assumption is that each packet has a
300 * header followed by raw packet data, and that we've already read the
301 * header, so if we get an EOF trying to read the packet data, the file
302 * has been cut short, even if the read didn't read any data at all.)
306 wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
309 #endif /* __WTAP_INT_H__ */
317 * indent-tabs-mode: t
320 * ex: set shiftwidth=8 tabstop=8 noexpandtab:
321 * :indentSize=8:tabSize=8:noTabs=false: