Move prefs.c and prefs.h into the epan subdirectory.
[obnox/wireshark/wip.git] / plugins / enttec / packet-enttec.c
1 /* packet-enttec.c
2  * Routines for ENTTEC packet disassembly
3  *
4  * $Id$
5  *
6  * Copyright (c) 2003 by Erwin Rol <erwin@erwinrol.com>
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1999 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /* Include files */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "plugins/plugin_api.h"
34
35 #include "moduleinfo.h"
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <gmodule.h>
40 #include <ctype.h>
41 #include <time.h>
42 #include <string.h>
43 #include <epan/packet.h>
44 #include <epan/addr_resolv.h>
45 #include <epan/prefs.h>
46 #include <epan/strutil.h>
47
48 #include "plugins/plugin_api_defs.h"
49
50 /* Define version if we are not building ethereal statically */
51
52 #ifndef ENABLE_STATIC
53 G_MODULE_EXPORT const gchar version[] = VERSION;
54 #endif
55
56 /*
57  * See
58  *
59  *      http://www.enttec.com/docs/enttec_protocol.pdf
60  */
61
62 /* Define udp_port for ENTTEC */
63
64 #define UDP_PORT_ENTTEC 0x0D05
65
66 void proto_reg_handoff_enttec(void);
67
68 /* Define the enttec proto */
69 static int proto_enttec = -1;
70
71 /* general */
72 static int hf_enttec_head = -1;
73
74 /* Define the tree for enttec */
75 static int ett_enttec = -1;
76
77 /*
78  * Here are the global variables associated with the preferences
79  * for enttec
80  */
81
82 static guint global_udp_port_enttec = UDP_PORT_ENTTEC;
83 static guint udp_port_enttec = UDP_PORT_ENTTEC;
84
85 /* A static handle for the ip dissector */
86 static dissector_handle_t ip_handle;
87 static dissector_handle_t rdm_handle;
88
89 static void
90 dissect_enttec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
91   gint offset = 0;
92   proto_tree *ti,*enttec_tree=NULL;
93
94   /* Set the protocol column */
95   if(check_col(pinfo->cinfo,COL_PROTOCOL)){
96     col_set_str(pinfo->cinfo,COL_PROTOCOL,"ENTTEC");
97   }
98
99   /* Clear out stuff in the info column */
100   if(check_col(pinfo->cinfo,COL_INFO)){
101     col_clear(pinfo->cinfo,COL_INFO);
102   }
103
104   if (tree) {
105     ti = proto_tree_add_item(tree, proto_enttec, tvb, offset, -1, FALSE);
106     enttec_tree = proto_item_add_subtree(ti, ett_enttec);
107   }
108
109
110   if( enttec_tree ) {
111     proto_tree_add_item(enttec_tree, hf_enttec_head, tvb,
112                         offset, 4, FALSE );
113     offset += 4;
114   }
115 }
116
117 void
118 proto_register_enttec(void) {
119   static hf_register_info hf[] = {
120
121     /* General */
122
123     { &hf_enttec_head,
124       { "Head",
125         "enttec.head",
126         FT_STRING, BASE_HEX, NULL, 0x0,
127         "Head", HFILL }}
128   };
129
130   static gint *ett[] = {
131     &ett_enttec,
132   };
133
134   module_t *enttec_module;
135
136   proto_enttec = proto_register_protocol("ENTTEC",
137                                        "ENTTEC","enttec");
138   proto_register_field_array(proto_enttec,hf,array_length(hf));
139   proto_register_subtree_array(ett,array_length(ett));
140
141   enttec_module = prefs_register_protocol(proto_enttec,
142                                         proto_reg_handoff_enttec);
143   prefs_register_uint_preference(enttec_module, "udp_port",
144                                  "ENTTEC UDP Port",
145                                  "The UDP port on which "
146                                  "ENTTEC "
147                                  "packets will be sent",
148                                  10,&global_udp_port_enttec);
149
150 }
151
152 /* The registration hand-off routing */
153
154 void
155 proto_reg_handoff_enttec(void) {
156   static int enttec_initialized = FALSE;
157   static dissector_handle_t enttec_handle;
158
159   ip_handle = find_dissector("ip");
160   rdm_handle = find_dissector("rdm");
161
162
163   if(!enttec_initialized) {
164     enttec_handle = create_dissector_handle(dissect_enttec,proto_enttec);
165     enttec_initialized = TRUE;
166   } else {
167     dissector_delete("udp.port",udp_port_enttec,enttec_handle);
168   }
169
170   udp_port_enttec = global_udp_port_enttec;
171   
172   dissector_add("udp.port",global_udp_port_enttec,enttec_handle);
173 }
174
175 /* Start the functions we need for the plugin stuff */
176
177 #ifndef ENABLE_STATIC
178
179 G_MODULE_EXPORT void
180 plugin_reg_handoff(void){
181   proto_reg_handoff_enttec();
182 }
183
184 G_MODULE_EXPORT void
185 plugin_init(plugin_address_table_t *pat
186 #ifndef PLUGINS_NEED_ADDRESS_TABLE
187 _U_
188 #endif
189 ){
190   /* initialise the table of pointers needed in Win32 DLLs */
191   plugin_address_table_init(pat);
192   /* register the new protocol, protocol fields, and subtrees */
193   if (proto_enttec == -1) { /* execute protocol initialization only once */
194     proto_register_enttec();
195   }
196 }
197
198 #endif
199
200 /* End the functions we need for plugin stuff */
201