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;
50 GArray *dpibs;
51 unsigned next_dpib_id;
52 char *pathname;
54 void *priv;
55 void *wslua_data;
57 subtype_read_func subtype_read;
58 subtype_seek_read_func subtype_seek_read;
59 void (*subtype_sequential_close)(struct wtap*);
60 void (*subtype_close)(struct wtap*);
89 wtap_new_ipv4_callback_t add_new_ipv4;
90 wtap_new_ipv6_callback_t add_new_ipv6;
91 wtap_new_secrets_callback_t add_new_secrets;
92 GPtrArray *fast_seek;
93};
94
95struct wtap_dumper;
96
97/*
98 * This could either be a FILE * or a handle used by code that writes
99 * a compressed file.
100 */
101typedef void *WFILE_T;
102
103typedef bool (*subtype_add_idb_func)(struct wtap_dumper*, wtap_block_t,
104 int *, char **);
105
106typedef bool (*subtype_write_func)(struct wtap_dumper*, const wtap_rec*,
107 int*, char**);
108typedef bool (*subtype_finish_func)(struct wtap_dumper*, int*, char**);
109
111 WFILE_T fh;
112 int file_type_subtype;
113 int snaplen;
114 int file_encap; /* per-file, for those
115 * file formats that have
116 * per-file encapsulation
117 * types rather than per-packet
118 * encapsulation types
119 */
120 ws_compression_type compression_type;
121 bool needs_reload; /* true if the file requires re-loading after saving with wtap */
122 int64_t bytes_dumped;
123
124 void *priv; /* this one holds per-file state and is free'd automatically by wtap_dump_close() */
125 void *wslua_data; /* this one holds wslua state info and is not free'd */
126
127 subtype_add_idb_func subtype_add_idb; /* add an IDB, writing it as necessary */
128 subtype_write_func subtype_write; /* write out a record */
129 subtype_finish_func subtype_finish; /* write out information to finish writing file */
130
132 GArray *shb_hdrs;
133 const GArray *shb_iface_to_global;
135 GArray *dsbs_initial;
137 /*
138 * Additional blocks that might grow as data is being collected.
139 * Subtypes should write these blocks before writing new packet blocks.
140 */
141 const GArray *nrbs_growing;
142 const GArray *dsbs_growing;
143 const GArray *mevs_growing;
144 const GArray *dpibs_growing;
149};
150
151WS_DLL_PUBLIC bool wtap_dump_file_write(wtap_dumper *wdh, const void *buf,
152 size_t bufsize, int *err);
153WS_DLL_PUBLIC int64_t wtap_dump_file_seek(wtap_dumper *wdh, int64_t offset, int whence, int *err);
154WS_DLL_PUBLIC int64_t wtap_dump_file_tell(wtap_dumper *wdh, int *err);
155
156extern int wtap_num_file_types;
157
158/* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
159 * they take a pointer to the quantity, and byte-swap it in place.
160 */
161#define PBSWAP64(p) \
162 { \
163 uint8_t tmp; \
164 tmp = (p)[7]; \
165 (p)[7] = (p)[0]; \
166 (p)[0] = tmp; \
167 tmp = (p)[6]; \
168 (p)[6] = (p)[1]; \
169 (p)[1] = tmp; \
170 tmp = (p)[5]; \
171 (p)[5] = (p)[2]; \
172 (p)[2] = tmp; \
173 tmp = (p)[4]; \
174 (p)[4] = (p)[3]; \
175 (p)[3] = tmp; \
176 }
177#define PBSWAP32(p) \
178 { \
179 uint8_t tmp; \
180 tmp = (p)[3]; \
181 (p)[3] = (p)[0]; \
182 (p)[0] = tmp; \
183 tmp = (p)[2]; \
184 (p)[2] = (p)[1]; \
185 (p)[1] = tmp; \
186 }
187#define PBSWAP16(p) \
188 { \
189 uint8_t tmp; \
190 tmp = (p)[1]; \
191 (p)[1] = (p)[0]; \
192 (p)[0] = tmp; \
193 }
194
195/*
196 * Read a given number of bytes from a file into a buffer or, if
197 * buf is NULL, just discard them.
198 *
199 * If we succeed, return true.
200 *
201 * If we get an EOF, return false with *err set to 0, reporting this
202 * as an EOF.
203 *
204 * If we get fewer bytes than the specified number, return false with
205 * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
206 * error.
207 *
208 * If we get a read error, return false with *err and *err_info set
209 * appropriately.
210 */
211WS_DLL_PUBLIC
212bool
213wtap_read_bytes_or_eof(FILE_T fh, void *buf, unsigned int count, int *err,
214 char **err_info);
215
216/*
217 * Read a given number of bytes from a file into a buffer or, if
218 * buf is NULL, just discard them.
219 *
220 * If we succeed, return true.
221 *
222 * If we get fewer bytes than the specified number, including getting
223 * an EOF, return false with *err set to WTAP_ERR_SHORT_READ, reporting
224 * this as a short read error.
225 *
226 * If we get a read error, return false with *err and *err_info set
227 * appropriately.
228 */
229WS_DLL_PUBLIC
230bool
231wtap_read_bytes(FILE_T fh, void *buf, unsigned int count, int *err,
232 char **err_info);
233
234/*
235 * Read a given number of bytes from a file into a Buffer, growing the
236 * buffer as necessary.
237 *
238 * This returns an error on a short read, even if the short read hit
239 * the EOF immediately. (The assumption is that each packet has a
240 * header followed by raw packet data, and that we've already read the
241 * header, so if we get an EOF trying to read the packet data, the file
242 * has been cut short, even if the read didn't read any data at all.)
243 */
244WS_DLL_PUBLIC
245bool
246wtap_read_bytes_buffer(FILE_T fh, Buffer *buf, unsigned length, int *err,
247 char **err_info);
248
249/*
250 * Implementation of wth->subtype_read that reads the full file contents
251 * as a single packet.
252 */
253bool
254wtap_full_file_read(wtap *wth, wtap_rec *rec, int *err, char **err_info,
255 int64_t *data_offset);
256
257/*
258 * Implementation of wth->subtype_seek_read that reads the full file contents
259 * as a single packet.
260 */
261bool
262wtap_full_file_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec,
263 int *err, char **err_info);
264
268void
270
274 void
275 wtap_add_dpib(wtap *wth, wtap_block_t dpib);
276
280void
282
286void
288
289void
290wtap_register_compatibility_file_subtype_name(const char *old_name,
291 const char *new_name);
292
293void
294wtap_register_backwards_compatibility_lua_name(const char *name, int ft);
295
297 const char *name;
298 int ft;
299};
300
301WS_DLL_PUBLIC
302const GArray *get_backwards_compatibility_lua_table(void);
303
318
330WS_DLL_PUBLIC
332
346
359
371
372#endif /* __WTAP_INT_H__ */
373
374/*
375 * Editor modelines - https://www.wireshark.org/tools/modelines.html
376 *
377 * Local variables:
378 * c-basic-offset: 4
379 * tab-width: 8
380 * indent-tabs-mode: nil
381 * End:
382 *
383 * vi: set shiftwidth=4 tabstop=8 expandtab:
384 * :indentSize=4:tabSize=8:noTabs=true:
385 */
Definition buffer.h:22
Definition wtap.h:1539
Definition wtap-int.h:296
Definition pcapio.c:117
Definition nstime.h:26
Definition wtap_opttypes.h:272
Definition wtap.h:1560
Definition wtap-int.h:110
unsigned dpibs_growing_written
Definition wtap-int.h:148
unsigned nrbs_growing_written
Definition wtap-int.h:145
GArray * dsbs_initial
Definition wtap-int.h:135
GArray * interface_data
Definition wtap-int.h:134
const GArray * dsbs_growing
Definition wtap-int.h:142
const GArray * mevs_growing
Definition wtap-int.h:143
unsigned mevs_growing_written
Definition wtap-int.h:147
const GArray * shb_iface_to_global
Definition wtap-int.h:133
const GArray * dpibs_growing
Definition wtap-int.h:144
unsigned dsbs_growing_written
Definition wtap-int.h:146
addrinfo_lists_t * addrinfo_lists
Definition wtap-int.h:131
const GArray * nrbs_growing
Definition wtap-int.h:141
Definition file_wrappers.c:97
Definition wtap.h:1443
Definition wtap-int.h:37
GArray * interface_data
Definition wtap-int.h:45
bool ispipe
Definition wtap-int.h:40
nstime_t file_start_ts
Definition wtap-int.h:77
unsigned next_dpib_id
Definition wtap-int.h:51
int file_tsprec
Definition wtap-int.h:67
subtype_read_func subtype_read
Definition wtap-int.h:57
nstime_t file_end_ts
Definition wtap-int.h:83
GArray * shb_iface_to_global
Definition wtap-int.h:44
subtype_seek_read_func subtype_seek_read
Definition wtap-int.h:58
int file_encap
Definition wtap-int.h:61
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
GArray * dpibs
Definition wtap-int.h:50
char * pathname
Definition wtap-int.h:52
GArray * meta_events
Definition wtap-int.h:49
void * priv
Definition wtap-int.h:54
void * wslua_data
Definition wtap-int.h:55
GArray * dsbs
Definition wtap-int.h:48
void wtapng_process_nrb(wtap *wth, wtap_block_t nrb)
Definition wtap.c:1710
void wtapng_process_dsb(wtap *wth, wtap_block_t dsb)
Definition wtap.c:1734
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:2049
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:164
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:651
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:382
void wtap_add_dpib(wtap *wth, wtap_block_t dpib)
Definition wtap.c:306
void wtap_add_idb(wtap *wth, wtap_block_t idb)
Definition wtap.c:300
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:552
void(* wtap_new_secrets_callback_t)(uint32_t secrets_type, const void *secrets, unsigned size)
Definition wtap.h:1927
void(* wtap_new_ipv4_callback_t)(const unsigned addr, const char *name, const bool static_entry)
Definition wtap.h:1915