-
Notifications
You must be signed in to change notification settings - Fork 0
/
wireshark-glue.h.template
executable file
·177 lines (139 loc) · 5.88 KB
/
wireshark-glue.h.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef __|GLUE_H_DEFINE_NAME|__
#define __|GLUE_H_DEFINE_NAME|__
#include <string>
#include <list>
extern "C" {
///////////////////////////////////////////////////////////////////////////////////
// Following are definitions that are from wireshark. The necessary headers are
// not included here to minimize dependencies of glue code
//////////////////////////////////////////////////////////////////////////////////
struct tvbuff_t;
struct proto_tree;
struct proto_item;
// Following enum should match wireshark/epan/ftypes/ftypes.h
enum ftenum {
FT_NONE, /* used for text labels with no value */
FT_PROTOCOL,
FT_BOOLEAN, /* TRUE and FALSE come from <glib.h> */
FT_UINT8,
FT_UINT16,
FT_UINT24, /* really a UINT32, but displayed as 3 hex-digits if FD_HEX*/
FT_UINT32,
FT_UINT64,
FT_INT8,
FT_INT16,
FT_INT24, /* same as for UINT24 */
FT_INT32,
FT_INT64,
FT_FLOAT,
FT_DOUBLE,
FT_ABSOLUTE_TIME,
FT_RELATIVE_TIME,
FT_STRING
};
extern proto_item* proto_tree_add_item( void *tree, int handle, void * tvb,
int offset, int length, bool b );
extern proto_item* proto_tree_add_none_format( void *tree, int handle, void * tvb,
int offset, int length, const char* format, ...);
extern proto_item* proto_tree_add_uint( void *tree, int handle, void * tvb,
int offset, int length, unsigned int b );
extern proto_item* proto_tree_add_uint64( void *tree, int handle, void * tvb,
int offset, int length, unsigned long long b );
extern proto_item* proto_tree_add_int( void *tree, int handle, void * tvb,
int offset, int length, int b );
extern proto_item* proto_tree_add_int64( void *tree, int handle, void * tvb,
int offset, int length, long long b );
extern proto_item* proto_tree_add_float( void *tree, int handle, void * tvb,
int offset, int length, float b );
extern proto_item* proto_tree_add_double( void *tree, int handle, void * tvb,
int offset, int length, double b );
extern proto_item* proto_tree_add_boolean( void *tree, int handle, void * tvb,
int offset, int length, unsigned b );
extern proto_item* proto_tree_add_text( void *tree, void * tvb,
int offset, int length, const char* b, ... );
extern proto_item* proto_tree_add_int_format_value(void *tree, int handle,
void *tvb, int offset,
int length, int value,
const char *format, ...);
extern proto_item* proto_tree_add_string( void *tree, int handle, void *tvb,
int offset, int length,
const char* value );
extern proto_tree* proto_item_add_subtree( void * item, int tree_handle );
// end of wireshark definitions
///////////////////////////////////////////////////////////////////////////////////
// following functions are implemented in packet-|PLUGIN|.c code
//////////////////////////////////////////////////////////////////////////////////
extern int wireshark_pb_add_|PLUGIN_NAME|(void* tree_root, void *tvb, int item_id, char* msg_str);
extern void wireshark_pb_process_|PLUGIN_NAME|_register_subtree( int proto, const char* name,
int *handle, int ** tree_handle );
extern void wireshark_pb_process_|PLUGIN_NAME|_register_field( int proto, int type,
const char* name, const char * fullName,
int *handle );
///////////////////////////////////////////////////////////////////////////////////
// rest of definitions are specific to the glue file
//////////////////////////////////////////////////////////////////////////////////
//fwd declarations
namespace google
{
namespace protobuf
{
class Descriptor;
class FieldDescriptor;
class Message;
class Reflection;
}
}
class |PLUGIN_NAME|_Dissector;
struct Handles;
typedef std::pair<std::string, Handles> StringHandlePair;
typedef std::map<std::string, Handles> HandleMap;
typedef std::vector<const google::protobuf::Descriptor*> DescriptorList;
typedef std::vector<const google::protobuf::FieldDescriptor*> FieldDescriptorList;
typedef std::list<|PLUGIN_NAME|_Dissector> DissectorList;
// this is the main dissector class which hold context during dissection of message
class |PLUGIN_NAME|_Dissector
{
public: // methods
// default ctor to satisfy std::list
|PLUGIN_NAME|_Dissector();
// actual ctor that is used
|PLUGIN_NAME|_Dissector( proto_tree* tree, int offset,
const google::protobuf::Message* mess,
const google::protobuf::FieldDescriptor* field, int index = -1 );
// main dissect method
void dissect( DissectorList& list );
protected: // methods
// dissect a basic field
void dissectField( const google::protobuf::FieldDescriptor* field );
// dissect a repeated field
void dissectRepeatedField( const google::protobuf::FieldDescriptor* field, int index );
// returns total length of message as seen in byte stream
// this will be data size + encoding length of tag + data_size length
int messageLength()
{
return _len;
}
private: // data
// the leaf tree for this message and subfields
proto_tree* _leaf;
// total length of message including overhead
int _len;
// message pointer
const google::protobuf::Message* _message;
// offset into tvb
int _offset;
// size of overhead
int _prefix_len;
// reflection pointer cache
const google::protobuf::Reflection* _reflection;
};
typedef struct Handles
{
int handle;
int * tree_handle;
Handles() : handle( -1 ), tree_handle( NULL ) {}
} Handles;
#define DBG( x ) { std::cout << x << std::endl; }
#define DBG_ERR( x ) { std::cerr << x << std::endl; }
} // of extern "C"
#endif