Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
wtap-int.h
Go to the documentation of this file.
1
9#ifndef __WTAP_INT_H__
10#define __WTAP_INT_H__
11
12#include "wtap.h"
13#include <time.h>
14
15#ifdef _WIN32
16#include <winsock2.h>
17#endif
18
19#include <wsutil/array.h>
20#include <wsutil/file_util.h>
21
22#include "wtap_opttypes.h"
23
24void wtap_init_file_type_subtypes(void);
25
26WS_DLL_PUBLIC
27int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err);
28
29typedef bool (*subtype_read_func)(struct wtap*, wtap_rec *,
30 int *, char **, int64_t *);
31typedef bool (*subtype_seek_read_func)(struct wtap*, int64_t, wtap_rec *,
32 int *, char **);
33
37struct wtap {
40 bool ispipe;
41 int file_type_subtype;
42 unsigned snapshot_length;
43 GArray *shb_hdrs;
47 GArray *nrbs;
48 GArray *dsbs;
49 GArray *meta_events;
51 char *pathname;
53 void *priv;
54 void *wslua_data;
56 subtype_read_func subtype_read;
57 subtype_seek_read_func subtype_seek_read;
58 void (*subtype_sequential_close)(struct wtap*);
59 void (*subtype_close)(struct wtap*);
76 wtap_new_ipv4_callback_t add_new_ipv4;
77 wtap_new_ipv6_callback_t add_new_ipv6;
78 wtap_new_secrets_callback_t add_new_secrets;
79 GPtrArray *fast_seek;
80};
81
82struct wtap_dumper;
83
84/*
85 * This could either be a FILE * or a handle used by code that writes
86 * a compressed file.
87 */
88typedef void *WFILE_T;
89
90typedef bool (*subtype_add_idb_func)(struct wtap_dumper*, wtap_block_t,
91 int *, char **);
92
93typedef bool (*subtype_write_func)(struct wtap_dumper*, const wtap_rec*,
94 int*, char**);
95typedef bool (*subtype_finish_func)(struct wtap_dumper*, int*, char**);
96
98 WFILE_T fh;
99 int file_type_subtype;
100 int snaplen;
101 int file_encap; /* per-file, for those
102 * file formats that have
103 * per-file encapsulation
104 * types rather than per-packet
105 * encapsulation types
106 */
107 wtap_compression_type compression_type;
108 bool needs_reload; /* true if the file requires re-loading after saving with wtap */
109 int64_t bytes_dumped;
110
111 void *priv; /* this one holds per-file state and is free'd automatically by wtap_dump_close() */
112 void *wslua_data; /* this one holds wslua state info and is not free'd */
113
114 subtype_add_idb_func subtype_add_idb; /* add an IDB, writing it as necessary */
115 subtype_write_func subtype_write; /* write out a record */
116 subtype_finish_func subtype_finish; /* write out information to finish writing file */
117
119 GArray *shb_hdrs;
120 const GArray *shb_iface_to_global;
122 GArray *dsbs_initial;
124 /*
125 * Additional blocks that might grow as data is being collected.
126 * Subtypes should write these blocks before writing new packet blocks.
127 */
128 const GArray *nrbs_growing;
129 const GArray *dsbs_growing;
130 const GArray *mevs_growing;
134};
135
136WS_DLL_PUBLIC bool wtap_dump_file_write(wtap_dumper *wdh, const void *buf,
137 size_t bufsize, int *err);
138WS_DLL_PUBLIC int64_t wtap_dump_file_seek(wtap_dumper *wdh, int64_t offset, int whence, int *err);
139WS_DLL_PUBLIC int64_t wtap_dump_file_tell(wtap_dumper *wdh, int *err);
140
141extern int wtap_num_file_types;
142
143/* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
144 * they take a pointer to the quantity, and byte-swap it in place.
145 */
146#define PBSWAP64(p) \
147 { \
148 uint8_t tmp; \
149 tmp = (p)[7]; \
150 (p)[7] = (p)[0]; \
151 (p)[0] = tmp; \
152 tmp = (p)[6]; \
153 (p)[6] = (p)[1]; \
154 (p)[1] = tmp; \
155 tmp = (p)[5]; \
156 (p)[5] = (p)[2]; \
157 (p)[2] = tmp; \
158 tmp = (p)[4]; \
159 (p)[4] = (p)[3]; \
160 (p)[3] = tmp; \
161 }
162#define PBSWAP32(p) \
163 { \
164 uint8_t tmp; \
165 tmp = (p)[3]; \
166 (p)[3] = (p)[0]; \
167 (p)[0] = tmp; \
168 tmp = (p)[2]; \
169 (p)[2] = (p)[1]; \
170 (p)[1] = tmp; \
171 }
172#define PBSWAP16(p) \
173 { \
174 uint8_t tmp; \
175 tmp = (p)[1]; \
176 (p)[1] = (p)[0]; \
177 (p)[0] = tmp; \
178 }
179
180/*
181 * Read a given number of bytes from a file into a buffer or, if
182 * buf is NULL, just discard them.
183 *
184 * If we succeed, return true.
185 *
186 * If we get an EOF, return false with *err set to 0, reporting this
187 * as an EOF.
188 *
189 * If we get fewer bytes than the specified number, return false with
190 * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
191 * error.
192 *
193 * If we get a read error, return false with *err and *err_info set
194 * appropriately.
195 */
196WS_DLL_PUBLIC
197bool
198wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err,
199 char **err_info);
200
201/*
202 * Read a given number of bytes from a file into a buffer or, if
203 * buf is NULL, just discard them.
204 *
205 * If we succeed, return true.
206 *
207 * If we get fewer bytes than the specified number, including getting
208 * an EOF, return false with *err set to WTAP_ERR_SHORT_READ, reporting
209 * this as a short read error.
210 *
211 * If we get a read error, return false with *err and *err_info set
212 * appropriately.
213 */
214WS_DLL_PUBLIC
215bool
216wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
217 char **err_info);
218
219/*
220 * Read a given number of bytes from a file into a Buffer, growing the
221 * buffer as necessary.
222 *
223 * This returns an error on a short read, even if the short read hit
224 * the EOF immediately. (The assumption is that each packet has a
225 * header followed by raw packet data, and that we've already read the
226 * header, so if we get an EOF trying to read the packet data, the file
227 * has been cut short, even if the read didn't read any data at all.)
228 */
229WS_DLL_PUBLIC
230bool
231wtap_read_bytes_buffer(FILE_T fh, Buffer *buf, unsigned length, int *err,
232 char **err_info);
233
234/*
235 * Implementation of wth->subtype_read that reads the full file contents
236 * as a single packet.
237 */
238bool
239wtap_full_file_read(wtap *wth, wtap_rec *rec, int *err, char **err_info,
240 int64_t *data_offset);
241
242/*
243 * Implementation of wth->subtype_seek_read that reads the full file contents
244 * as a single packet.
245 */
246bool
247wtap_full_file_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec,
248 int *err, char **err_info);
249
253void
255
259void
261
265void
267
268void
269wtap_register_compatibility_file_subtype_name(const char *old_name,
270 const char *new_name);
271
272void
273wtap_register_backwards_compatibility_lua_name(const char *name, int ft);
274
276 const char *name;
277 int ft;
278};
279
280WS_DLL_PUBLIC
281const GArray *get_backwards_compatibility_lua_table(void);
282
297
309WS_DLL_PUBLIC
311
325
338
350
351#endif /* __WTAP_INT_H__ */
352
353/*
354 * Editor modelines - https://www.wireshark.org/tools/modelines.html
355 *
356 * Local variables:
357 * c-basic-offset: 4
358 * tab-width: 8
359 * indent-tabs-mode: nil
360 * End:
361 *
362 * vi: set shiftwidth=4 tabstop=8 expandtab:
363 * :indentSize=4:tabSize=8:noTabs=true:
364 */
Definition buffer.h:22
Definition wtap.h:1523
Definition wtap-int.h:275
Definition pcapio.c:124
Definition wtap_opttypes.h:229
Definition wtap.h:1544
Definition wtap-int.h:97
unsigned nrbs_growing_written
Definition wtap-int.h:131
GArray * dsbs_initial
Definition wtap-int.h:122
GArray * interface_data
Definition wtap-int.h:121
const GArray * dsbs_growing
Definition wtap-int.h:129
const GArray * mevs_growing
Definition wtap-int.h:130
unsigned mevs_growing_written
Definition wtap-int.h:133
const GArray * shb_iface_to_global
Definition wtap-int.h:120
unsigned dsbs_growing_written
Definition wtap-int.h:132
addrinfo_lists_t * addrinfo_lists
Definition wtap-int.h:118
const GArray * nrbs_growing
Definition wtap-int.h:128
Definition file_wrappers.c:215
Definition wtap.h:1425
Definition wtap-int.h:37
GArray * interface_data
Definition wtap-int.h:45
bool ispipe
Definition wtap-int.h:40
int file_tsprec
Definition wtap-int.h:66
subtype_read_func subtype_read
Definition wtap-int.h:56
GArray * shb_iface_to_global
Definition wtap-int.h:44
subtype_seek_read_func subtype_seek_read
Definition wtap-int.h:57
int file_encap
Definition wtap-int.h:60
FILE_T random_fh
Definition wtap-int.h:39
FILE_T fh
Definition wtap-int.h:38
unsigned next_interface_data
Definition wtap-int.h:46
GArray * nrbs
Definition wtap-int.h:47
char * pathname
Definition wtap-int.h:51
GArray * meta_events
Definition wtap-int.h:49
void * priv
Definition wtap-int.h:53
void * wslua_data
Definition wtap-int.h:54
GArray * dsbs
Definition wtap-int.h:48
void wtapng_process_nrb(wtap *wth, wtap_block_t nrb)
Definition wtap.c:1675
void wtapng_process_dsb(wtap *wth, wtap_block_t dsb)
Definition wtap.c:1699
wtap_block_t wtap_rec_generate_idb(const wtap_rec *rec)
Generate an IDB, given a packet record, using the records's encapsulation type and time stamp resolut...
Definition wtap.c:2014
GArray * wtap_file_get_shb_for_new_file(wtap *wth)
Gets new section header block for new file, based on existing info.
Definition wtap.c:152
wtap_block_t wtap_dump_params_generate_idb(const wtap_dump_params *params)
Generate an IDB, given a set of dump parameters, using the parameters' encapsulation type,...
Definition wtap.c:620
WS_DLL_PUBLIC void wtap_add_generated_idb(wtap *wth)
Generate an IDB, given a wiretap handle for the file, using the file's encapsulation type,...
Definition wtap.c:353
void wtap_add_idb(wtap *wth, wtap_block_t idb)
Definition wtap.c:277
GArray * wtap_file_get_nrb_for_new_file(wtap *wth)
Gets new name resolution info for new file, based on existing info.
Definition wtap.c:523
void(* wtap_new_secrets_callback_t)(uint32_t secrets_type, const void *secrets, unsigned size)
Definition wtap.h:1908
void(* wtap_new_ipv4_callback_t)(const unsigned addr, const char *name, const bool static_entry)
Definition wtap.h:1896