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__
28 #ifdef HAVE_WINSOCK2_H
32 #include <wsutil/file_util.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,
44 * Struct holding data of the currently read file.
48 FILE_T random_fh; /**< Secondary FILE_T for random access */
49 int file_type_subtype;
50 guint snapshot_length;
51 struct Buffer *frame_buffer;
52 struct wtap_pkthdr phdr;
53 struct wtapng_section_s shb_hdr;
54 guint number_of_interfaces; /**< The number of interfaces a capture was made on, number of IDB:s in a pcapng file or equivalent(?)*/
55 GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?)*/
57 void *priv; /* this one holds per-file state and is free'd automatically by wtap_close() */
58 void *wslua_data; /* this one holds wslua state info and is not free'd */
60 subtype_read_func subtype_read;
61 subtype_seek_read_func subtype_seek_read;
62 void (*subtype_sequential_close)(struct wtap*);
63 void (*subtype_close)(struct wtap*);
64 int file_encap; /* per-file, for those
65 * file formats that have
66 * per-file encapsulation
67 * types rather than per-packet
70 int file_tsprec; /* per-file timestamp precision
71 * of the fractional part of
72 * the time stamp, for those
73 * file formats that have
75 * precision rather than
76 * per-packet timestamp
78 * e.g. WTAP_TSPREC_USEC
80 wtap_new_ipv4_callback_t add_new_ipv4;
81 wtap_new_ipv6_callback_t add_new_ipv6;
88 * This could either be a FILE * or a gzFile.
90 typedef void *WFILE_T;
92 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
93 const struct wtap_pkthdr*,
94 const guint8*, int*, gchar**);
95 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
99 int file_type_subtype;
105 void *priv; /* this one holds per-file state and is free'd automatically by wtap_dump_close() */
106 void *wslua_data; /* this one holds wslua state info and is not free'd */
108 subtype_write_func subtype_write;
109 subtype_close_func subtype_close;
111 int tsprecision; /**< timestamp precision of the lower 32bits
112 * e.g. WTAP_TSPREC_USEC
114 addrinfo_lists_t *addrinfo_lists; /**< Struct containing lists of resolved addresses */
115 struct wtapng_section_s *shb_hdr;
116 GArray *interface_data; /**< An array holding the interface data from pcapng IDB:s or equivalent(?) NULL if not present.*/
119 WS_DLL_PUBLIC gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf,
120 size_t bufsize, int *err);
121 WS_DLL_PUBLIC gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err);
122 WS_DLL_PUBLIC gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err);
125 extern gint wtap_num_file_types;
127 #include <wsutil/pint.h>
129 /* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
130 * they take a pointer to the quantity, and byte-swap it in place.
132 #define PBSWAP64(p) \
148 #define PBSWAP32(p) \
158 #define PBSWAP16(p) \
167 /* Pointer routines to put items out in a particular byte order.
168 * These will work regardless of the byte alignment of the pointer.
172 #define phtons(p, v) \
174 (p)[0] = (guint8)((v) >> 8); \
175 (p)[1] = (guint8)((v) >> 0); \
180 #define phton24(p, v) \
182 (p)[0] = (guint8)((v) >> 16); \
183 (p)[1] = (guint8)((v) >> 8); \
184 (p)[2] = (guint8)((v) >> 0); \
189 #define phtonl(p, v) \
191 (p)[0] = (guint8)((v) >> 24); \
192 (p)[1] = (guint8)((v) >> 16); \
193 (p)[2] = (guint8)((v) >> 8); \
194 (p)[3] = (guint8)((v) >> 0); \
199 #define phtonll(p, v) \
201 (p)[0] = (guint8)((v) >> 56); \
202 (p)[1] = (guint8)((v) >> 48); \
203 (p)[2] = (guint8)((v) >> 40); \
204 (p)[3] = (guint8)((v) >> 32); \
205 (p)[4] = (guint8)((v) >> 24); \
206 (p)[5] = (guint8)((v) >> 16); \
207 (p)[6] = (guint8)((v) >> 8); \
208 (p)[7] = (guint8)((v) >> 0); \
213 #define phtoles(p, v) \
215 (p)[0] = (guint8)((v) >> 0); \
216 (p)[1] = (guint8)((v) >> 8); \
221 #define phtolel(p, v) \
223 (p)[0] = (guint8)((v) >> 0); \
224 (p)[1] = (guint8)((v) >> 8); \
225 (p)[2] = (guint8)((v) >> 16); \
226 (p)[3] = (guint8)((v) >> 24); \
231 #define phtolell(p, v) \
233 (p)[0] = (guint8)((v) >> 0); \
234 (p)[1] = (guint8)((v) >> 8); \
235 (p)[2] = (guint8)((v) >> 16); \
236 (p)[3] = (guint8)((v) >> 24); \
237 (p)[4] = (guint8)((v) >> 32); \
238 (p)[5] = (guint8)((v) >> 40); \
239 (p)[6] = (guint8)((v) >> 48); \
240 (p)[7] = (guint8)((v) >> 56); \
244 /* glib doesn't have g_ptr_array_len of all things!*/
245 #ifndef g_ptr_array_len
246 #define g_ptr_array_len(a) ((a)->len)
249 /*** get GSList of all compressed file extensions ***/
250 GSList *wtap_get_compressed_file_extensions(void);
253 * Read a given number of bytes from a file.
255 * If we succeed, return TRUE.
257 * If we get an EOF, return FALSE with *err set to 0, reporting this
260 * If we get fewer bytes than the specified number, return FALSE with
261 * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
264 * If we get a read error, return FALSE with *err and *err_info set
269 wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err,
273 * Read a given number of bytes from a file.
275 * If we succeed, return TRUE.
277 * If we get fewer bytes than the specified number, including getting
278 * an EOF, return FALSE with *err set to WTAP_ERR_SHORT_READ, reporting
279 * this as a short read error.
281 * If we get a read error, return FALSE with *err and *err_info set
286 wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
290 * Read packet data into a Buffer, growing the buffer as necessary.
292 * This returns an error on a short read, even if the short read hit
293 * the EOF immediately. (The assumption is that each packet has a
294 * header followed by raw packet data, and that we've already read the
295 * header, so if we get an EOF trying to read the packet data, the file
296 * has been cut short, even if the read didn't read any data at all.)
300 wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
303 #endif /* __WTAP_INT_H__ */
311 * indent-tabs-mode: t
314 * ex: set shiftwidth=8 tabstop=8 noexpandtab:
315 * :indentSize=8:tabSize=8:noTabs=false: