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
34 #ifdef HAVE_WINSOCK2_H
40 #endif /* HAVE_LIBZ */
42 #include <wsutil/file_util.h>
44 typedef struct wtap_reader *FILE_T;
48 int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err);
50 typedef gboolean (*subtype_read_func)(struct wtap*, int*, char**, gint64*);
51 typedef gboolean (*subtype_seek_read_func)(struct wtap*, gint64, union wtap_pseudo_header*,
52 guint8*, int, int *, char **);
55 FILE_T random_fh; /* Secondary FILE_T for random access */
58 struct Buffer *frame_buffer;
59 struct wtap_pkthdr phdr;
60 union wtap_pseudo_header pseudo_header;
66 subtype_read_func subtype_read;
67 subtype_seek_read_func subtype_seek_read;
68 void (*subtype_sequential_close)(struct wtap*);
69 void (*subtype_close)(struct wtap*);
70 int file_encap; /* per-file, for those
71 file formats that have
72 per-file encapsulation
74 int tsprecision; /* timestamp precision of the lower 32bits
75 * e.g. WTAP_FILE_TSPREC_USEC */
76 wtap_new_ipv4_callback_t add_new_ipv4;
77 wtap_new_ipv6_callback_t add_new_ipv6;
84 * This could either be a FILE * or a gzFile.
86 typedef void *WFILE_T;
88 typedef gboolean (*subtype_write_func)(struct wtap_dumper*,
89 const struct wtap_pkthdr*, const union wtap_pseudo_header*,
91 typedef gboolean (*subtype_close_func)(struct wtap_dumper*, int*);
103 subtype_write_func subtype_write;
104 subtype_close_func subtype_close;
106 int tsprecision; /* timestamp precision of the lower 32bits
107 * e.g. WTAP_FILE_TSPREC_USEC */
108 struct addrinfo *addrinfo_list;
111 extern gboolean wtap_dump_file_write(wtap_dumper *wdh, const void *buf,
112 size_t bufsize, int *err);
113 extern gint64 wtap_dump_file_seek(wtap_dumper *wdh, gint64 offset, int whence, int *err);
114 extern gint64 wtap_dump_file_tell(wtap_dumper *wdh);
117 extern gint wtap_num_file_types;
119 /* Macros to byte-swap 64-bit, 32-bit and 16-bit quantities. */
121 ((((x)&G_GINT64_CONSTANT(0xFF00000000000000U))>>56) | \
122 (((x)&G_GINT64_CONSTANT(0x00FF000000000000U))>>40) | \
123 (((x)&G_GINT64_CONSTANT(0x0000FF0000000000U))>>24) | \
124 (((x)&G_GINT64_CONSTANT(0x000000FF00000000U))>>8) | \
125 (((x)&G_GINT64_CONSTANT(0x00000000FF000000U))<<8) | \
126 (((x)&G_GINT64_CONSTANT(0x0000000000FF0000U))<<24) | \
127 (((x)&G_GINT64_CONSTANT(0x000000000000FF00U))<<40) | \
128 (((x)&G_GINT64_CONSTANT(0x00000000000000FFU))<<56))
130 ((((x)&0xFF000000)>>24) | \
131 (((x)&0x00FF0000)>>8) | \
132 (((x)&0x0000FF00)<<8) | \
133 (((x)&0x000000FF)<<24))
135 ((((x)&0xFF00)>>8) | \
138 /* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
139 * they take a pointer to the quantity, and byte-swap it in place.
141 #define PBSWAP64(p) \
157 #define PBSWAP32(p) \
167 #define PBSWAP16(p) \
175 /* Turn host-byte-order values into little-endian values. */
176 #define htoles(s) GUINT16_TO_LE(s)
177 #define htolel(l) GUINT32_TO_LE(l)
178 #define htolell(ll) GUINT64_TO_LE(ll)
180 /* Pointer versions of ntohs and ntohl. Given a pointer to a member of a
181 * byte array, returns the value of the two or four bytes at the pointer.
182 * The pletoh[sl] versions return the little-endian representation.
183 * We also provide pntohll and pletohll, which extract 64-bit integral
186 * These will work regardless of the byte alignment of the pointer.
190 #define pntohs(p) ((guint16) \
191 ((guint16)*((const guint8 *)(p)+0)<<8| \
192 (guint16)*((const guint8 *)(p)+1)<<0))
196 #define pntoh24(p) ((guint32)*((const guint8 *)(p)+0)<<16| \
197 (guint32)*((const guint8 *)(p)+1)<<8| \
198 (guint32)*((const guint8 *)(p)+2)<<0)
202 #define pntohl(p) ((guint32)*((const guint8 *)(p)+0)<<24| \
203 (guint32)*((const guint8 *)(p)+1)<<16| \
204 (guint32)*((const guint8 *)(p)+2)<<8| \
205 (guint32)*((const guint8 *)(p)+3)<<0)
209 #define pntohll(p) ((guint64)*((const guint8 *)(p)+0)<<56| \
210 (guint64)*((const guint8 *)(p)+1)<<48| \
211 (guint64)*((const guint8 *)(p)+2)<<40| \
212 (guint64)*((const guint8 *)(p)+3)<<32| \
213 (guint64)*((const guint8 *)(p)+4)<<24| \
214 (guint64)*((const guint8 *)(p)+5)<<16| \
215 (guint64)*((const guint8 *)(p)+6)<<8| \
216 (guint64)*((const guint8 *)(p)+7)<<0)
221 #define pletohs(p) ((guint16) \
222 ((guint16)*((const guint8 *)(p)+1)<<8| \
223 (guint16)*((const guint8 *)(p)+0)<<0))
227 #define pletoh24(p) ((guint32)*((const guint8 *)(p)+2)<<16| \
228 (guint32)*((const guint8 *)(p)+1)<<8| \
229 (guint32)*((const guint8 *)(p)+0)<<0)
234 #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \
235 (guint32)*((const guint8 *)(p)+2)<<16| \
236 (guint32)*((const guint8 *)(p)+1)<<8| \
237 (guint32)*((const guint8 *)(p)+0)<<0)
242 #define pletohll(p) ((guint64)*((const guint8 *)(p)+7)<<56| \
243 (guint64)*((const guint8 *)(p)+6)<<48| \
244 (guint64)*((const guint8 *)(p)+5)<<40| \
245 (guint64)*((const guint8 *)(p)+4)<<32| \
246 (guint64)*((const guint8 *)(p)+3)<<24| \
247 (guint64)*((const guint8 *)(p)+2)<<16| \
248 (guint64)*((const guint8 *)(p)+1)<<8| \
249 (guint64)*((const guint8 *)(p)+0)<<0)
252 /* Pointer routines to put items out in a particular byte order.
253 * These will work regardless of the byte alignment of the pointer.
257 #define phtons(p, v) \
259 (p)[0] = (guint8)((v) >> 8); \
260 (p)[1] = (guint8)((v) >> 0); \
265 #define phton24(p, v) \
267 (p)[0] = (guint8)((v) >> 16); \
268 (p)[1] = (guint8)((v) >> 8); \
269 (p)[2] = (guint8)((v) >> 0); \
274 #define phtonl(p, v) \
276 (p)[0] = (guint8)((v) >> 24); \
277 (p)[1] = (guint8)((v) >> 16); \
278 (p)[2] = (guint8)((v) >> 8); \
279 (p)[3] = (guint8)((v) >> 0); \
284 #define phtonll(p, v) \
286 (p)[0] = (guint8)((v) >> 56); \
287 (p)[1] = (guint8)((v) >> 48); \
288 (p)[2] = (guint8)((v) >> 40); \
289 (p)[3] = (guint8)((v) >> 32); \
290 (p)[4] = (guint8)((v) >> 24); \
291 (p)[5] = (guint8)((v) >> 16); \
292 (p)[6] = (guint8)((v) >> 8); \
293 (p)[7] = (guint8)((v) >> 0); \
298 #define pletonll(p, v) \
300 (p)[0] = (guint8)((v) >> 0); \
301 (p)[1] = (guint8)((v) >> 8); \
302 (p)[2] = (guint8)((v) >> 16); \
303 (p)[3] = (guint8)((v) >> 24); \
304 (p)[4] = (guint8)((v) >> 32); \
305 (p)[5] = (guint8)((v) >> 40); \
306 (p)[6] = (guint8)((v) >> 48); \
307 (p)[7] = (guint8)((v) >> 56); \
311 #define wtap_file_read_unknown_bytes(target, num_bytes, fh, err, err_info) \
315 _bytes_read = file_read((target), (num_bytes), (fh)); \
316 if (_bytes_read != (int) (num_bytes)) { \
317 *(err) = file_error((fh), (err_info)); \
323 #define wtap_file_read_expected_bytes(target, num_bytes, fh, err, err_info) \
327 _bytes_read = file_read((target), (num_bytes), (fh)); \
328 if (_bytes_read != (int) (num_bytes)) { \
329 *(err) = file_error((fh), (err_info)); \
330 if (*(err) == 0 && _bytes_read > 0) { \
331 *(err) = WTAP_ERR_SHORT_READ; \
338 /* glib doesn't have g_ptr_array_len of all things!*/
339 #ifndef g_ptr_array_len
340 #define g_ptr_array_len(a) ((a)->len)
343 #endif /* __WTAP_INT_H__ */
351 * indent-tabs-mode: t
354 * ex: set shiftwidth=8 tabstop=8 noexpandtab
355 * :indentSize=8:tabSize=8:noTabs=false: