Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
wtap_opttypes.h
1 /* wtap_opttypes.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 2001 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef WTAP_OPT_TYPES_H
11 #define WTAP_OPT_TYPES_H
12 
13 #include "ws_symbol_export.h"
14 
15 #include <wsutil/inet_ipv6.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20 
21 /*
22  * We use the pcapng option codes for option type values.
23  */
24 
25 /* Options for all blocks */
26 #define OPT_EOFOPT 0
27 #define OPT_COMMENT 1
29 /* Section Header block (SHB) */
30 #define OPT_SHB_HARDWARE 2
33 #define OPT_SHB_OS 3
36 #define OPT_SHB_USERAPPL 4
40 /* Interface Description block (IDB) */
41 #define OPT_IDB_NAME 2
45 #define OPT_IDB_DESCR 3
49 #define OPT_IDB_IP4ADDR 4
54 #define OPT_IDB_IP6ADDR 5 /* XXX: if_IPv6addr Interface network address and prefix length (stored in the last byte).
55  * This option can be repeated multiple times within the same Interface
56  * Description Block when multiple IPv6 addresses are assigned to the interface.
57  * 2001:0db8:85a3:08d3:1319:8a2e:0370:7344/64 is written (in hex) as
58  * "20 01 0d b8 85 a3 08 d3 13 19 8a 2e 03 70 73 44 40"*/
59 #define OPT_IDB_MACADDR 6 /* XXX: if_MACaddr Interface Hardware MAC address (48 bits). */
60 #define OPT_IDB_EUIADDR 7 /* XXX: if_EUIaddr Interface Hardware EUI address (64 bits) */
61 #define OPT_IDB_SPEED 8
63 #define OPT_IDB_TSRESOL 9
72 #define OPT_IDB_TZONE 10 /* XXX: if_tzone Time zone for GMT support (TODO: specify better). */
73 #define OPT_IDB_FILTER 11
80 #define OPT_IDB_OS 12
88 #define OPT_IDB_FCSLEN 13
93 #define OPT_IDB_TSOFFSET 14
102 #define OPT_NS_DNSNAME 2
103 #define OPT_NS_DNSIP4ADDR 3
104 #define OPT_NS_DNSIP6ADDR 4
105 
106 #define OPT_ISB_STARTTIME 2
107 #define OPT_ISB_ENDTIME 3
108 #define OPT_ISB_IFRECV 4
109 #define OPT_ISB_IFDROP 5
110 #define OPT_ISB_FILTERACCEPT 6
111 #define OPT_ISB_OSDROP 7
112 #define OPT_ISB_USRDELIV 8
113 
114 struct wtap_block;
115 typedef struct wtap_block *wtap_block_t;
116 
117 /*
118  * Currently supported blocks; these are not the pcapng block type values
119  * for them, they're identifiers used internally.
120  */
121 typedef enum {
122  WTAP_BLOCK_NG_SECTION = 0,
123  WTAP_BLOCK_IF_DESCR,
124  WTAP_BLOCK_NG_NRB,
125  WTAP_BLOCK_IF_STATS,
126  WTAP_BLOCK_END_OF_LIST
127 } wtap_block_type_t;
128 
129 /* Currently supported option types */
130 typedef enum {
131  WTAP_OPTTYPE_UINT8,
132  WTAP_OPTTYPE_UINT64,
133  WTAP_OPTTYPE_STRING,
134  WTAP_OPTTYPE_IPv4,
135  WTAP_OPTTYPE_IPv6,
136  WTAP_OPTTYPE_CUSTOM
137 } wtap_opttype_e;
138 
139 typedef enum {
140  WTAP_OPTTYPE_SUCCESS = 0,
141  WTAP_OPTTYPE_NO_SUCH_OPTION = -1,
142  WTAP_OPTTYPE_NOT_FOUND = -2,
143  WTAP_OPTTYPE_TYPE_MISMATCH = -3,
144  WTAP_OPTTYPE_NUMBER_MISMATCH = -4,
145  WTAP_OPTTYPE_ALREADY_EXISTS = -5
146 } wtap_opttype_return_val;
147 
148 struct wtap_opttype_custom
149 {
150  void* data;
151  guint size;
152 };
153 
154 /*
155  * Structure describing a value of an option.
156  */
157 typedef union {
158  guint8 uint8val;
159  guint64 uint64val;
160  guint32 ipv4val; /* network byte order */
161  ws_in6_addr ipv6val;
162  char *stringval;
163  struct wtap_opttype_custom customval;
164 } wtap_optval_t;
165 
166 /*
167  * Structure describing an option in a block.
168  */
169 typedef struct {
170  guint option_id;
171  wtap_optval_t value;
172 } wtap_option_t;
173 
174 struct wtap_dumper;
175 
176 typedef void (*wtap_block_create_func)(wtap_block_t block);
177 typedef void (*wtap_mand_free_func)(wtap_block_t block);
178 typedef void (*wtap_mand_copy_func)(wtap_block_t dest_block, wtap_block_t src_block);
179 
186 WS_DLL_PUBLIC void wtap_opttypes_initialize(void);
187 
195 WS_DLL_PUBLIC wtap_block_t wtap_block_create(wtap_block_type_t block_type);
196 
203 WS_DLL_PUBLIC void wtap_block_free(wtap_block_t block);
204 
213 WS_DLL_PUBLIC void wtap_block_array_free(GArray* block_array);
214 
220 WS_DLL_PUBLIC void* wtap_block_get_mandatory_data(wtap_block_t block);
221 
230 WS_DLL_PUBLIC wtap_opttype_return_val
231 wtap_block_add_uint8_option(wtap_block_t block, guint option_id, guint8 value);
232 
241 WS_DLL_PUBLIC wtap_opttype_return_val
242 wtap_block_set_uint8_option_value(wtap_block_t block, guint option_id, guint8 value);
243 
252 WS_DLL_PUBLIC wtap_opttype_return_val
253 wtap_block_get_uint8_option_value(wtap_block_t block, guint option_id, guint8* value) G_GNUC_WARN_UNUSED_RESULT;
254 
263 WS_DLL_PUBLIC wtap_opttype_return_val
264 wtap_block_add_uint64_option(wtap_block_t block, guint option_id, guint64 value);
265 
274 WS_DLL_PUBLIC wtap_opttype_return_val
275 wtap_block_set_uint64_option_value(wtap_block_t block, guint option_id, guint64 value);
276 
285 WS_DLL_PUBLIC wtap_opttype_return_val
286 wtap_block_get_uint64_option_value(wtap_block_t block, guint option_id, guint64* value) G_GNUC_WARN_UNUSED_RESULT;
287 
296 WS_DLL_PUBLIC wtap_opttype_return_val
297 wtap_block_add_ipv4_option(wtap_block_t block, guint option_id, guint32 value);
298 
307 WS_DLL_PUBLIC wtap_opttype_return_val
308 wtap_block_set_ipv4_option_value(wtap_block_t block, guint option_id, guint32 value);
309 
318 WS_DLL_PUBLIC wtap_opttype_return_val
319 wtap_block_get_ipv4_option_value(wtap_block_t block, guint option_id, guint32* value) G_GNUC_WARN_UNUSED_RESULT;
320 
329 WS_DLL_PUBLIC wtap_opttype_return_val
330 wtap_block_add_ipv6_option(wtap_block_t block, guint option_id, ws_in6_addr *value);
331 
340 WS_DLL_PUBLIC wtap_opttype_return_val
341 wtap_block_set_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr *value);
342 
351 WS_DLL_PUBLIC wtap_opttype_return_val
352 wtap_block_get_ipv6_option_value(wtap_block_t block, guint option_id, ws_in6_addr* value) G_GNUC_WARN_UNUSED_RESULT;
353 
363 WS_DLL_PUBLIC wtap_opttype_return_val
364 wtap_block_add_string_option(wtap_block_t block, guint option_id, const char *value, gsize value_length);
365 
374 WS_DLL_PUBLIC wtap_opttype_return_val
375 wtap_block_add_string_option_format(wtap_block_t block, guint option_id, const char *format, ...)
376  G_GNUC_PRINTF(3,4);
377 
387 WS_DLL_PUBLIC wtap_opttype_return_val
388 wtap_block_set_string_option_value(wtap_block_t block, guint option_id, const char* value, gsize value_length);
389 
400 WS_DLL_PUBLIC wtap_opttype_return_val
401 wtap_block_set_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, const char* value, gsize value_length);
402 
411 WS_DLL_PUBLIC wtap_opttype_return_val
412 wtap_block_set_string_option_value_format(wtap_block_t block, guint option_id, const char *format, ...)
413  G_GNUC_PRINTF(3,4);
414 
423 WS_DLL_PUBLIC wtap_opttype_return_val
424 wtap_block_get_string_option_value(wtap_block_t block, guint option_id, char** value) G_GNUC_WARN_UNUSED_RESULT;
425 
435 WS_DLL_PUBLIC wtap_opttype_return_val
436 wtap_block_get_nth_string_option_value(wtap_block_t block, guint option_id, guint idx, char** value) G_GNUC_WARN_UNUSED_RESULT;
437 
447 WS_DLL_PUBLIC wtap_opttype_return_val
448 wtap_block_add_custom_option(wtap_block_t block, guint option_id, void* value, size_t value_size);
449 
458 WS_DLL_PUBLIC wtap_opttype_return_val
459 wtap_block_set_custom_option_value(wtap_block_t block, guint option_id, void* value);
460 
469 WS_DLL_PUBLIC wtap_opttype_return_val
470 wtap_block_get_custom_option_value(wtap_block_t block, guint option_id, void** value) G_GNUC_WARN_UNUSED_RESULT;
471 
479 WS_DLL_PUBLIC wtap_opttype_return_val
480 wtap_block_remove_option(wtap_block_t block, guint option_id);
481 
490 WS_DLL_PUBLIC wtap_opttype_return_val
491 wtap_block_remove_nth_option_instance(wtap_block_t block, guint option_id,
492  guint idx);
493 
502 WS_DLL_PUBLIC void wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block);
503 
504 
505 typedef void (*wtap_block_foreach_func)(wtap_block_t block, guint option_id, wtap_opttype_e option_type, wtap_optval_t *option, void *user_data);
506 WS_DLL_PUBLIC void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data);
507 
508 WS_DLL_PUBLIC int wtap_opttype_register_custom_block_type(const char* name, const char* description, wtap_block_create_func create,
509  wtap_mand_free_func free_mand, wtap_mand_copy_func copy_mand);
510 
513 WS_DLL_PUBLIC void wtap_opttypes_cleanup(void);
514 
515 #ifdef __cplusplus
516 }
517 #endif /* __cplusplus */
518 
519 #endif /* WTAP_OPT_TYPES_H */
520 
Definition: wtap_opttypes.h:206
Definition: inet_ipv6.h:20
Definition: wtap_opttypes.c:57
Definition: wtap_opttypes.h:218
Definition: pcapng.c:148
Definition: wtap_opttypes.h:197
Definition: wtap-int.h:86