-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.c.template
executable file
·176 lines (133 loc) · 5.01 KB
/
packet.c.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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gmodule.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/emem.h>
#include <string.h>
/* forward reference */
void proto_register_|PLUGIN_NAME|();
void proto_reg_handoff_|PLUGIN_NAME|();
static void dissect_|PLUGIN_NAME|(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
/* Define version if we are not building ethereal statically */
#ifndef ENABLE_STATIC
G_MODULE_EXPORT const gchar version[] = "0.0";
#endif
static int proto_|PLUGIN_NAME| = -1;
static int global_|PLUGIN_NAME|_udp_ports[] =
{
|PORT_NUM|
};
static dissector_handle_t |PLUGIN_NAME|_handle;
// Protocol field variables - START
static int hf_|PLUGIN_NAME| = -1;
// Protocol field variables - END
int wireshark_pb_process_|PLUGIN_NAME|(void *tree_root, int item_id, void *tvb, void *buf, int buf_size);
void wireshark_pb_process_|PLUGIN_NAME|_register_proto( int proto );
void wireshark_pb_process_|PLUGIN_NAME|_register_subtree( int proto, const char* name,
int *handle, int ** tree_handle );
void wireshark_pb_process_|PLUGIN_NAME|_register_field( int proto, int type,
const char* name, const char * fullName,
int *handle );
/* Register plugin - START */
#ifndef ENABLE_STATIC
G_MODULE_EXPORT void
plugin_register(void) {
/* register the new protocol, protocol fields, and subtrees */
if (proto_|PLUGIN_NAME| == -1) { /* execute protocol initialization only once */
proto_register_|PLUGIN_NAME|();
}
}
G_MODULE_EXPORT void
plugin_reg_handoff(void){
proto_reg_handoff_|PLUGIN_NAME|();
}
#endif
void proto_register_|PLUGIN_NAME|(void) {
module_t *|PLUGIN_NAME|_module;
if (proto_|PLUGIN_NAME| == -1) {
proto_|PLUGIN_NAME| = proto_register_protocol (
"|PLUGIN_NAME|-D ",/* name */
"|PLUGIN_NAME|",/* short name */
"|PLUGIN_NAME_LOWER|"/* abbrev */
);
}
|PLUGIN_NAME|_module= prefs_register_protocol(proto_|PLUGIN_NAME|, proto_reg_handoff_|PLUGIN_NAME|);
wireshark_pb_process_|PLUGIN_NAME|_register_proto( proto_|PLUGIN_NAME| );
}
void proto_reg_handoff_|PLUGIN_NAME| (void) {
static int Initialized=FALSE;
unsigned int i = 0;
if (!Initialized) {
|PLUGIN_NAME|_handle = create_dissector_handle(dissect_|PLUGIN_NAME|, proto_|PLUGIN_NAME|);
for( ; i < ( sizeof( global_|PLUGIN_NAME|_udp_ports ) / sizeof( global_|PLUGIN_NAME|_udp_ports[0] ) ); i++) {
dissector_add("udp.port", global_|PLUGIN_NAME|_udp_ports[i], |PLUGIN_NAME|_handle);
}
}
}
/* Register plugin - END */
/* Generate the main dissector function - START */
static void dissect_|PLUGIN_NAME| (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
col_set_str(pinfo->cinfo, COL_PROTOCOL, "|PLUGIN_NAME|");
}
/* Clear out stuff in the info column */
if(check_col(pinfo->cinfo,COL_INFO)){
col_clear(pinfo->cinfo,COL_INFO);
}
if (tree) { /* we are being asked for details */
/* Always make sure that offset is LESS than maxOffset */
gint maxOffset = tvb_length(tvb);
wireshark_pb_process_|PLUGIN_NAME|((void *) tree, hf_|PLUGIN_NAME|,
(void *)tvb, (void *)tvb_get_ptr(tvb,0,maxOffset), maxOffset);
}
} //dissect_|PLUGIN_NAME|
/* Generate the main dissector function - END */
/** Called from PB to add msg_str to tree_root */
int wireshark_pb_add_|PLUGIN_NAME|(void* tree_root, void* tvb, int item_id, char* msg_str) {
proto_tree_add_none_format ((proto_tree *) tree_root, item_id, (tvbuff_t*) tvb, 0, -1, msg_str);
return 0;
}
void wireshark_pb_process_|PLUGIN_NAME|_register_subtree( int proto, const char* name,
int *handle, int ** p_tree_handle )
{
hf_register_info message_info =
{ handle,
{ (char*)name,
(char*)name,
FT_NONE,
BASE_NONE,
NULL, 0,
"",
HFILL
}
};
int * tree_handle;
hf_register_info *hf_info = malloc(sizeof( hf_register_info ) );
*hf_info = message_info;
proto_register_field_array( proto, hf_info, 1 );
tree_handle = malloc( sizeof(int) );
proto_register_subtree_array( &tree_handle, 1 );
*p_tree_handle = tree_handle;
}
void wireshark_pb_process_|PLUGIN_NAME|_register_field( int proto, int type,
const char* name, const char * fullName,
int *handle )
{
int base = ((type == FT_UINT32) || (type == FT_UINT64) ) ? BASE_HEX : ( type == FT_INT32) ? BASE_DEC : BASE_NONE;
hf_register_info message_info =
{ handle,
{ (char*)fullName,
(char*)name,
type,
base,
NULL, 0,
"",
HFILL
}
};
hf_register_info *hf_info = malloc(sizeof( hf_register_info ) );
*hf_info = message_info;
proto_register_field_array( proto, hf_info, 1 );
}