attr_dissector_fn_t
[wireshark-sm.git] / epan / capture_dissectors.h
blobebbe23d9ed6a7304210b46ed870efa5fa0b0c87e
1 /* capture_dissectors.h
2 * Routines for handling capture dissectors
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #ifndef __CAPTURE_DISSECTORS_H__
12 #define __CAPTURE_DISSECTORS_H__
14 #include "ws_symbol_export.h"
15 #include <wiretap/wtap.h>
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
21 /** @file
24 /** Table of counts of packets of various types. */
25 typedef struct {
26 GHashTable* counts_hash; /* packet counters keyed by proto */
27 int other; /* Packets not counted in the hash total */
28 int total; /* Cache of total packets */
29 } packet_counts;
31 typedef struct _capture_packet_info {
32 GHashTable *counts;
33 } capture_packet_info_t;
35 typedef struct capture_dissector_handle* capture_dissector_handle_t;
37 /** callback function definition for capture dissectors */
38 typedef bool (*capture_dissector_t)(const uint8_t *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header);
40 /* a protocol uses the function to register a capture sub-dissector table
41 * @param[in] name Name of capture sub-dissector table.
42 * @param[in] ui_name Name string used when referring to capture sub-dissector table in UI.
44 WS_DLL_PUBLIC void register_capture_dissector_table(const char *name, const char *ui_name);
46 /* Create an anonymous handle for a capture dissector
47 * @param[in] dissector capture dissector function.
48 * @param[in] proto Protocol associated with capture dissector function.
49 * @return Handle created for capture dissector
51 WS_DLL_PUBLIC capture_dissector_handle_t create_capture_dissector_handle(capture_dissector_t dissector, const int proto);
53 /* Find a dissector by name
54 * @param[in] name Name of capture dissector
55 * @return Handle for capture dissector if found, NULL otherwise
57 WS_DLL_PUBLIC capture_dissector_handle_t find_capture_dissector(const char *name);
59 /* Register a new capture dissector
60 * @param[in] name Name of capture dissector function.
61 * @param[in] dissector capture dissector function.
62 * @param[in] proto Protocol associated with capture dissector function.
63 * @return Handle created for capture dissector
65 WS_DLL_PUBLIC capture_dissector_handle_t register_capture_dissector(const char *name, capture_dissector_t dissector, int proto);
67 /* Add an entry to a uint capture dissector table
68 * @param[in] name Name of capture dissector table
69 * @param[in] pattern Numerical value associated with capture dissector
70 * @param[in] handle Handle to capture dissector
72 WS_DLL_PUBLIC void capture_dissector_add_uint(const char *name, const uint32_t pattern, capture_dissector_handle_t handle);
74 /* Look for a given value in a given uint capture dissector table and, if found,
75 * call the dissector with the arguments supplied, and return true,
76 * otherwise return false
77 * @param[in] name Name of capture dissector table
78 * @param[in] pattern Numerical value associated with capture dissector
79 * @param[in] pd Data buffer of captured bytes
80 * @param[in] offset Current offset into pd
81 * @param[in] len Length of pd
82 * @param[in] cpinfo Capture statistics
83 * @param[in] pseudo_header Wiretap pseudo header information
85 WS_DLL_PUBLIC bool try_capture_dissector(const char* name, const uint32_t pattern, const uint8_t *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header);
87 /* Call a capture dissector through a handle. If handle is value return true,
88 * otherwise return false
89 * @param[in] handle Capture dissector handle
90 * @param[in] pd Data buffer of captured bytes
91 * @param[in] offset Current offset into pd
92 * @param[in] len Length of pd
93 * @param[in] cpinfo Capture statistics
94 * @param[in] pseudo_header Wiretap pseudo header information
96 WS_DLL_PUBLIC bool call_capture_dissector(capture_dissector_handle_t handle, const uint8_t *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header);
98 /* Get current capture packet count for a particular protocol
99 * @param[in] counts Packet count structure
100 * @param[in] proto Protocol to retrieve packet count from
101 * @return Number of packets captured for a particular protocol
103 WS_DLL_PUBLIC uint32_t capture_dissector_get_count(packet_counts* counts, const int proto);
105 /* Increment packet capture count by 1 for a particular protocol.
106 * @param[in] cpinfo Capture statistics
107 * @param[in] proto Protocol to increment packet count
109 WS_DLL_PUBLIC void capture_dissector_increment_count(capture_packet_info_t *cpinfo, const int proto);
111 extern void capture_dissector_init(void);
112 extern void capture_dissector_cleanup(void);
114 #ifdef __cplusplus
116 #endif /* __cplusplus */
118 #endif /* capture_dissectors.h */