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