Add data parameter to call_dissector_only.
[metze/wireshark/wip.git] / epan / packet.c
1 /* packet.c
2  * Routines for packet disassembly
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30
31 #include <stdio.h>
32 #include <stdlib.h>
33
34 #ifdef HAVE_STDARG_H
35 #include <stdarg.h>
36 #endif
37
38 #include <string.h>
39 #include <ctype.h>
40 #include <time.h>
41
42 #include "packet.h"
43 #include "timestamp.h"
44
45 #include "atalk-utils.h"
46 #include "sna-utils.h"
47 #include "osi-utils.h"
48 #include "to_str.h"
49
50 #include "addr_resolv.h"
51 #include "tvbuff.h"
52 #include "plugins.h"
53 #include "epan_dissect.h"
54
55 #include "emem.h"
56
57 #include <epan/reassemble.h>
58 #include <epan/stream.h>
59 #include <epan/expert.h>
60
61 static gint proto_malformed = -1;
62 static dissector_handle_t frame_handle = NULL;
63 static dissector_handle_t data_handle = NULL;
64
65 void
66 packet_init(void)
67 {
68         frame_handle = find_dissector("frame");
69         data_handle = find_dissector("data");
70         proto_malformed = proto_get_id_by_filter_name("malformed");
71 }
72
73 void
74 packet_cleanup(void)
75 {
76         /* nothing */
77 }
78
79 /*
80  * Given a tvbuff, and a length from a packet header, adjust the length
81  * of the tvbuff to reflect the specified length.
82  */
83 void
84 set_actual_length(tvbuff_t *tvb, const guint specified_len)
85 {
86         if (specified_len < tvb_reported_length(tvb)) {
87                 /* Adjust the length of this tvbuff to include only the specified
88                    payload length.
89
90                    The dissector above the one calling us (the dissector above is
91                    probably us) may use that to determine how much of its packet
92                    was padding. */
93                 tvb_set_reported_length(tvb, specified_len);
94         }
95 }
96
97 /* Allow protocols to register "init" routines, which are called before
98    we make a pass through a capture file and dissect all its packets
99    (e.g., when we read in a new capture file, or run a "filter packets"
100    or "colorize packets" pass over the current capture file). */
101 static GSList *init_routines;
102
103 void
104 register_init_routine(void (*func)(void))
105 {
106         init_routines = g_slist_append(init_routines, (gpointer)func);
107 }
108
109 typedef void (*void_func_t)(void);
110
111 /* Initialize all data structures used for dissection. */
112 static void
113 call_init_routine(gpointer routine, gpointer dummy _U_)
114 {
115         void_func_t func = (void_func_t)routine;
116         (*func)();
117 }
118
119 /*
120  * XXX - for now, these are the same; the "init" routines free whatever
121  * stuff is left over from any previous dissection, and then initialize
122  * their tables.
123  *
124  * We should probably split that into "init" and "cleanup" routines, for
125  * cleanliness' sake.
126  */
127 void
128 init_dissection(void)
129 {
130         /* Reclaim and reinitialize all memory of seasonal scope */
131         se_free_all();
132
133         /* Initialize the table of conversations. */
134         epan_conversation_init();
135
136         /* Initialize the table of circuits. */
137         epan_circuit_init();
138
139         /* Initialize protocol-specific variables. */
140         g_slist_foreach(init_routines, &call_init_routine, NULL);
141
142         /* Initialize the stream-handling tables */
143         stream_init();
144
145         /* Initialize the expert infos */
146         expert_init();
147 }
148
149 void
150 cleanup_dissection(void)
151 {
152         /* Cleanup the table of conversations. Do this before freeing seasonal
153          * memory (at least until conversation's use of g_slist is changed).
154          */
155         epan_conversation_cleanup();
156
157         /* Reclaim all memory of seasonal scope */
158         se_free_all();
159
160         /* Cleanup the table of circuits. */
161         epan_circuit_cleanup();
162
163         /* TODO: Introduce cleanup_routines */
164         /* Cleanup protocol-specific variables. */
165         g_slist_foreach(init_routines, &call_init_routine, NULL);
166
167         /* Cleanup the stream-handling tables */
168         stream_cleanup();
169
170         /* Initialize the expert infos */
171         expert_cleanup();
172 }
173
174 /* Allow protocols to register a "cleanup" routine to be
175  * run after the initial sequential run through the packets.
176  * Note that the file can still be open after this; this is not
177  * the final cleanup. */
178 static GSList *postseq_cleanup_routines;
179
180 void
181 register_postseq_cleanup_routine(void_func_t func)
182 {
183         postseq_cleanup_routines = g_slist_append(postseq_cleanup_routines,
184                         (gpointer)func);
185 }
186
187 /* Call all the registered "postseq_cleanup" routines. */
188 static void
189 call_postseq_cleanup_routine(gpointer routine, gpointer dummy _U_)
190 {
191         void_func_t func = (void_func_t)routine;
192         (*func)();
193 }
194
195 void
196 postseq_cleanup_all_protocols(void)
197 {
198         g_slist_foreach(postseq_cleanup_routines,
199                         &call_postseq_cleanup_routine, NULL);
200 }
201
202 /*
203  * Add a new data source to the list of data sources for a frame, given
204  * the tvbuff for the data source and its name.
205  */
206 void
207 add_new_data_source(packet_info *pinfo, tvbuff_t *tvb, const char *name)
208 {
209         data_source *src;
210
211         src = ep_alloc(sizeof (data_source));
212         src->tvb = tvb;
213         src->name_initialized = FALSE;
214         src->name = name;
215         pinfo->data_src = g_slist_append(pinfo->data_src, src);
216 }
217
218 const char*
219 get_data_source_name(data_source *src)
220 {
221         if (!src->name_initialized) {
222                 src->name = ep_strdup_printf("%s (%u bytes)", src->name, tvb_length(src->tvb));
223                 src->name_initialized = TRUE;
224         }
225
226         return src->name;
227 }
228
229 /*
230  * Free up a frame's list of data sources.
231  */
232 void
233 free_data_sources(packet_info *pinfo)
234 {
235         if (pinfo->data_src) {
236                 g_slist_free(pinfo->data_src);
237                 pinfo->data_src = NULL;
238         }
239 }
240
241 void
242 mark_frame_as_depended_upon(packet_info *pinfo, guint32 frame_num)
243 {
244         /* Don't mark a frame as dependent on itself */
245         if (frame_num != PINFO_FD_NUM(pinfo)) {
246                 pinfo->dependent_frames = g_slist_prepend(pinfo->dependent_frames, GUINT_TO_POINTER(frame_num));
247         }
248 }
249
250 /* Allow dissectors to register a "final_registration" routine
251  * that is run like the proto_register_XXX() routine, but at the
252  * end of the epan_init() function; that is, *after* all other
253  * subsystems, like dfilters, have finished initializing. This is
254  * useful for dissector registration routines which need to compile
255  * display filters. dfilters can't initialize itself until all protocols
256  * have registered themselves. */
257 static GSList *final_registration_routines;
258
259 void
260 register_final_registration_routine(void (*func)(void))
261 {
262         final_registration_routines = g_slist_append(final_registration_routines,
263                         (gpointer)func);
264 }
265
266 /* Call all the registered "final_registration" routines. */
267 static void
268 call_final_registration_routine(gpointer routine, gpointer dummy _U_)
269 {
270         void_func_t func = (void_func_t)routine;
271
272         (*func)();
273 }
274
275 void
276 final_registration_all_protocols(void)
277 {
278         g_slist_foreach(final_registration_routines,
279                         &call_final_registration_routine, NULL);
280 }
281
282
283 /* Creates the top-most tvbuff and calls dissect_frame() */
284 void
285 dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header,
286                const guchar *pd, frame_data *fd, column_info *cinfo)
287 {
288         if (cinfo != NULL)
289                 col_init(cinfo);
290         memset(&edt->pi, 0, sizeof(edt->pi));
291         edt->pi.current_proto = "<Missing Protocol Name>";
292         edt->pi.cinfo = cinfo;
293         edt->pi.fd = fd;
294         edt->pi.pseudo_header = pseudo_header;
295         edt->pi.dl_src.type = AT_NONE;
296         edt->pi.dl_dst.type = AT_NONE;
297         edt->pi.net_src.type = AT_NONE;
298         edt->pi.net_dst.type = AT_NONE;
299         edt->pi.src.type = AT_NONE;
300         edt->pi.dst.type = AT_NONE;
301         edt->pi.ctype = CT_NONE;
302         edt->pi.noreassembly_reason = "";
303         edt->pi.ptype = PT_NONE;
304         edt->pi.p2p_dir = P2P_DIR_UNKNOWN;
305         edt->pi.dcetransporttype = -1;
306         edt->pi.annex_a_used = MTP2_ANNEX_A_USED_UNKNOWN;
307         edt->pi.dcerpc_procedure_name="";
308         edt->pi.link_dir = LINK_DIR_UNKNOWN;
309         edt->tvb = NULL;
310
311         /* to enable decode as for ethertype=0x0000 (fix for bug 4721) */
312         edt->pi.ethertype = G_MAXINT;
313
314         EP_CHECK_CANARY(("before dissecting frame %d",fd->num));
315
316         TRY {
317                 /*
318                  * XXX - currently, the length arguments to
319                  * tvb_new_real_data() are signed, but the captured
320                  * and reported length values are unsigned; this means
321                  * that length values > 2^31 - 1 will appear as
322                  * negative lengths in tvb_new_real_data().
323                  *
324                  * Captured length values that large will already
325                  * have been filtered out by the Wiretap modules
326                  * (the file will be reported as corrupted), to
327                  * avoid trying to allocate large chunks of data.
328                  *
329                  * Reported length values will not have been
330                  * filtered out, and should not be filtered out,
331                  * as those lengths are not necessarily invalid.
332                  *
333                  * For now, we clip the reported length at G_MAXINT,
334                  * so that tvb_new_real_data() doesn't fail.  It
335                  * would throw an exception, which we'd catch, but
336                  * that would mean we would have no tvbuffs
337                  * associated with edt, which would upset much of
338                  * the rest of the application.
339                  */
340                 edt->tvb = tvb_new_real_data(pd, fd->cap_len,
341                     fd->pkt_len > G_MAXINT ? G_MAXINT : fd->pkt_len);
342                 /* Add this tvbuffer into the data_src list */
343                 add_new_data_source(&edt->pi, edt->tvb, "Frame");
344
345                 /* Even though dissect_frame() catches all the exceptions a
346                  * sub-dissector can throw, dissect_frame() itself may throw
347                  * a ReportedBoundsError in bizarre cases. Thus, we catch the exception
348                  * in this function. */
349                 if(frame_handle != NULL)
350                   call_dissector(frame_handle, edt->tvb, &edt->pi, edt->tree);
351
352         }
353         CATCH(BoundsError) {
354                 g_assert_not_reached();
355         }
356         CATCH(ReportedBoundsError) {
357                 if(proto_malformed != -1){
358                         proto_tree_add_protocol_format(edt->tree, proto_malformed, edt->tvb, 0, 0,
359                                                        "[Malformed Frame: Packet Length]" );
360                 } else {
361                         g_assert_not_reached();
362                 }
363         }
364         CATCH(OutOfMemoryError) {
365                 RETHROW;
366         }
367         ENDTRY;
368
369         EP_CHECK_CANARY(("after dissecting frame %d",fd->num));
370
371         fd->flags.visited = 1;
372 }
373
374 /*********************** code added for sub-dissector lookup *********************/
375
376 /*
377  * A dissector handle.
378  */
379 struct dissector_handle {
380         const char      *name;          /* dissector name */
381         gboolean        is_new;         /* TRUE if new-style dissector */
382         union {
383                 dissector_t     old;
384                 new_dissector_t new;
385         } dissector;
386         protocol_t      *protocol;
387 };
388
389 /* This function will return
390  * old style dissector :
391  *   length of the payload or 1 of the payload is empty
392  * new dissector :
393  *   >0  this protocol was successfully dissected and this was this protocol.
394  *   0   this packet did not match this protocol.
395  *
396  * The only time this function will return 0 is if it is a new style dissector
397  * and if the dissector rejected the packet.
398  */
399 static int
400 call_dissector_through_handle(dissector_handle_t handle, tvbuff_t *tvb,
401                               packet_info *pinfo, proto_tree *tree, void *data)
402 {
403         const char *saved_proto;
404         int         ret;
405
406         saved_proto = pinfo->current_proto;
407
408         if (handle->protocol != NULL) {
409                 pinfo->current_proto =
410                         proto_get_protocol_short_name(handle->protocol);
411         }
412
413         if (handle->is_new) {
414                 EP_CHECK_CANARY(("before calling handle->dissector.new for %s",handle->name));
415                 ret = (*handle->dissector.new)(tvb, pinfo, tree, data);
416                 EP_CHECK_CANARY(("after calling handle->dissector.new for %s",handle->name));
417         } else {
418                 EP_CHECK_CANARY(("before calling handle->dissector.old for %s",handle->name));
419                 (*handle->dissector.old)(tvb, pinfo, tree);
420                 EP_CHECK_CANARY(("after calling handle->dissector.old for %s",handle->name));
421                 ret = tvb_length(tvb);
422                 if (ret == 0) {
423                         /*
424                          * XXX - a tvbuff can have 0 bytes of data in
425                          * it, so we have to make sure we don't return
426                          * 0.
427                          */
428                         ret = 1;
429                 }
430         }
431
432         pinfo->current_proto = saved_proto;
433
434         return ret;
435 }
436
437 /*
438  * Call a dissector through a handle.
439  * If the protocol for that handle isn't enabled, return 0 without
440  * calling the dissector.
441  * Otherwise, if the handle refers to a new-style dissector, call the
442  * dissector and return its return value, otherwise call it and return
443  * the length of the tvbuff pointed to by the argument.
444  */
445
446 static int
447 call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb,
448                           packet_info *pinfo_arg, proto_tree *tree, void *);
449
450 static int
451 call_dissector_work(dissector_handle_t handle, tvbuff_t *tvb, packet_info *pinfo_arg,
452                     proto_tree *tree, gboolean add_proto_name, void *data)
453 {
454         packet_info *pinfo = pinfo_arg;
455         const char  *saved_proto;
456         guint16      saved_can_desegment;
457         int          ret;
458         gint         saved_layer_names_len = 0;
459
460         if (handle->protocol != NULL &&
461             !proto_is_protocol_enabled(handle->protocol)) {
462                 /*
463                  * The protocol isn't enabled.
464                  */
465                 return 0;
466         }
467
468         saved_proto = pinfo->current_proto;
469         saved_can_desegment = pinfo->can_desegment;
470
471         if (pinfo->layer_names != NULL)
472                 saved_layer_names_len = (gint) pinfo->layer_names->len;
473
474         /*
475          * can_desegment is set to 2 by anyone which offers the
476          * desegmentation api/service.
477          * Then everytime a subdissector is called it is decremented
478          * by one.
479          * Thus only the subdissector immediately on top of whoever
480          * offers this service can use it.
481          * We save the current value of "can_desegment" for the
482          * benefit of TCP proxying dissectors such as SOCKS, so they
483          * can restore it and allow the dissectors they call to use
484          * the desegmentation service.
485          */
486         pinfo->saved_can_desegment = saved_can_desegment;
487         pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
488         if (handle->protocol != NULL) {
489                 pinfo->current_proto =
490                         proto_get_protocol_short_name(handle->protocol);
491
492                 /*
493                  * Add the protocol name to the layers
494                  * if not told not to. Asn2wrs generated dissectors may be added multiple times otherwise.
495                  */
496                 if ((pinfo->layer_names)&&(add_proto_name)) {
497                         if (pinfo->layer_names->len > 0)
498                                 g_string_append(pinfo->layer_names, ":");
499                                 g_string_append(pinfo->layer_names,
500                                 proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
501                 }
502         }
503
504         if (pinfo->flags.in_error_pkt) {
505                 ret = call_dissector_work_error(handle, tvb, pinfo, tree, data);
506         } else {
507                 /*
508                  * Just call the subdissector.
509                  */
510                 ret = call_dissector_through_handle(handle, tvb, pinfo, tree, data);
511         }
512         if (ret == 0) {
513                 /*
514                  * That dissector didn't accept the packet, so
515                  * remove its protocol's name from the list
516                  * of protocols.
517                  */
518                 if ((pinfo->layer_names != NULL)&&(add_proto_name)) {
519                         g_string_truncate(pinfo->layer_names, saved_layer_names_len);
520                 }
521         }
522         pinfo->current_proto = saved_proto;
523         pinfo->can_desegment = saved_can_desegment;
524         return ret;
525 }
526
527
528 static int
529 call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb,
530                           packet_info *pinfo_arg, proto_tree *tree, void *data)
531 {
532         packet_info  *pinfo = pinfo_arg;
533         const char   *saved_proto;
534         guint16       saved_can_desegment;
535         volatile int  ret = 0;
536         gboolean      save_writable;
537         address       save_dl_src;
538         address       save_dl_dst;
539         address       save_net_src;
540         address       save_net_dst;
541         address       save_src;
542         address       save_dst;
543
544         /*
545         * This isn't a packet being transported inside
546         * the protocol whose dissector is calling us,
547         * it's a copy of a packet that caused an error
548         * in some protocol included in a packet that
549         * reports the error (e.g., an ICMP Unreachable
550         * packet).
551         */
552
553         /*
554         * Save the current state of the writability of
555         * the columns, and restore them after the
556         * dissector returns, so that the columns
557         * don't reflect the packet that got the error,
558         * they reflect the packet that reported the
559         * error.
560         */
561         saved_proto = pinfo->current_proto;
562         saved_can_desegment = pinfo->can_desegment;
563
564         save_writable = col_get_writable(pinfo->cinfo);
565         col_set_writable(pinfo->cinfo, FALSE);
566         save_dl_src   = pinfo->dl_src;
567         save_dl_dst   = pinfo->dl_dst;
568         save_net_src  = pinfo->net_src;
569         save_net_dst  = pinfo->net_dst;
570         save_src      = pinfo->src;
571         save_dst      = pinfo->dst;
572
573         /* Dissect the contained packet. */
574         TRY {
575                 ret = call_dissector_through_handle(handle, tvb,pinfo, tree, data);
576         }
577         CATCH(BoundsError) {
578                 /*
579                 * Restore the column writability and addresses.
580                 */
581                 col_set_writable(pinfo->cinfo, save_writable);
582                 pinfo->dl_src  = save_dl_src;
583                 pinfo->dl_dst  = save_dl_dst;
584                 pinfo->net_src = save_net_src;
585                 pinfo->net_dst = save_net_dst;
586                 pinfo->src     = save_src;
587                 pinfo->dst     = save_dst;
588
589                 /*
590                 * Restore the current protocol, so any
591                 * "Short Frame" indication reflects that
592                 * protocol, not the protocol for the
593                 * packet that got the error.
594                 */
595                 pinfo->current_proto = saved_proto;
596
597                 /*
598                 * Restore the desegmentability state.
599                 */
600                 pinfo->can_desegment = saved_can_desegment;
601
602                 /*
603                 * Rethrow the exception, so this will be
604                 * reported as a short frame.
605                 */
606                 RETHROW;
607         }
608         CATCH(ReportedBoundsError) {
609                 /*
610                 * "ret" wasn't set because an exception was thrown
611                 * before "call_dissector_through_handle()" returned.
612                 * As it called something, at least one dissector
613                 * accepted the packet, and, as an exception was
614                 * thrown, not only was all the tvbuff dissected,
615                 * a dissector tried dissecting past the end of
616                 * the data in some tvbuff, so we'll assume that
617                 * the entire tvbuff was dissected.
618                 */
619                 ret = tvb_length(tvb);
620         }
621         CATCH(OutOfMemoryError) {
622                 RETHROW;
623         }
624         ENDTRY;
625
626         col_set_writable(pinfo->cinfo, save_writable);
627         pinfo->dl_src  = save_dl_src;
628         pinfo->dl_dst  = save_dl_dst;
629         pinfo->net_src = save_net_src;
630         pinfo->net_dst = save_net_dst;
631         pinfo->src     = save_src;
632         pinfo->dst     = save_dst;
633         pinfo->want_pdu_tracking = 0;
634         return ret;
635 }
636
637 /*
638  * An entry in the hash table portion of a dissector table.
639  */
640 struct dtbl_entry {
641         dissector_handle_t initial;
642         dissector_handle_t current;
643 };
644
645 /*
646  * A dissector table.
647  *
648  * "hash_table" is a hash table, indexed by port number, supplying
649  * a "struct dtbl_entry"; it records what dissector is assigned to
650  * that uint or string value in that table.
651  *
652  * "dissector_handles" is a list of all dissectors that *could* be
653  * used in that table; not all of them are necessarily in the table,
654  * as they may be for protocols that don't have a fixed uint value,
655  * e.g. for TCP or UDP port number tables and protocols with no fixed
656  * port number.
657  *
658  * "ui_name" is the name the dissector table has in the user interface.
659  *
660  * "type" is a field type giving the width of the uint value for that
661  * dissector table, if it's a uint dissector table.
662  *
663  * "base" is the base in which to display the uint value for that
664  * dissector table, if it's a uint dissector table.
665  */
666 struct dissector_table {
667         GHashTable      *hash_table;
668         GSList          *dissector_handles;
669         const char      *ui_name;
670         ftenum_t        type;
671         int             base;
672 };
673
674 static GHashTable *dissector_tables = NULL;
675
676 /* Finds a dissector table by table name. */
677 dissector_table_t
678 find_dissector_table(const char *name)
679 {
680         g_assert(dissector_tables);
681         return g_hash_table_lookup( dissector_tables, name );
682 }
683
684 /* Find an entry in a uint dissector table. */
685 static dtbl_entry_t *
686 find_uint_dtbl_entry(dissector_table_t sub_dissectors, const guint32 pattern)
687 {
688         switch (sub_dissectors->type) {
689
690         case FT_UINT8:
691         case FT_UINT16:
692         case FT_UINT24:
693         case FT_UINT32:
694                 /*
695                  * You can do a uint lookup in these tables.
696                  */
697                 break;
698
699         default:
700                 /*
701                  * But you can't do a uint lookup in any other types
702                  * of tables.
703                  */
704                 g_assert_not_reached();
705         }
706
707         /*
708          * Find the entry.
709          */
710         return g_hash_table_lookup(sub_dissectors->hash_table,
711                                    GUINT_TO_POINTER(pattern));
712 }
713
714 #if 0
715 static void
716 dissector_add_uint_sanity_check(const char *name, guint32 pattern, dissector_handle_t handle, dissector_table_t sub_dissectors)
717 {
718         dtbl_entry_t *dtbl_entry;
719
720         if (pattern == 0) {
721                 g_warning("%s: %s registering using a pattern of 0",
722                           name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)));
723         }
724
725         dtbl_entry = g_hash_table_lookup(sub_dissectors->hash_table, GUINT_TO_POINTER(pattern));
726         if (dtbl_entry != NULL) {
727                 g_warning("%s: %s registering using pattern %d already registered by %s",
728                           name, proto_get_protocol_filter_name(proto_get_id(handle->protocol)),
729                           pattern, proto_get_protocol_filter_name(proto_get_id(dtbl_entry->initial->protocol)));
730         }
731 }
732 #endif
733
734 /* Add an entry to a uint dissector table. */
735 void
736 dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t handle)
737 {
738         dissector_table_t  sub_dissectors;
739         dtbl_entry_t      *dtbl_entry;
740
741         sub_dissectors = find_dissector_table(name);
742
743         /*
744          * Make sure the dissector table exists.
745          */
746         if (sub_dissectors == NULL) {
747                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
748                     name);
749                 fprintf(stderr, "Protocol being registered is \"%s\"\n",
750                     proto_get_protocol_long_name(handle->protocol));
751                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
752                         abort();
753                 return;
754         }
755
756         /* sanity checks */
757         g_assert(handle!=NULL);
758         switch (sub_dissectors->type) {
759
760         case FT_UINT8:
761         case FT_UINT16:
762         case FT_UINT24:
763         case FT_UINT32:
764                 /*
765                  * You can do a uint lookup in these tables.
766                  */
767                 break;
768
769         default:
770                 /*
771                  * But you can't do a uint lookup in any other types
772                  * of tables.
773                  */
774                 g_assert_not_reached();
775         }
776
777 #if 0
778         dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors);
779 #endif
780
781         dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
782         dtbl_entry->current = handle;
783         dtbl_entry->initial = dtbl_entry->current;
784
785         /* do the table insertion */
786         g_hash_table_insert( sub_dissectors->hash_table,
787                              GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
788
789         /*
790          * Now add it to the list of handles that could be used with this
791          * table, because it *is* being used with this table.
792          */
793         dissector_add_handle(name, handle);
794 }
795
796 /* Delete the entry for a dissector in a uint dissector table
797    with a particular pattern. */
798
799 /* NOTE: this doesn't use the dissector call variable. It is included to */
800 /*      be consistant with the dissector_add_uint and more importantly to be used */
801 /*      if the technique of adding a temporary dissector is implemented.  */
802 /*      If temporary dissectors are deleted, then the original dissector must */
803 /*      be available. */
804 void
805 dissector_delete_uint(const char *name, const guint32 pattern,
806         dissector_handle_t handle _U_)
807 {
808         dissector_table_t sub_dissectors = find_dissector_table( name);
809         dtbl_entry_t *dtbl_entry;
810
811         /* sanity check */
812         g_assert( sub_dissectors);
813
814         /*
815          * Find the entry.
816          */
817         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
818
819         if (dtbl_entry != NULL) {
820                 /*
821                  * Found - remove it.
822                  */
823                 g_hash_table_remove(sub_dissectors->hash_table,
824                                     GUINT_TO_POINTER(pattern));
825         }
826 }
827
828 /* Change the entry for a dissector in a uint dissector table
829    with a particular pattern to use a new dissector handle. */
830 void
831 dissector_change_uint(const char *name, const guint32 pattern, dissector_handle_t handle)
832 {
833         dissector_table_t sub_dissectors = find_dissector_table( name);
834         dtbl_entry_t *dtbl_entry;
835
836         /* sanity check */
837         g_assert( sub_dissectors);
838
839         /*
840          * See if the entry already exists. If so, reuse it.
841          */
842         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
843         if (dtbl_entry != NULL) {
844                 dtbl_entry->current = handle;
845                 return;
846         }
847
848         /*
849          * Don't create an entry if there is no dissector handle - I.E. the
850          * user said not to decode something that wasn't being decoded
851          * in the first place.
852          */
853         if (handle == NULL)
854                 return;
855
856         dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
857         dtbl_entry->initial = NULL;
858         dtbl_entry->current = handle;
859
860         /* do the table insertion */
861         g_hash_table_insert( sub_dissectors->hash_table,
862                              GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
863 }
864
865 /* Reset an entry in a uint dissector table to its initial value. */
866 void
867 dissector_reset_uint(const char *name, const guint32 pattern)
868 {
869         dissector_table_t  sub_dissectors = find_dissector_table( name);
870         dtbl_entry_t      *dtbl_entry;
871
872         /* sanity check */
873         g_assert( sub_dissectors);
874
875         /*
876          * Find the entry.
877          */
878         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, pattern);
879
880         if (dtbl_entry == NULL)
881                 return;
882
883         /*
884          * Found - is there an initial value?
885          */
886         if (dtbl_entry->initial != NULL) {
887                 dtbl_entry->current = dtbl_entry->initial;
888         } else {
889                 g_hash_table_remove(sub_dissectors->hash_table,
890                                     GUINT_TO_POINTER(pattern));
891         }
892 }
893
894 /* Look for a given value in a given uint dissector table and, if found,
895    call the dissector with the arguments supplied, and return TRUE,
896    otherwise return FALSE. */
897
898 gboolean
899 dissector_try_uint_new(dissector_table_t sub_dissectors, const guint32 uint_val,
900                        tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, const gboolean add_proto_name)
901 {
902         dtbl_entry_t            *dtbl_entry;
903         struct dissector_handle *handle;
904         guint32                  saved_match_uint;
905         int ret;
906
907         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, uint_val);
908         if (dtbl_entry != NULL) {
909                 /*
910                  * Is there currently a dissector handle for this entry?
911                  */
912                 handle = dtbl_entry->current;
913                 if (handle == NULL) {
914                         /*
915                          * No - pretend this dissector didn't exist,
916                          * so that other dissectors might have a chance
917                          * to dissect this packet.
918                          */
919                         return FALSE;
920                 }
921
922                 /*
923                  * Save the current value of "pinfo->match_uint",
924                  * set it to the uint_val that matched, call the
925                  * dissector, and restore "pinfo->match_uint".
926                  */
927                 saved_match_uint  = pinfo->match_uint;
928                 pinfo->match_uint = uint_val;
929                 ret = call_dissector_work(handle, tvb, pinfo, tree, add_proto_name, NULL);
930                 pinfo->match_uint = saved_match_uint;
931
932                 /*
933                  * If a new-style dissector returned 0, it means that
934                  * it didn't think this tvbuff represented a packet for
935                  * its protocol, and didn't dissect anything.
936                  *
937                  * Old-style dissectors can't reject the packet.
938                  *
939                  * 0 is also returned if the protocol wasn't enabled.
940                  *
941                  * If the packet was rejected, we return FALSE, so that
942                  * other dissectors might have a chance to dissect this
943                  * packet, otherwise we return TRUE.
944                  */
945                 return ret != 0;
946         }
947         return FALSE;
948 }
949
950 gboolean
951 dissector_try_uint(dissector_table_t sub_dissectors, const guint32 uint_val,
952                    tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
953 {
954
955         return dissector_try_uint_new(sub_dissectors, uint_val, tvb, pinfo, tree, TRUE);
956 }
957
958 /* Look for a given value in a given uint dissector table and, if found,
959    return the dissector handle for that value. */
960 dissector_handle_t
961 dissector_get_uint_handle(dissector_table_t const sub_dissectors, const guint32 uint_val)
962 {
963         dtbl_entry_t *dtbl_entry;
964
965         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, uint_val);
966         if (dtbl_entry != NULL)
967                 return dtbl_entry->current;
968         else
969                 return NULL;
970 }
971
972 /* Find an entry in a string dissector table. */
973 static dtbl_entry_t *
974 find_string_dtbl_entry(dissector_table_t const sub_dissectors, const gchar *pattern)
975 {
976         switch (sub_dissectors->type) {
977
978         case FT_STRING:
979         case FT_STRINGZ:
980                 /*
981                  * You can do a string lookup in these tables.
982                  */
983                 break;
984
985         default:
986                 /*
987                  * But you can't do a string lookup in any other types
988                  * of tables.
989                  */
990                 g_assert_not_reached();
991         }
992
993         /*
994          * Find the entry.
995          */
996         return g_hash_table_lookup(sub_dissectors->hash_table, pattern);
997 }
998
999 /* Add an entry to a string dissector table. */
1000 void
1001 dissector_add_string(const char *name, const gchar *pattern,
1002                      dissector_handle_t handle)
1003 {
1004         dissector_table_t  sub_dissectors = find_dissector_table( name);
1005         dtbl_entry_t      *dtbl_entry;
1006
1007         /*
1008          * Make sure the dissector table exists.
1009          */
1010         if (sub_dissectors == NULL) {
1011                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
1012                     name);
1013                 fprintf(stderr, "Protocol being registered is \"%s\"\n",
1014                     proto_get_protocol_long_name(handle->protocol));
1015                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
1016                         abort();
1017                 return;
1018         }
1019
1020         /* sanity checks */
1021         g_assert(handle!=NULL);
1022         switch (sub_dissectors->type) {
1023
1024         case FT_STRING:
1025         case FT_STRINGZ:
1026                 /*
1027                  * You can do a string lookup in these tables.
1028                  */
1029                 break;
1030
1031         default:
1032                 /*
1033                  * But you can't do a string lookup in any other types
1034                  * of tables.
1035                  */
1036                 g_assert_not_reached();
1037         }
1038
1039         dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1040         dtbl_entry->current = handle;
1041         dtbl_entry->initial = dtbl_entry->current;
1042
1043         /* do the table insertion */
1044         g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1045                              (gpointer)dtbl_entry);
1046
1047         /*
1048          * Now add it to the list of handles that could be used with this
1049          * table, because it *is* being used with this table.
1050          */
1051         dissector_add_handle(name, handle);
1052 }
1053
1054 /* Delete the entry for a dissector in a string dissector table
1055    with a particular pattern. */
1056
1057 /* NOTE: this doesn't use the dissector call variable. It is included to */
1058 /*      be consistant with the dissector_add_string and more importantly to */
1059 /*      be used if the technique of adding a temporary dissector is */
1060 /*      implemented.  */
1061 /*      If temporary dissectors are deleted, then the original dissector must */
1062 /*      be available. */
1063 void
1064 dissector_delete_string(const char *name, const gchar *pattern,
1065         dissector_handle_t handle _U_)
1066 {
1067         dissector_table_t  sub_dissectors = find_dissector_table( name);
1068         dtbl_entry_t      *dtbl_entry;
1069
1070         /* sanity check */
1071         g_assert( sub_dissectors);
1072
1073         /*
1074          * Find the entry.
1075          */
1076         dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1077
1078         if (dtbl_entry != NULL) {
1079                 /*
1080                  * Found - remove it.
1081                  */
1082                 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1083         }
1084 }
1085
1086 /* Change the entry for a dissector in a string dissector table
1087    with a particular pattern to use a new dissector handle. */
1088 void
1089 dissector_change_string(const char *name, const gchar *pattern,
1090                         dissector_handle_t handle)
1091 {
1092         dissector_table_t  sub_dissectors = find_dissector_table( name);
1093         dtbl_entry_t      *dtbl_entry;
1094
1095         /* sanity check */
1096         g_assert( sub_dissectors);
1097
1098         /*
1099          * See if the entry already exists. If so, reuse it.
1100          */
1101         dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1102         if (dtbl_entry != NULL) {
1103                 dtbl_entry->current = handle;
1104                 return;
1105         }
1106
1107         /*
1108          * Don't create an entry if there is no dissector handle - I.E. the
1109          * user said not to decode something that wasn't being decoded
1110          * in the first place.
1111          */
1112         if (handle == NULL)
1113                 return;
1114
1115         dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1116         dtbl_entry->initial = NULL;
1117         dtbl_entry->current = handle;
1118
1119         /* do the table insertion */
1120         g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1121                              (gpointer)dtbl_entry);
1122 }
1123
1124 /* Reset an entry in a string sub-dissector table to its initial value. */
1125 void
1126 dissector_reset_string(const char *name, const gchar *pattern)
1127 {
1128         dissector_table_t  sub_dissectors = find_dissector_table( name);
1129         dtbl_entry_t      *dtbl_entry;
1130
1131         /* sanity check */
1132         g_assert( sub_dissectors);
1133
1134         /*
1135          * Find the entry.
1136          */
1137         dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1138
1139         if (dtbl_entry == NULL)
1140                 return;
1141
1142         /*
1143          * Found - is there an initial value?
1144          */
1145         if (dtbl_entry->initial != NULL) {
1146                 dtbl_entry->current = dtbl_entry->initial;
1147         } else {
1148                 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1149         }
1150 }
1151
1152 /* Look for a given string in a given dissector table and, if found, call
1153    the dissector with the arguments supplied, and return TRUE, otherwise
1154    return FALSE. */
1155 gboolean
1156 dissector_try_string(dissector_table_t sub_dissectors, const gchar *string,
1157                      tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1158 {
1159         dtbl_entry_t            *dtbl_entry;
1160         struct dissector_handle *handle;
1161         int                      ret;
1162         const gchar             *saved_match_string;
1163
1164         /* XXX ASSERT instead ? */
1165         if (!string) return FALSE;
1166         dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1167         if (dtbl_entry != NULL) {
1168                 /*
1169                  * Is there currently a dissector handle for this entry?
1170                  */
1171                 handle = dtbl_entry->current;
1172                 if (handle == NULL) {
1173                         /*
1174                          * No - pretend this dissector didn't exist,
1175                          * so that other dissectors might have a chance
1176                          * to dissect this packet.
1177                          */
1178                         return FALSE;
1179                 }
1180
1181                 /*
1182                  * Save the current value of "pinfo->match_string",
1183                  * set it to the string that matched, call the
1184                  * dissector, and restore "pinfo->match_string".
1185                  */
1186                 saved_match_string = pinfo->match_string;
1187                 pinfo->match_string = string;
1188                 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE, NULL);
1189                 pinfo->match_string = saved_match_string;
1190
1191                 /*
1192                  * If a new-style dissector returned 0, it means that
1193                  * it didn't think this tvbuff represented a packet for
1194                  * its protocol, and didn't dissect anything.
1195                  *
1196                  * Old-style dissectors can't reject the packet.
1197                  *
1198                  * 0 is also returned if the protocol wasn't enabled.
1199                  *
1200                  * If the packet was rejected, we return FALSE, so that
1201                  * other dissectors might have a chance to dissect this
1202                  * packet, otherwise we return TRUE.
1203                  */
1204                 return ret != 0;
1205         }
1206         return FALSE;
1207 }
1208
1209 /* Look for a given value in a given string dissector table and, if found,
1210    return the dissector handle for that value. */
1211 dissector_handle_t
1212 dissector_get_string_handle(dissector_table_t sub_dissectors,
1213                             const gchar *string)
1214 {
1215         dtbl_entry_t *dtbl_entry;
1216
1217         dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1218         if (dtbl_entry != NULL)
1219                 return dtbl_entry->current;
1220         else
1221                 return NULL;
1222 }
1223
1224 dissector_handle_t
1225 dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry)
1226 {
1227         return dtbl_entry->current;
1228 }
1229
1230 gint
1231 dissector_compare_filter_name(gconstpointer dissector_a, gconstpointer dissector_b)
1232 {
1233         dissector_handle_t a = (dissector_handle_t)dissector_a;
1234         dissector_handle_t b = (dissector_handle_t)dissector_b;
1235         const char *a_name, *b_name;
1236         gint ret;
1237
1238         if (a->protocol == NULL)
1239                 a_name = "";
1240         else
1241                 a_name = proto_get_protocol_filter_name(proto_get_id(a->protocol));
1242
1243         if (b->protocol == NULL)
1244                 b_name = "";
1245         else
1246                 b_name = proto_get_protocol_filter_name(proto_get_id(b->protocol));
1247
1248         ret = strcmp(a_name, b_name); 
1249         return ret;
1250 }
1251
1252 /* Add a handle to the list of handles that *could* be used with this
1253    table.  That list is used by code in the UI. */
1254 void
1255 dissector_add_handle(const char *name, dissector_handle_t handle)
1256 {
1257         dissector_table_t  sub_dissectors = find_dissector_table( name);
1258         GSList            *entry;
1259
1260         /*
1261          * Make sure the dissector table exists.
1262          */
1263         if (sub_dissectors == NULL) {
1264                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
1265                     name);
1266                 fprintf(stderr, "Protocol being registered is \"%s\"\n",
1267                     proto_get_protocol_long_name(handle->protocol));
1268                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
1269                         abort();
1270                 return;
1271         }
1272
1273         /* Is it already in this list? */
1274         entry = g_slist_find(sub_dissectors->dissector_handles, (gpointer)handle);
1275         if (entry != NULL) {
1276                 /*
1277                  * Yes - don't insert it again.
1278                  */
1279                 return;
1280         }
1281
1282         /* Add it to the list. */
1283         sub_dissectors->dissector_handles =
1284                 g_slist_insert_sorted(sub_dissectors->dissector_handles, (gpointer)handle, (GCompareFunc)dissector_compare_filter_name);
1285 }
1286
1287 dissector_handle_t
1288 dtbl_entry_get_initial_handle (dtbl_entry_t *dtbl_entry)
1289 {
1290         return dtbl_entry->initial;
1291 }
1292
1293 /**************************************************/
1294 /*                                                */
1295 /*       Routines to walk dissector tables        */
1296 /*                                                */
1297 /**************************************************/
1298
1299 typedef struct dissector_foreach_info {
1300         gpointer      caller_data;
1301         DATFunc       caller_func;
1302         GHFunc        next_func;
1303         const gchar  *table_name;
1304         ftenum_t      selector_type;
1305 } dissector_foreach_info_t;
1306
1307 /*
1308  * Called for each entry in a dissector table.
1309  */
1310 static void
1311 dissector_table_foreach_func (gpointer key, gpointer value, gpointer user_data)
1312 {
1313         dissector_foreach_info_t *info;
1314         dtbl_entry_t             *dtbl_entry;
1315
1316         g_assert(value);
1317         g_assert(user_data);
1318
1319         dtbl_entry = value;
1320         if (dtbl_entry->current == NULL ||
1321             dtbl_entry->current->protocol == NULL) {
1322                 /*
1323                  * Either there is no dissector for this entry, or
1324                  * the dissector doesn't have a protocol associated
1325                  * with it.
1326                  *
1327                  * XXX - should the latter check be done?
1328                  */
1329                 return;
1330         }
1331
1332         info = user_data;
1333         info->caller_func(info->table_name, info->selector_type, key, value,
1334                           info->caller_data);
1335 }
1336
1337 /*
1338  * Called for each entry in the table of all dissector tables.
1339  */
1340 static void
1341 dissector_all_tables_foreach_func (gpointer key, gpointer value, gpointer user_data)
1342 {
1343         dissector_table_t         sub_dissectors;
1344         dissector_foreach_info_t *info;
1345
1346         g_assert(value);
1347         g_assert(user_data);
1348
1349         sub_dissectors = value;
1350         info = user_data;
1351         info->table_name = (gchar*) key;
1352         info->selector_type = get_dissector_table_selector_type(info->table_name);
1353         g_hash_table_foreach(sub_dissectors->hash_table, info->next_func, info);
1354 }
1355
1356 /*
1357  * Walk all dissector tables calling a user supplied function on each
1358  * entry.
1359  */
1360 static void
1361 dissector_all_tables_foreach (DATFunc func,
1362                               gpointer user_data)
1363 {
1364         dissector_foreach_info_t info;
1365
1366         info.caller_data = user_data;
1367         info.caller_func = func;
1368         info.next_func   = dissector_table_foreach_func;
1369         g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1370 }
1371
1372 /*
1373  * Walk one dissector table's hash table calling a user supplied function
1374  * on each entry.
1375  */
1376 void
1377 dissector_table_foreach (const char *name,
1378                          DATFunc     func,
1379                          gpointer    user_data)
1380 {
1381         dissector_foreach_info_t info;
1382         dissector_table_t        sub_dissectors = find_dissector_table( name);
1383
1384         info.table_name    = name;
1385         info.selector_type = sub_dissectors->type;
1386         info.caller_func   = func;
1387         info.caller_data   = user_data;
1388         g_hash_table_foreach(sub_dissectors->hash_table, dissector_table_foreach_func, &info);
1389 }
1390
1391 /*
1392  * Walk one dissector table's list of handles calling a user supplied
1393  * function on each entry.
1394  */
1395 void
1396 dissector_table_foreach_handle(const char     *name,
1397                                DATFunc_handle  func,
1398                                gpointer        user_data)
1399 {
1400         dissector_table_t sub_dissectors = find_dissector_table( name);
1401         GSList *tmp;
1402
1403         for (tmp = sub_dissectors->dissector_handles; tmp != NULL;
1404              tmp = g_slist_next(tmp))
1405                 func(name, tmp->data, user_data);
1406 }
1407
1408 /*
1409  * Called for each entry in a dissector table.
1410  */
1411 static void
1412 dissector_table_foreach_changed_func (gpointer key, gpointer value, gpointer user_data)
1413 {
1414         dtbl_entry_t             *dtbl_entry;
1415         dissector_foreach_info_t *info;
1416
1417         g_assert(value);
1418         g_assert(user_data);
1419
1420         dtbl_entry = value;
1421         if (dtbl_entry->initial == dtbl_entry->current) {
1422                 /*
1423                  * Entry hasn't changed - don't call the function.
1424                  */
1425                 return;
1426         }
1427
1428         info = user_data;
1429         info->caller_func(info->table_name, info->selector_type, key, value,
1430                           info->caller_data);
1431 }
1432
1433 /*
1434  * Walk all dissector tables calling a user supplied function only on
1435  * any entry that has been changed from its original state.
1436  */
1437 void
1438 dissector_all_tables_foreach_changed (DATFunc  func,
1439                                       gpointer user_data)
1440 {
1441         dissector_foreach_info_t info;
1442
1443         info.caller_data = user_data;
1444         info.caller_func = func;
1445         info.next_func   = dissector_table_foreach_changed_func;
1446         g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1447 }
1448
1449 /*
1450  * Walk one dissector table calling a user supplied function only on
1451  * any entry that has been changed from its original state.
1452  */
1453 void
1454 dissector_table_foreach_changed (const char *name,
1455                                  DATFunc     func,
1456                                  gpointer    user_data)
1457 {
1458         dissector_foreach_info_t info;
1459         dissector_table_t sub_dissectors = find_dissector_table( name);
1460
1461         info.table_name    = name;
1462         info.selector_type = sub_dissectors->type;
1463         info.caller_func   = func;
1464         info.caller_data   = user_data;
1465         g_hash_table_foreach(sub_dissectors->hash_table,
1466                              dissector_table_foreach_changed_func, &info);
1467 }
1468
1469 typedef struct dissector_foreach_table_info {
1470         gpointer      caller_data;
1471         DATFunc_table caller_func;
1472 } dissector_foreach_table_info_t;
1473
1474 /*
1475  * Called for each entry in the table of all dissector tables.
1476  */
1477 static void
1478 dissector_all_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
1479 {
1480         dissector_table_t               table;
1481         dissector_foreach_table_info_t *info;
1482
1483         table = value;
1484         info = user_data;
1485         (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1486 }
1487
1488 /*
1489  * Called for each key in the table of all dissector tables.
1490  */
1491 static void
1492 dissector_all_tables_foreach_list_func (gpointer key, gpointer user_data)
1493 {
1494         dissector_table_t               table;
1495         dissector_foreach_table_info_t *info;
1496
1497         table = g_hash_table_lookup( dissector_tables, key );
1498         info = user_data;
1499         (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1500 }
1501
1502 /*
1503  * Walk all dissector tables calling a user supplied function on each
1504  * table.
1505  */
1506 void
1507 dissector_all_tables_foreach_table (DATFunc_table func,
1508                                         gpointer      user_data,
1509                                         GCompareFunc compare_key_func)
1510 {
1511         dissector_foreach_table_info_t info;
1512         GList* list;
1513
1514         info.caller_data = user_data;
1515         info.caller_func = func;
1516         if (compare_key_func != NULL)
1517         {
1518                 list = g_hash_table_get_keys(dissector_tables);
1519                 list = g_list_sort(list, compare_key_func);
1520                 g_list_foreach(list, dissector_all_tables_foreach_list_func, &info);
1521                 g_list_free(list);
1522         }
1523         else
1524         {
1525                 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_table_func, &info);
1526         }
1527 }
1528
1529 dissector_table_t
1530 register_dissector_table(const char *name, const char *ui_name, const ftenum_t type,
1531                          const int base)
1532 {
1533         dissector_table_t       sub_dissectors;
1534
1535         /* Create our hash-of-hashes if it doesn't already exist */
1536         if (!dissector_tables) {
1537                 dissector_tables = g_hash_table_new( g_str_hash, g_str_equal );
1538                 g_assert(dissector_tables);
1539         }
1540
1541         /* Make sure the registration is unique */
1542         if(g_hash_table_lookup( dissector_tables, name )) {
1543                 g_error("The filter name %s (%s) is already registered - do you use a buggy plugin?", name, ui_name);
1544         }
1545
1546         /* Create and register the dissector table for this name; returns */
1547         /* a pointer to the dissector table. */
1548         sub_dissectors = g_malloc(sizeof (struct dissector_table));
1549         switch (type) {
1550
1551         case FT_UINT8:
1552         case FT_UINT16:
1553         case FT_UINT24:
1554         case FT_UINT32:
1555                 /*
1556                  * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
1557                  * so we use "g_direct_hash()" and "g_direct_equal()".
1558                  */
1559                 sub_dissectors->hash_table = g_hash_table_new_full( g_direct_hash,
1560                                                                g_direct_equal,
1561                                                                NULL,
1562                                                                &g_free );
1563                 break;
1564
1565         case FT_STRING:
1566         case FT_STRINGZ:
1567                 sub_dissectors->hash_table = g_hash_table_new_full( g_str_hash,
1568                                                                g_str_equal,
1569                                                                NULL,
1570                                                                &g_free );
1571                 break;
1572
1573         default:
1574                 g_assert_not_reached();
1575         }
1576         sub_dissectors->dissector_handles = NULL;
1577         sub_dissectors->ui_name = ui_name;
1578         sub_dissectors->type    = type;
1579         sub_dissectors->base    = base;
1580         g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
1581         return sub_dissectors;
1582 }
1583
1584 const char *
1585 get_dissector_table_ui_name(const char *name)
1586 {
1587         dissector_table_t sub_dissectors = find_dissector_table( name);
1588
1589         return sub_dissectors->ui_name;
1590 }
1591
1592 ftenum_t
1593 get_dissector_table_selector_type(const char *name)
1594 {
1595         dissector_table_t sub_dissectors = find_dissector_table( name);
1596
1597         return sub_dissectors->type;
1598 }
1599
1600 int
1601 get_dissector_table_base(const char *name)
1602 {
1603         dissector_table_t sub_dissectors = find_dissector_table( name);
1604
1605         return sub_dissectors->base;
1606 }
1607
1608 static GHashTable *heur_dissector_lists = NULL;
1609
1610
1611 /* Finds a heuristic dissector table by table name. */
1612 static heur_dissector_list_t *
1613 find_heur_dissector_list(const char *name)
1614 {
1615         g_assert(heur_dissector_lists != NULL);
1616         return g_hash_table_lookup(heur_dissector_lists, name);
1617 }
1618
1619 void
1620 heur_dissector_add(const char *name, heur_dissector_t dissector, const int proto)
1621 {
1622         heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1623         const char            *proto_name;
1624         heur_dtbl_entry_t     *hdtbl_entry;
1625
1626         /*
1627          * Make sure the dissector table exists.
1628          */
1629         if (sub_dissectors == NULL) {
1630                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
1631                     name);
1632                 proto_name = proto_get_protocol_name(proto);
1633                 if (proto_name != NULL) {
1634                         fprintf(stderr, "Protocol being registered is \"%s\"\n",
1635                             proto_name);
1636                 }
1637                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
1638                         abort();
1639                 return;
1640         }
1641
1642         /* XXX: Should verify that sub-dissector is not already in the list ? */
1643
1644         hdtbl_entry = g_malloc(sizeof (heur_dtbl_entry_t));
1645         hdtbl_entry->dissector = dissector;
1646         hdtbl_entry->protocol  = find_protocol_by_id(proto);
1647         hdtbl_entry->enabled   = TRUE;
1648
1649         /* do the table insertion */
1650         *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)hdtbl_entry);
1651 }
1652
1653
1654
1655 static int
1656 find_matching_heur_dissector( gconstpointer a, gconstpointer b) {
1657         const heur_dtbl_entry_t *hdtbl_entry_a = (const heur_dtbl_entry_t *) a;
1658         const heur_dtbl_entry_t *hdtbl_entry_b = (const heur_dtbl_entry_t *) b;
1659         return (hdtbl_entry_a->dissector == hdtbl_entry_b->dissector) &&
1660                 (hdtbl_entry_a->protocol == hdtbl_entry_b->protocol) ? 0 : 1;
1661 }
1662
1663 void
1664 heur_dissector_delete(const char *name, heur_dissector_t dissector, const int proto) {
1665         heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1666         heur_dtbl_entry_t      hdtbl_entry;
1667         GSList                *found_entry;
1668
1669         /* sanity check */
1670         g_assert(sub_dissectors != NULL);
1671
1672         hdtbl_entry.dissector = dissector;
1673
1674         hdtbl_entry.protocol  = find_protocol_by_id(proto);
1675
1676         found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &hdtbl_entry, find_matching_heur_dissector);
1677
1678         if (found_entry) {
1679                 *sub_dissectors = g_slist_remove_link(*sub_dissectors, found_entry);
1680                 g_free(g_slist_nth_data(found_entry, 1));
1681                 g_slist_free_1(found_entry);
1682         }
1683 }
1684
1685 void
1686 heur_dissector_set_enabled(const char *name, heur_dissector_t dissector, const int proto, const gboolean enabled) {
1687         heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1688         GSList                *found_entry;
1689         heur_dtbl_entry_t      hdtbl_entry;
1690
1691         /* sanity check */
1692         g_assert(sub_dissectors != NULL);
1693
1694         hdtbl_entry.dissector = dissector;
1695
1696         hdtbl_entry.protocol  = find_protocol_by_id(proto);
1697
1698         found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &hdtbl_entry, find_matching_heur_dissector);
1699
1700         if (found_entry) {
1701                 heur_dtbl_entry_t *hdtbl_entry_p;
1702                 hdtbl_entry_p = (heur_dtbl_entry_t *)found_entry->data;
1703                 hdtbl_entry_p->enabled = enabled;
1704         }
1705 }
1706
1707 gboolean
1708 dissector_try_heuristic(heur_dissector_list_t sub_dissectors, tvbuff_t *tvb,
1709                         packet_info *pinfo, proto_tree *tree, void *data)
1710 {
1711         gboolean           status;
1712         const char        *saved_proto;
1713         GSList            *entry;
1714         heur_dtbl_entry_t *hdtbl_entry;
1715         guint16            saved_can_desegment;
1716         gint               saved_layer_names_len = 0;
1717
1718         /* can_desegment is set to 2 by anyone which offers this api/service.
1719            then everytime a subdissector is called it is decremented by one.
1720            thus only the subdissector immediately ontop of whoever offers this
1721            service can use it.
1722            We save the current value of "can_desegment" for the
1723            benefit of TCP proxying dissectors such as SOCKS, so they
1724            can restore it and allow the dissectors they call to use
1725            the desegmentation service.
1726         */
1727         saved_can_desegment        = pinfo->can_desegment;
1728         pinfo->saved_can_desegment = saved_can_desegment;
1729         pinfo->can_desegment       = saved_can_desegment-(saved_can_desegment>0);
1730
1731         status      = FALSE;
1732         saved_proto = pinfo->current_proto;
1733
1734         if (pinfo->layer_names != NULL)
1735                 saved_layer_names_len = (gint) pinfo->layer_names->len;
1736
1737         for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1738                 /* XXX - why set this now and above? */
1739                 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1740                 hdtbl_entry = (heur_dtbl_entry_t *)entry->data;
1741
1742                 if (hdtbl_entry->protocol != NULL &&
1743                     (!proto_is_protocol_enabled(hdtbl_entry->protocol)||(hdtbl_entry->enabled==FALSE))) {
1744                         /*
1745                          * No - don't try this dissector.
1746                          */
1747                         continue;
1748                 }
1749
1750                 if (hdtbl_entry->protocol != NULL) {
1751                         pinfo->current_proto =
1752                                 proto_get_protocol_short_name(hdtbl_entry->protocol);
1753
1754                         /*
1755                          * Add the protocol name to the layers; we'll remove it
1756                          * if the dissector fails.
1757                          */
1758                         if (pinfo->layer_names) {
1759                                 if (pinfo->layer_names->len > 0)
1760                                         g_string_append(pinfo->layer_names, ":");
1761                                         g_string_append(pinfo->layer_names,
1762                                         proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol)));
1763                         }
1764                 }
1765                 EP_CHECK_CANARY(("before calling heuristic dissector for protocol: %s",
1766                                  proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol))));
1767                 if ((*hdtbl_entry->dissector)(tvb, pinfo, tree, data)) {
1768                         EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has accepted and dissected packet",
1769                                          proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol))));
1770                         status = TRUE;
1771                         break;
1772                 } else {
1773                         EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has returned false",
1774                                          proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol))));
1775
1776                         /*
1777                          * That dissector didn't accept the packet, so
1778                          * remove its protocol's name from the list
1779                          * of protocols.
1780                          */
1781                         if (pinfo->layer_names != NULL) {
1782                                 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
1783                         }
1784                 }
1785         }
1786         pinfo->current_proto = saved_proto;
1787         pinfo->can_desegment=saved_can_desegment;
1788         return status;
1789 }
1790
1791 /*
1792  * Called for each entry in the table of all heuristic dissector tables.
1793  */
1794 typedef struct heur_dissector_foreach_table_info {
1795         gpointer           caller_data;
1796         DATFunc_heur_table caller_func;
1797 } heur_dissector_foreach_table_info_t;
1798
1799
1800 static void
1801 dissector_dump_heur_decodes_display(const gchar *table_name, const gpointer value, const gpointer user_data _U_)
1802 {
1803         heur_dissector_list_t  sub_dissectors = *(heur_dissector_list_t *)value;
1804         GSList                *entry;
1805         heur_dtbl_entry_t     *hdtbl_entry;
1806
1807         for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1808                 hdtbl_entry = (heur_dtbl_entry_t *)entry->data;
1809                 if (hdtbl_entry->protocol != NULL) {
1810                         printf("%s\t%s\t%c\n",
1811                                table_name,
1812                                proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol)),
1813                                (proto_is_protocol_enabled(hdtbl_entry->protocol) && hdtbl_entry->enabled) ? 'T' : 'F');
1814                 }
1815         }
1816 }
1817
1818
1819 static void
1820 dissector_all_heur_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
1821 {
1822         heur_dissector_foreach_table_info_t *info;
1823
1824         info = user_data;
1825         (*info->caller_func)((gchar*)key, value, info->caller_data);
1826 }
1827
1828 /*
1829  * Walk all heuristic dissector tables calling a user supplied function on each
1830  * table.
1831  */
1832 void
1833 dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
1834                                          gpointer user_data)
1835 {
1836         heur_dissector_foreach_table_info_t info;
1837
1838         info.caller_data = user_data;
1839         info.caller_func = func;
1840         g_hash_table_foreach(heur_dissector_lists, dissector_all_heur_tables_foreach_table_func, &info);
1841 }
1842
1843 /*
1844  * For each heuristic dissector table, dump list of dissectors (filter_names) for that table
1845  */
1846 void
1847 dissector_dump_heur_decodes(void)
1848 {
1849         dissector_all_heur_tables_foreach_table(dissector_dump_heur_decodes_display, NULL);
1850 }
1851
1852
1853 void
1854 register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
1855 {
1856         /* Create our hash-of-lists if it doesn't already exist */
1857         if (heur_dissector_lists == NULL) {
1858                 heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
1859                 g_assert(heur_dissector_lists != NULL);
1860         }
1861
1862         /* Make sure the registration is unique */
1863         g_assert(g_hash_table_lookup(heur_dissector_lists, name) == NULL);
1864
1865         *sub_dissectors = NULL; /* initially empty */
1866         g_hash_table_insert(heur_dissector_lists, (gpointer)name,
1867                             (gpointer) sub_dissectors);
1868 }
1869
1870 /*
1871  * Register dissectors by name; used if one dissector always calls a
1872  * particular dissector, or if it bases the decision of which dissector
1873  * to call on something other than a numerical value or on "try a bunch
1874  * of dissectors until one likes the packet".
1875  */
1876
1877 /*
1878  * List of registered dissectors.
1879  */
1880 static GHashTable *registered_dissectors = NULL;
1881
1882 /* Get the long name of the protocol for a dissector handle, if it has
1883    a protocol. */
1884 const char *
1885 dissector_handle_get_long_name(const dissector_handle_t handle)
1886 {
1887         if (handle == NULL || handle->protocol == NULL) {
1888                 return NULL;
1889         }
1890         return proto_get_protocol_long_name(handle->protocol);
1891 }
1892
1893 /* Get the short name of the protocol for a dissector handle, if it has
1894    a protocol. */
1895 const char *
1896 dissector_handle_get_short_name(const dissector_handle_t handle)
1897 {
1898         if (handle->protocol == NULL) {
1899                 /*
1900                  * No protocol (see, for example, the handle for
1901                  * dissecting the set of protocols where the first
1902                  * octet of the payload is an OSI network layer protocol
1903                  * ID).
1904                  */
1905                 return NULL;
1906         }
1907         return proto_get_protocol_short_name(handle->protocol);
1908 }
1909
1910 /* Get the index of the protocol for a dissector handle, if it has
1911    a protocol. */
1912 int
1913 dissector_handle_get_protocol_index(const dissector_handle_t handle)
1914 {
1915         if (handle->protocol == NULL) {
1916                 /*
1917                  * No protocol (see, for example, the handle for
1918                  * dissecting the set of protocols where the first
1919                  * octet of the payload is an OSI network layer protocol
1920                  * ID).
1921                  */
1922                 return -1;
1923         }
1924         return proto_get_id(handle->protocol);
1925 }
1926
1927 /* Find a registered dissector by name. */
1928 dissector_handle_t
1929 find_dissector(const char *name)
1930 {
1931         g_assert(registered_dissectors != NULL);
1932         return g_hash_table_lookup(registered_dissectors, name);
1933 }
1934
1935 /* Create an anonymous handle for a dissector. */
1936 dissector_handle_t
1937 create_dissector_handle(dissector_t dissector, const int proto)
1938 {
1939         struct dissector_handle *handle;
1940
1941         handle                = g_malloc(sizeof (struct dissector_handle));
1942         handle->name          = NULL;
1943         handle->is_new        = FALSE;
1944         handle->dissector.old = dissector;
1945         handle->protocol      = find_protocol_by_id(proto);
1946
1947         return handle;
1948 }
1949
1950 dissector_handle_t
1951 new_create_dissector_handle(new_dissector_t dissector, const int proto)
1952 {
1953         struct dissector_handle *handle;
1954
1955         handle                = g_malloc(sizeof (struct dissector_handle));
1956         handle->name          = NULL;
1957         handle->is_new        = TRUE;
1958         handle->dissector.new = dissector;
1959         handle->protocol      = find_protocol_by_id(proto);
1960
1961         return handle;
1962 }
1963
1964 /* Register a dissector by name. */
1965 void
1966 register_dissector(const char *name, dissector_t dissector, const int proto)
1967 {
1968         struct dissector_handle *handle;
1969
1970         /* Create our hash table if it doesn't already exist */
1971         if (registered_dissectors == NULL) {
1972                 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1973                 g_assert(registered_dissectors != NULL);
1974         }
1975
1976         /* Make sure the registration is unique */
1977         g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1978
1979         handle                = g_malloc(sizeof (struct dissector_handle));
1980         handle->name          = name;
1981         handle->is_new        = FALSE;
1982         handle->dissector.old = dissector;
1983         handle->protocol      = find_protocol_by_id(proto);
1984
1985         g_hash_table_insert(registered_dissectors, (gpointer)name,
1986                             (gpointer) handle);
1987 }
1988
1989 void
1990 new_register_dissector(const char *name, new_dissector_t dissector, const int proto)
1991 {
1992         struct dissector_handle *handle;
1993
1994         /* Create our hash table if it doesn't already exist */
1995         if (registered_dissectors == NULL) {
1996                 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1997                 g_assert(registered_dissectors != NULL);
1998         }
1999
2000         /* Make sure the registration is unique */
2001         g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
2002
2003         handle                = g_malloc(sizeof (struct dissector_handle));
2004         handle->name          = name;
2005         handle->is_new        = TRUE;
2006         handle->dissector.new = dissector;
2007         handle->protocol      = find_protocol_by_id(proto);
2008
2009         g_hash_table_insert(registered_dissectors, (gpointer)name,
2010                             (gpointer) handle);
2011 }
2012
2013 /* Call a dissector through a handle but if the dissector rejected it
2014  * return 0.
2015  */
2016 int
2017 call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
2018                     packet_info *pinfo, proto_tree *tree, void *data)
2019 {
2020         int ret;
2021
2022         g_assert(handle != NULL);
2023         ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE, data);
2024         return ret;
2025 }
2026
2027 /* Call a dissector through a handle and if this fails call the "data"
2028  * dissector.
2029  */
2030 int
2031 call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
2032                packet_info *pinfo, proto_tree *tree)
2033 {
2034         int ret;
2035
2036         ret = call_dissector_only(handle, tvb, pinfo, tree, NULL);
2037         if (ret == 0) {
2038                 /*
2039                  * The protocol was disabled, or the dissector rejected
2040                  * it.  Just dissect this packet as data.
2041                  */
2042                 g_assert(data_handle != NULL);
2043                 g_assert(data_handle->protocol != NULL);
2044                 call_dissector_work(data_handle, tvb, pinfo, tree, TRUE, NULL);
2045                 return tvb_length(tvb);
2046         }
2047         return ret;
2048 }
2049
2050 /*
2051  * Dumps the "layer type"/"decode as" associations to stdout, similar
2052  * to the proto_registrar_dump_*() routines.
2053  *
2054  * There is one record per line. The fields are tab-delimited.
2055  *
2056  * Field 1 = layer type, e.g. "tcp.port"
2057  * Field 2 = selector in decimal
2058  * Field 3 = "decode as" name, e.g. "http"
2059  */
2060
2061
2062 static void
2063 dissector_dump_decodes_display(const gchar *table_name,
2064                                ftenum_t selector_type _U_, const gpointer key, const gpointer value,
2065                                gpointer user_data _U_)
2066 {
2067         guint32             selector       = (guint32)(unsigned long) key;
2068         dissector_table_t   sub_dissectors = find_dissector_table(table_name);
2069         dtbl_entry_t       *dtbl_entry;
2070         dissector_handle_t  handle;
2071         gint                proto_id;
2072         const gchar        *decode_as;
2073
2074         g_assert(sub_dissectors);
2075         switch (sub_dissectors->type) {
2076
2077                 case FT_UINT8:
2078                 case FT_UINT16:
2079                 case FT_UINT24:
2080                 case FT_UINT32:
2081                         dtbl_entry = value;
2082                         g_assert(dtbl_entry);
2083
2084                         handle   = dtbl_entry->current;
2085                         g_assert(handle);
2086
2087                         proto_id = dissector_handle_get_protocol_index(handle);
2088
2089                         if (proto_id != -1) {
2090                                 decode_as = proto_get_protocol_filter_name(proto_id);
2091                                 g_assert(decode_as != NULL);
2092                                 printf("%s\t%u\t%s\n", table_name, selector, decode_as);
2093                         }
2094                         break;
2095
2096         default:
2097                 break;
2098         }
2099 }
2100
2101 void
2102 dissector_dump_decodes(void)
2103 {
2104         dissector_all_tables_foreach(dissector_dump_decodes_display, NULL);
2105 }
2106
2107 static GPtrArray* post_dissectors = NULL;
2108 static guint num_of_postdissectors = 0;
2109
2110 void
2111 register_postdissector(dissector_handle_t handle)
2112 {
2113         if (!post_dissectors)
2114                 post_dissectors = g_ptr_array_new();
2115
2116         g_ptr_array_add(post_dissectors, handle);
2117         num_of_postdissectors++;
2118 }
2119
2120 gboolean
2121 have_postdissector(void)
2122 {
2123         guint i;
2124         dissector_handle_t handle;
2125
2126         for(i = 0; i < num_of_postdissectors; i++) {
2127                 handle = (dissector_handle_t) g_ptr_array_index(post_dissectors,i);
2128
2129                 if (handle->protocol != NULL
2130                     && proto_is_protocol_enabled(handle->protocol)) {
2131                         /* We have at least one enabled postdissector */
2132                         return TRUE;
2133                 }
2134         }
2135         return FALSE;
2136 }
2137
2138 void
2139 call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2140 {
2141         guint i;
2142
2143         for(i = 0; i < num_of_postdissectors; i++) {
2144                 call_dissector_only((dissector_handle_t) g_ptr_array_index(post_dissectors,i),
2145                                     tvb,pinfo,tree, NULL);
2146         }
2147 }
2148
2149 /*
2150  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
2151  *
2152  * Local variables:
2153  * c-basic-offset: 8
2154  * tab-width: 8
2155  * indent-tabs-mode: t
2156  * End:
2157  *
2158  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
2159  * :indentSize=8:tabSize=8:noTabs=false:
2160  */