Add IPv6 heuristic.
[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, 
901                        const gboolean add_proto_name, void *data)
902 {
903         dtbl_entry_t            *dtbl_entry;
904         struct dissector_handle *handle;
905         guint32                  saved_match_uint;
906         int ret;
907
908         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, uint_val);
909         if (dtbl_entry != NULL) {
910                 /*
911                  * Is there currently a dissector handle for this entry?
912                  */
913                 handle = dtbl_entry->current;
914                 if (handle == NULL) {
915                         /*
916                          * No - pretend this dissector didn't exist,
917                          * so that other dissectors might have a chance
918                          * to dissect this packet.
919                          */
920                         return FALSE;
921                 }
922
923                 /*
924                  * Save the current value of "pinfo->match_uint",
925                  * set it to the uint_val that matched, call the
926                  * dissector, and restore "pinfo->match_uint".
927                  */
928                 saved_match_uint  = pinfo->match_uint;
929                 pinfo->match_uint = uint_val;
930                 ret = call_dissector_work(handle, tvb, pinfo, tree, add_proto_name, data);
931                 pinfo->match_uint = saved_match_uint;
932
933                 /*
934                  * If a new-style dissector returned 0, it means that
935                  * it didn't think this tvbuff represented a packet for
936                  * its protocol, and didn't dissect anything.
937                  *
938                  * Old-style dissectors can't reject the packet.
939                  *
940                  * 0 is also returned if the protocol wasn't enabled.
941                  *
942                  * If the packet was rejected, we return FALSE, so that
943                  * other dissectors might have a chance to dissect this
944                  * packet, otherwise we return TRUE.
945                  */
946                 return ret != 0;
947         }
948         return FALSE;
949 }
950
951 gboolean
952 dissector_try_uint(dissector_table_t sub_dissectors, const guint32 uint_val,
953                    tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
954 {
955
956         return dissector_try_uint_new(sub_dissectors, uint_val, tvb, pinfo, tree, TRUE, NULL);
957 }
958
959 /* Look for a given value in a given uint dissector table and, if found,
960    return the dissector handle for that value. */
961 dissector_handle_t
962 dissector_get_uint_handle(dissector_table_t const sub_dissectors, const guint32 uint_val)
963 {
964         dtbl_entry_t *dtbl_entry;
965
966         dtbl_entry = find_uint_dtbl_entry(sub_dissectors, uint_val);
967         if (dtbl_entry != NULL)
968                 return dtbl_entry->current;
969         else
970                 return NULL;
971 }
972
973 /* Find an entry in a string dissector table. */
974 static dtbl_entry_t *
975 find_string_dtbl_entry(dissector_table_t const sub_dissectors, const gchar *pattern)
976 {
977         switch (sub_dissectors->type) {
978
979         case FT_STRING:
980         case FT_STRINGZ:
981                 /*
982                  * You can do a string lookup in these tables.
983                  */
984                 break;
985
986         default:
987                 /*
988                  * But you can't do a string lookup in any other types
989                  * of tables.
990                  */
991                 g_assert_not_reached();
992         }
993
994         /*
995          * Find the entry.
996          */
997         return g_hash_table_lookup(sub_dissectors->hash_table, pattern);
998 }
999
1000 /* Add an entry to a string dissector table. */
1001 void
1002 dissector_add_string(const char *name, const gchar *pattern,
1003                      dissector_handle_t handle)
1004 {
1005         dissector_table_t  sub_dissectors = find_dissector_table( name);
1006         dtbl_entry_t      *dtbl_entry;
1007
1008         /*
1009          * Make sure the dissector table exists.
1010          */
1011         if (sub_dissectors == NULL) {
1012                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
1013                     name);
1014                 fprintf(stderr, "Protocol being registered is \"%s\"\n",
1015                     proto_get_protocol_long_name(handle->protocol));
1016                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
1017                         abort();
1018                 return;
1019         }
1020
1021         /* sanity checks */
1022         g_assert(handle!=NULL);
1023         switch (sub_dissectors->type) {
1024
1025         case FT_STRING:
1026         case FT_STRINGZ:
1027                 /*
1028                  * You can do a string lookup in these tables.
1029                  */
1030                 break;
1031
1032         default:
1033                 /*
1034                  * But you can't do a string lookup in any other types
1035                  * of tables.
1036                  */
1037                 g_assert_not_reached();
1038         }
1039
1040         dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1041         dtbl_entry->current = handle;
1042         dtbl_entry->initial = dtbl_entry->current;
1043
1044         /* do the table insertion */
1045         g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1046                              (gpointer)dtbl_entry);
1047
1048         /*
1049          * Now add it to the list of handles that could be used with this
1050          * table, because it *is* being used with this table.
1051          */
1052         dissector_add_handle(name, handle);
1053 }
1054
1055 /* Delete the entry for a dissector in a string dissector table
1056    with a particular pattern. */
1057
1058 /* NOTE: this doesn't use the dissector call variable. It is included to */
1059 /*      be consistant with the dissector_add_string and more importantly to */
1060 /*      be used if the technique of adding a temporary dissector is */
1061 /*      implemented.  */
1062 /*      If temporary dissectors are deleted, then the original dissector must */
1063 /*      be available. */
1064 void
1065 dissector_delete_string(const char *name, const gchar *pattern,
1066         dissector_handle_t handle _U_)
1067 {
1068         dissector_table_t  sub_dissectors = find_dissector_table( name);
1069         dtbl_entry_t      *dtbl_entry;
1070
1071         /* sanity check */
1072         g_assert( sub_dissectors);
1073
1074         /*
1075          * Find the entry.
1076          */
1077         dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1078
1079         if (dtbl_entry != NULL) {
1080                 /*
1081                  * Found - remove it.
1082                  */
1083                 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1084         }
1085 }
1086
1087 /* Change the entry for a dissector in a string dissector table
1088    with a particular pattern to use a new dissector handle. */
1089 void
1090 dissector_change_string(const char *name, const gchar *pattern,
1091                         dissector_handle_t handle)
1092 {
1093         dissector_table_t  sub_dissectors = find_dissector_table( name);
1094         dtbl_entry_t      *dtbl_entry;
1095
1096         /* sanity check */
1097         g_assert( sub_dissectors);
1098
1099         /*
1100          * See if the entry already exists. If so, reuse it.
1101          */
1102         dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1103         if (dtbl_entry != NULL) {
1104                 dtbl_entry->current = handle;
1105                 return;
1106         }
1107
1108         /*
1109          * Don't create an entry if there is no dissector handle - I.E. the
1110          * user said not to decode something that wasn't being decoded
1111          * in the first place.
1112          */
1113         if (handle == NULL)
1114                 return;
1115
1116         dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
1117         dtbl_entry->initial = NULL;
1118         dtbl_entry->current = handle;
1119
1120         /* do the table insertion */
1121         g_hash_table_insert( sub_dissectors->hash_table, (gpointer)pattern,
1122                              (gpointer)dtbl_entry);
1123 }
1124
1125 /* Reset an entry in a string sub-dissector table to its initial value. */
1126 void
1127 dissector_reset_string(const char *name, const gchar *pattern)
1128 {
1129         dissector_table_t  sub_dissectors = find_dissector_table( name);
1130         dtbl_entry_t      *dtbl_entry;
1131
1132         /* sanity check */
1133         g_assert( sub_dissectors);
1134
1135         /*
1136          * Find the entry.
1137          */
1138         dtbl_entry = find_string_dtbl_entry(sub_dissectors, pattern);
1139
1140         if (dtbl_entry == NULL)
1141                 return;
1142
1143         /*
1144          * Found - is there an initial value?
1145          */
1146         if (dtbl_entry->initial != NULL) {
1147                 dtbl_entry->current = dtbl_entry->initial;
1148         } else {
1149                 g_hash_table_remove(sub_dissectors->hash_table, pattern);
1150         }
1151 }
1152
1153 /* Look for a given string in a given dissector table and, if found, call
1154    the dissector with the arguments supplied, and return TRUE, otherwise
1155    return FALSE. */
1156 gboolean
1157 dissector_try_string(dissector_table_t sub_dissectors, const gchar *string,
1158                      tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1159 {
1160         dtbl_entry_t            *dtbl_entry;
1161         struct dissector_handle *handle;
1162         int                      ret;
1163         const gchar             *saved_match_string;
1164
1165         /* XXX ASSERT instead ? */
1166         if (!string) return FALSE;
1167         dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1168         if (dtbl_entry != NULL) {
1169                 /*
1170                  * Is there currently a dissector handle for this entry?
1171                  */
1172                 handle = dtbl_entry->current;
1173                 if (handle == NULL) {
1174                         /*
1175                          * No - pretend this dissector didn't exist,
1176                          * so that other dissectors might have a chance
1177                          * to dissect this packet.
1178                          */
1179                         return FALSE;
1180                 }
1181
1182                 /*
1183                  * Save the current value of "pinfo->match_string",
1184                  * set it to the string that matched, call the
1185                  * dissector, and restore "pinfo->match_string".
1186                  */
1187                 saved_match_string = pinfo->match_string;
1188                 pinfo->match_string = string;
1189                 ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE, NULL);
1190                 pinfo->match_string = saved_match_string;
1191
1192                 /*
1193                  * If a new-style dissector returned 0, it means that
1194                  * it didn't think this tvbuff represented a packet for
1195                  * its protocol, and didn't dissect anything.
1196                  *
1197                  * Old-style dissectors can't reject the packet.
1198                  *
1199                  * 0 is also returned if the protocol wasn't enabled.
1200                  *
1201                  * If the packet was rejected, we return FALSE, so that
1202                  * other dissectors might have a chance to dissect this
1203                  * packet, otherwise we return TRUE.
1204                  */
1205                 return ret != 0;
1206         }
1207         return FALSE;
1208 }
1209
1210 /* Look for a given value in a given string dissector table and, if found,
1211    return the dissector handle for that value. */
1212 dissector_handle_t
1213 dissector_get_string_handle(dissector_table_t sub_dissectors,
1214                             const gchar *string)
1215 {
1216         dtbl_entry_t *dtbl_entry;
1217
1218         dtbl_entry = find_string_dtbl_entry(sub_dissectors, string);
1219         if (dtbl_entry != NULL)
1220                 return dtbl_entry->current;
1221         else
1222                 return NULL;
1223 }
1224
1225 dissector_handle_t
1226 dtbl_entry_get_handle (dtbl_entry_t *dtbl_entry)
1227 {
1228         return dtbl_entry->current;
1229 }
1230
1231 gint
1232 dissector_compare_filter_name(gconstpointer dissector_a, gconstpointer dissector_b)
1233 {
1234         dissector_handle_t a = (dissector_handle_t)dissector_a;
1235         dissector_handle_t b = (dissector_handle_t)dissector_b;
1236         const char *a_name, *b_name;
1237         gint ret;
1238
1239         if (a->protocol == NULL)
1240                 a_name = "";
1241         else
1242                 a_name = proto_get_protocol_filter_name(proto_get_id(a->protocol));
1243
1244         if (b->protocol == NULL)
1245                 b_name = "";
1246         else
1247                 b_name = proto_get_protocol_filter_name(proto_get_id(b->protocol));
1248
1249         ret = strcmp(a_name, b_name); 
1250         return ret;
1251 }
1252
1253 /* Add a handle to the list of handles that *could* be used with this
1254    table.  That list is used by code in the UI. */
1255 void
1256 dissector_add_handle(const char *name, dissector_handle_t handle)
1257 {
1258         dissector_table_t  sub_dissectors = find_dissector_table( name);
1259         GSList            *entry;
1260
1261         /*
1262          * Make sure the dissector table exists.
1263          */
1264         if (sub_dissectors == NULL) {
1265                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
1266                     name);
1267                 fprintf(stderr, "Protocol being registered is \"%s\"\n",
1268                     proto_get_protocol_long_name(handle->protocol));
1269                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
1270                         abort();
1271                 return;
1272         }
1273
1274         /* Is it already in this list? */
1275         entry = g_slist_find(sub_dissectors->dissector_handles, (gpointer)handle);
1276         if (entry != NULL) {
1277                 /*
1278                  * Yes - don't insert it again.
1279                  */
1280                 return;
1281         }
1282
1283         /* Add it to the list. */
1284         sub_dissectors->dissector_handles =
1285                 g_slist_insert_sorted(sub_dissectors->dissector_handles, (gpointer)handle, (GCompareFunc)dissector_compare_filter_name);
1286 }
1287
1288 dissector_handle_t
1289 dtbl_entry_get_initial_handle (dtbl_entry_t *dtbl_entry)
1290 {
1291         return dtbl_entry->initial;
1292 }
1293
1294 /**************************************************/
1295 /*                                                */
1296 /*       Routines to walk dissector tables        */
1297 /*                                                */
1298 /**************************************************/
1299
1300 typedef struct dissector_foreach_info {
1301         gpointer      caller_data;
1302         DATFunc       caller_func;
1303         GHFunc        next_func;
1304         const gchar  *table_name;
1305         ftenum_t      selector_type;
1306 } dissector_foreach_info_t;
1307
1308 /*
1309  * Called for each entry in a dissector table.
1310  */
1311 static void
1312 dissector_table_foreach_func (gpointer key, gpointer value, gpointer user_data)
1313 {
1314         dissector_foreach_info_t *info;
1315         dtbl_entry_t             *dtbl_entry;
1316
1317         g_assert(value);
1318         g_assert(user_data);
1319
1320         dtbl_entry = value;
1321         if (dtbl_entry->current == NULL ||
1322             dtbl_entry->current->protocol == NULL) {
1323                 /*
1324                  * Either there is no dissector for this entry, or
1325                  * the dissector doesn't have a protocol associated
1326                  * with it.
1327                  *
1328                  * XXX - should the latter check be done?
1329                  */
1330                 return;
1331         }
1332
1333         info = user_data;
1334         info->caller_func(info->table_name, info->selector_type, key, value,
1335                           info->caller_data);
1336 }
1337
1338 /*
1339  * Called for each entry in the table of all dissector tables.
1340  */
1341 static void
1342 dissector_all_tables_foreach_func (gpointer key, gpointer value, gpointer user_data)
1343 {
1344         dissector_table_t         sub_dissectors;
1345         dissector_foreach_info_t *info;
1346
1347         g_assert(value);
1348         g_assert(user_data);
1349
1350         sub_dissectors = value;
1351         info = user_data;
1352         info->table_name = (gchar*) key;
1353         info->selector_type = get_dissector_table_selector_type(info->table_name);
1354         g_hash_table_foreach(sub_dissectors->hash_table, info->next_func, info);
1355 }
1356
1357 /*
1358  * Walk all dissector tables calling a user supplied function on each
1359  * entry.
1360  */
1361 static void
1362 dissector_all_tables_foreach (DATFunc func,
1363                               gpointer user_data)
1364 {
1365         dissector_foreach_info_t info;
1366
1367         info.caller_data = user_data;
1368         info.caller_func = func;
1369         info.next_func   = dissector_table_foreach_func;
1370         g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1371 }
1372
1373 /*
1374  * Walk one dissector table's hash table calling a user supplied function
1375  * on each entry.
1376  */
1377 void
1378 dissector_table_foreach (const char *name,
1379                          DATFunc     func,
1380                          gpointer    user_data)
1381 {
1382         dissector_foreach_info_t info;
1383         dissector_table_t        sub_dissectors = find_dissector_table( name);
1384
1385         info.table_name    = name;
1386         info.selector_type = sub_dissectors->type;
1387         info.caller_func   = func;
1388         info.caller_data   = user_data;
1389         g_hash_table_foreach(sub_dissectors->hash_table, dissector_table_foreach_func, &info);
1390 }
1391
1392 /*
1393  * Walk one dissector table's list of handles calling a user supplied
1394  * function on each entry.
1395  */
1396 void
1397 dissector_table_foreach_handle(const char     *name,
1398                                DATFunc_handle  func,
1399                                gpointer        user_data)
1400 {
1401         dissector_table_t sub_dissectors = find_dissector_table( name);
1402         GSList *tmp;
1403
1404         for (tmp = sub_dissectors->dissector_handles; tmp != NULL;
1405              tmp = g_slist_next(tmp))
1406                 func(name, tmp->data, user_data);
1407 }
1408
1409 /*
1410  * Called for each entry in a dissector table.
1411  */
1412 static void
1413 dissector_table_foreach_changed_func (gpointer key, gpointer value, gpointer user_data)
1414 {
1415         dtbl_entry_t             *dtbl_entry;
1416         dissector_foreach_info_t *info;
1417
1418         g_assert(value);
1419         g_assert(user_data);
1420
1421         dtbl_entry = value;
1422         if (dtbl_entry->initial == dtbl_entry->current) {
1423                 /*
1424                  * Entry hasn't changed - don't call the function.
1425                  */
1426                 return;
1427         }
1428
1429         info = user_data;
1430         info->caller_func(info->table_name, info->selector_type, key, value,
1431                           info->caller_data);
1432 }
1433
1434 /*
1435  * Walk all dissector tables calling a user supplied function only on
1436  * any entry that has been changed from its original state.
1437  */
1438 void
1439 dissector_all_tables_foreach_changed (DATFunc  func,
1440                                       gpointer user_data)
1441 {
1442         dissector_foreach_info_t info;
1443
1444         info.caller_data = user_data;
1445         info.caller_func = func;
1446         info.next_func   = dissector_table_foreach_changed_func;
1447         g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_func, &info);
1448 }
1449
1450 /*
1451  * Walk one dissector table calling a user supplied function only on
1452  * any entry that has been changed from its original state.
1453  */
1454 void
1455 dissector_table_foreach_changed (const char *name,
1456                                  DATFunc     func,
1457                                  gpointer    user_data)
1458 {
1459         dissector_foreach_info_t info;
1460         dissector_table_t sub_dissectors = find_dissector_table( name);
1461
1462         info.table_name    = name;
1463         info.selector_type = sub_dissectors->type;
1464         info.caller_func   = func;
1465         info.caller_data   = user_data;
1466         g_hash_table_foreach(sub_dissectors->hash_table,
1467                              dissector_table_foreach_changed_func, &info);
1468 }
1469
1470 typedef struct dissector_foreach_table_info {
1471         gpointer      caller_data;
1472         DATFunc_table caller_func;
1473 } dissector_foreach_table_info_t;
1474
1475 /*
1476  * Called for each entry in the table of all dissector tables.
1477  */
1478 static void
1479 dissector_all_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
1480 {
1481         dissector_table_t               table;
1482         dissector_foreach_table_info_t *info;
1483
1484         table = value;
1485         info = user_data;
1486         (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1487 }
1488
1489 /*
1490  * Called for each key in the table of all dissector tables.
1491  */
1492 static void
1493 dissector_all_tables_foreach_list_func (gpointer key, gpointer user_data)
1494 {
1495         dissector_table_t               table;
1496         dissector_foreach_table_info_t *info;
1497
1498         table = g_hash_table_lookup( dissector_tables, key );
1499         info = user_data;
1500         (*info->caller_func)((gchar*)key, table->ui_name, info->caller_data);
1501 }
1502
1503 /*
1504  * Walk all dissector tables calling a user supplied function on each
1505  * table.
1506  */
1507 void
1508 dissector_all_tables_foreach_table (DATFunc_table func,
1509                                         gpointer      user_data,
1510                                         GCompareFunc compare_key_func)
1511 {
1512         dissector_foreach_table_info_t info;
1513         GList* list;
1514
1515         info.caller_data = user_data;
1516         info.caller_func = func;
1517         if (compare_key_func != NULL)
1518         {
1519                 list = g_hash_table_get_keys(dissector_tables);
1520                 list = g_list_sort(list, compare_key_func);
1521                 g_list_foreach(list, dissector_all_tables_foreach_list_func, &info);
1522                 g_list_free(list);
1523         }
1524         else
1525         {
1526                 g_hash_table_foreach(dissector_tables, dissector_all_tables_foreach_table_func, &info);
1527         }
1528 }
1529
1530 dissector_table_t
1531 register_dissector_table(const char *name, const char *ui_name, const ftenum_t type,
1532                          const int base)
1533 {
1534         dissector_table_t       sub_dissectors;
1535
1536         /* Create our hash-of-hashes if it doesn't already exist */
1537         if (!dissector_tables) {
1538                 dissector_tables = g_hash_table_new( g_str_hash, g_str_equal );
1539                 g_assert(dissector_tables);
1540         }
1541
1542         /* Make sure the registration is unique */
1543         if(g_hash_table_lookup( dissector_tables, name )) {
1544                 g_error("The filter name %s (%s) is already registered - do you use a buggy plugin?", name, ui_name);
1545         }
1546
1547         /* Create and register the dissector table for this name; returns */
1548         /* a pointer to the dissector table. */
1549         sub_dissectors = g_malloc(sizeof (struct dissector_table));
1550         switch (type) {
1551
1552         case FT_UINT8:
1553         case FT_UINT16:
1554         case FT_UINT24:
1555         case FT_UINT32:
1556                 /*
1557                  * XXX - there's no "g_uint_hash()" or "g_uint_equal()",
1558                  * so we use "g_direct_hash()" and "g_direct_equal()".
1559                  */
1560                 sub_dissectors->hash_table = g_hash_table_new_full( g_direct_hash,
1561                                                                g_direct_equal,
1562                                                                NULL,
1563                                                                &g_free );
1564                 break;
1565
1566         case FT_STRING:
1567         case FT_STRINGZ:
1568                 sub_dissectors->hash_table = g_hash_table_new_full( g_str_hash,
1569                                                                g_str_equal,
1570                                                                NULL,
1571                                                                &g_free );
1572                 break;
1573
1574         default:
1575                 g_assert_not_reached();
1576         }
1577         sub_dissectors->dissector_handles = NULL;
1578         sub_dissectors->ui_name = ui_name;
1579         sub_dissectors->type    = type;
1580         sub_dissectors->base    = base;
1581         g_hash_table_insert( dissector_tables, (gpointer)name, (gpointer) sub_dissectors );
1582         return sub_dissectors;
1583 }
1584
1585 const char *
1586 get_dissector_table_ui_name(const char *name)
1587 {
1588         dissector_table_t sub_dissectors = find_dissector_table( name);
1589
1590         return sub_dissectors->ui_name;
1591 }
1592
1593 ftenum_t
1594 get_dissector_table_selector_type(const char *name)
1595 {
1596         dissector_table_t sub_dissectors = find_dissector_table( name);
1597
1598         return sub_dissectors->type;
1599 }
1600
1601 int
1602 get_dissector_table_base(const char *name)
1603 {
1604         dissector_table_t sub_dissectors = find_dissector_table( name);
1605
1606         return sub_dissectors->base;
1607 }
1608
1609 static GHashTable *heur_dissector_lists = NULL;
1610
1611
1612 /* Finds a heuristic dissector table by table name. */
1613 static heur_dissector_list_t *
1614 find_heur_dissector_list(const char *name)
1615 {
1616         g_assert(heur_dissector_lists != NULL);
1617         return g_hash_table_lookup(heur_dissector_lists, name);
1618 }
1619
1620 void
1621 heur_dissector_add(const char *name, heur_dissector_t dissector, const int proto)
1622 {
1623         heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1624         const char            *proto_name;
1625         heur_dtbl_entry_t     *hdtbl_entry;
1626
1627         /*
1628          * Make sure the dissector table exists.
1629          */
1630         if (sub_dissectors == NULL) {
1631                 fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
1632                     name);
1633                 proto_name = proto_get_protocol_name(proto);
1634                 if (proto_name != NULL) {
1635                         fprintf(stderr, "Protocol being registered is \"%s\"\n",
1636                             proto_name);
1637                 }
1638                 if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
1639                         abort();
1640                 return;
1641         }
1642
1643         /* XXX: Should verify that sub-dissector is not already in the list ? */
1644
1645         hdtbl_entry = g_malloc(sizeof (heur_dtbl_entry_t));
1646         hdtbl_entry->dissector = dissector;
1647         hdtbl_entry->protocol  = find_protocol_by_id(proto);
1648         hdtbl_entry->enabled   = TRUE;
1649
1650         /* do the table insertion */
1651         *sub_dissectors = g_slist_append(*sub_dissectors, (gpointer)hdtbl_entry);
1652 }
1653
1654
1655
1656 static int
1657 find_matching_heur_dissector( gconstpointer a, gconstpointer b) {
1658         const heur_dtbl_entry_t *hdtbl_entry_a = (const heur_dtbl_entry_t *) a;
1659         const heur_dtbl_entry_t *hdtbl_entry_b = (const heur_dtbl_entry_t *) b;
1660         return (hdtbl_entry_a->dissector == hdtbl_entry_b->dissector) &&
1661                 (hdtbl_entry_a->protocol == hdtbl_entry_b->protocol) ? 0 : 1;
1662 }
1663
1664 void
1665 heur_dissector_delete(const char *name, heur_dissector_t dissector, const int proto) {
1666         heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1667         heur_dtbl_entry_t      hdtbl_entry;
1668         GSList                *found_entry;
1669
1670         /* sanity check */
1671         g_assert(sub_dissectors != NULL);
1672
1673         hdtbl_entry.dissector = dissector;
1674
1675         hdtbl_entry.protocol  = find_protocol_by_id(proto);
1676
1677         found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &hdtbl_entry, find_matching_heur_dissector);
1678
1679         if (found_entry) {
1680                 *sub_dissectors = g_slist_remove_link(*sub_dissectors, found_entry);
1681                 g_free(g_slist_nth_data(found_entry, 1));
1682                 g_slist_free_1(found_entry);
1683         }
1684 }
1685
1686 void
1687 heur_dissector_set_enabled(const char *name, heur_dissector_t dissector, const int proto, const gboolean enabled) {
1688         heur_dissector_list_t *sub_dissectors = find_heur_dissector_list(name);
1689         GSList                *found_entry;
1690         heur_dtbl_entry_t      hdtbl_entry;
1691
1692         /* sanity check */
1693         g_assert(sub_dissectors != NULL);
1694
1695         hdtbl_entry.dissector = dissector;
1696
1697         hdtbl_entry.protocol  = find_protocol_by_id(proto);
1698
1699         found_entry = g_slist_find_custom(*sub_dissectors, (gpointer) &hdtbl_entry, find_matching_heur_dissector);
1700
1701         if (found_entry) {
1702                 heur_dtbl_entry_t *hdtbl_entry_p;
1703                 hdtbl_entry_p = (heur_dtbl_entry_t *)found_entry->data;
1704                 hdtbl_entry_p->enabled = enabled;
1705         }
1706 }
1707
1708 gboolean
1709 dissector_try_heuristic(heur_dissector_list_t sub_dissectors, tvbuff_t *tvb,
1710                         packet_info *pinfo, proto_tree *tree, void *data)
1711 {
1712         gboolean           status;
1713         const char        *saved_proto;
1714         GSList            *entry;
1715         heur_dtbl_entry_t *hdtbl_entry;
1716         guint16            saved_can_desegment;
1717         gint               saved_layer_names_len = 0;
1718
1719         /* can_desegment is set to 2 by anyone which offers this api/service.
1720            then everytime a subdissector is called it is decremented by one.
1721            thus only the subdissector immediately ontop of whoever offers this
1722            service can use it.
1723            We save the current value of "can_desegment" for the
1724            benefit of TCP proxying dissectors such as SOCKS, so they
1725            can restore it and allow the dissectors they call to use
1726            the desegmentation service.
1727         */
1728         saved_can_desegment        = pinfo->can_desegment;
1729         pinfo->saved_can_desegment = saved_can_desegment;
1730         pinfo->can_desegment       = saved_can_desegment-(saved_can_desegment>0);
1731
1732         status      = FALSE;
1733         saved_proto = pinfo->current_proto;
1734
1735         if (pinfo->layer_names != NULL)
1736                 saved_layer_names_len = (gint) pinfo->layer_names->len;
1737
1738         for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1739                 /* XXX - why set this now and above? */
1740                 pinfo->can_desegment = saved_can_desegment-(saved_can_desegment>0);
1741                 hdtbl_entry = (heur_dtbl_entry_t *)entry->data;
1742
1743                 if (hdtbl_entry->protocol != NULL &&
1744                     (!proto_is_protocol_enabled(hdtbl_entry->protocol)||(hdtbl_entry->enabled==FALSE))) {
1745                         /*
1746                          * No - don't try this dissector.
1747                          */
1748                         continue;
1749                 }
1750
1751                 if (hdtbl_entry->protocol != NULL) {
1752                         pinfo->current_proto =
1753                                 proto_get_protocol_short_name(hdtbl_entry->protocol);
1754
1755                         /*
1756                          * Add the protocol name to the layers; we'll remove it
1757                          * if the dissector fails.
1758                          */
1759                         if (pinfo->layer_names) {
1760                                 if (pinfo->layer_names->len > 0)
1761                                         g_string_append(pinfo->layer_names, ":");
1762                                         g_string_append(pinfo->layer_names,
1763                                         proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol)));
1764                         }
1765                 }
1766                 EP_CHECK_CANARY(("before calling heuristic dissector for protocol: %s",
1767                                  proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol))));
1768                 if ((*hdtbl_entry->dissector)(tvb, pinfo, tree, data)) {
1769                         EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has accepted and dissected packet",
1770                                          proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol))));
1771                         status = TRUE;
1772                         break;
1773                 } else {
1774                         EP_CHECK_CANARY(("after heuristic dissector for protocol: %s has returned false",
1775                                          proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol))));
1776
1777                         /*
1778                          * That dissector didn't accept the packet, so
1779                          * remove its protocol's name from the list
1780                          * of protocols.
1781                          */
1782                         if (pinfo->layer_names != NULL) {
1783                                 g_string_truncate(pinfo->layer_names, saved_layer_names_len);
1784                         }
1785                 }
1786         }
1787         pinfo->current_proto = saved_proto;
1788         pinfo->can_desegment=saved_can_desegment;
1789         return status;
1790 }
1791
1792 /*
1793  * Called for each entry in the table of all heuristic dissector tables.
1794  */
1795 typedef struct heur_dissector_foreach_table_info {
1796         gpointer           caller_data;
1797         DATFunc_heur_table caller_func;
1798 } heur_dissector_foreach_table_info_t;
1799
1800
1801 static void
1802 dissector_dump_heur_decodes_display(const gchar *table_name, const gpointer value, const gpointer user_data _U_)
1803 {
1804         heur_dissector_list_t  sub_dissectors = *(heur_dissector_list_t *)value;
1805         GSList                *entry;
1806         heur_dtbl_entry_t     *hdtbl_entry;
1807
1808         for (entry = sub_dissectors; entry != NULL; entry = g_slist_next(entry)) {
1809                 hdtbl_entry = (heur_dtbl_entry_t *)entry->data;
1810                 if (hdtbl_entry->protocol != NULL) {
1811                         printf("%s\t%s\t%c\n",
1812                                table_name,
1813                                proto_get_protocol_filter_name(proto_get_id(hdtbl_entry->protocol)),
1814                                (proto_is_protocol_enabled(hdtbl_entry->protocol) && hdtbl_entry->enabled) ? 'T' : 'F');
1815                 }
1816         }
1817 }
1818
1819
1820 static void
1821 dissector_all_heur_tables_foreach_table_func (gpointer key, const gpointer value, const gpointer user_data)
1822 {
1823         heur_dissector_foreach_table_info_t *info;
1824
1825         info = user_data;
1826         (*info->caller_func)((gchar*)key, value, info->caller_data);
1827 }
1828
1829 /*
1830  * Walk all heuristic dissector tables calling a user supplied function on each
1831  * table.
1832  */
1833 void
1834 dissector_all_heur_tables_foreach_table (DATFunc_heur_table func,
1835                                          gpointer user_data)
1836 {
1837         heur_dissector_foreach_table_info_t info;
1838
1839         info.caller_data = user_data;
1840         info.caller_func = func;
1841         g_hash_table_foreach(heur_dissector_lists, dissector_all_heur_tables_foreach_table_func, &info);
1842 }
1843
1844 /*
1845  * For each heuristic dissector table, dump list of dissectors (filter_names) for that table
1846  */
1847 void
1848 dissector_dump_heur_decodes(void)
1849 {
1850         dissector_all_heur_tables_foreach_table(dissector_dump_heur_decodes_display, NULL);
1851 }
1852
1853
1854 void
1855 register_heur_dissector_list(const char *name, heur_dissector_list_t *sub_dissectors)
1856 {
1857         /* Create our hash-of-lists if it doesn't already exist */
1858         if (heur_dissector_lists == NULL) {
1859                 heur_dissector_lists = g_hash_table_new(g_str_hash, g_str_equal);
1860                 g_assert(heur_dissector_lists != NULL);
1861         }
1862
1863         /* Make sure the registration is unique */
1864         g_assert(g_hash_table_lookup(heur_dissector_lists, name) == NULL);
1865
1866         *sub_dissectors = NULL; /* initially empty */
1867         g_hash_table_insert(heur_dissector_lists, (gpointer)name,
1868                             (gpointer) sub_dissectors);
1869 }
1870
1871 /*
1872  * Register dissectors by name; used if one dissector always calls a
1873  * particular dissector, or if it bases the decision of which dissector
1874  * to call on something other than a numerical value or on "try a bunch
1875  * of dissectors until one likes the packet".
1876  */
1877
1878 /*
1879  * List of registered dissectors.
1880  */
1881 static GHashTable *registered_dissectors = NULL;
1882
1883 /* Get the long name of the protocol for a dissector handle, if it has
1884    a protocol. */
1885 const char *
1886 dissector_handle_get_long_name(const dissector_handle_t handle)
1887 {
1888         if (handle == NULL || handle->protocol == NULL) {
1889                 return NULL;
1890         }
1891         return proto_get_protocol_long_name(handle->protocol);
1892 }
1893
1894 /* Get the short name of the protocol for a dissector handle, if it has
1895    a protocol. */
1896 const char *
1897 dissector_handle_get_short_name(const dissector_handle_t handle)
1898 {
1899         if (handle->protocol == NULL) {
1900                 /*
1901                  * No protocol (see, for example, the handle for
1902                  * dissecting the set of protocols where the first
1903                  * octet of the payload is an OSI network layer protocol
1904                  * ID).
1905                  */
1906                 return NULL;
1907         }
1908         return proto_get_protocol_short_name(handle->protocol);
1909 }
1910
1911 /* Get the index of the protocol for a dissector handle, if it has
1912    a protocol. */
1913 int
1914 dissector_handle_get_protocol_index(const dissector_handle_t handle)
1915 {
1916         if (handle->protocol == NULL) {
1917                 /*
1918                  * No protocol (see, for example, the handle for
1919                  * dissecting the set of protocols where the first
1920                  * octet of the payload is an OSI network layer protocol
1921                  * ID).
1922                  */
1923                 return -1;
1924         }
1925         return proto_get_id(handle->protocol);
1926 }
1927
1928 /* Find a registered dissector by name. */
1929 dissector_handle_t
1930 find_dissector(const char *name)
1931 {
1932         g_assert(registered_dissectors != NULL);
1933         return g_hash_table_lookup(registered_dissectors, name);
1934 }
1935
1936 /* Create an anonymous handle for a dissector. */
1937 dissector_handle_t
1938 create_dissector_handle(dissector_t dissector, const int proto)
1939 {
1940         struct dissector_handle *handle;
1941
1942         handle                = g_malloc(sizeof (struct dissector_handle));
1943         handle->name          = NULL;
1944         handle->is_new        = FALSE;
1945         handle->dissector.old = dissector;
1946         handle->protocol      = find_protocol_by_id(proto);
1947
1948         return handle;
1949 }
1950
1951 dissector_handle_t
1952 new_create_dissector_handle(new_dissector_t dissector, const int proto)
1953 {
1954         struct dissector_handle *handle;
1955
1956         handle                = g_malloc(sizeof (struct dissector_handle));
1957         handle->name          = NULL;
1958         handle->is_new        = TRUE;
1959         handle->dissector.new = dissector;
1960         handle->protocol      = find_protocol_by_id(proto);
1961
1962         return handle;
1963 }
1964
1965 /* Register a dissector by name. */
1966 void
1967 register_dissector(const char *name, dissector_t dissector, const int proto)
1968 {
1969         struct dissector_handle *handle;
1970
1971         /* Create our hash table if it doesn't already exist */
1972         if (registered_dissectors == NULL) {
1973                 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1974                 g_assert(registered_dissectors != NULL);
1975         }
1976
1977         /* Make sure the registration is unique */
1978         g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
1979
1980         handle                = g_malloc(sizeof (struct dissector_handle));
1981         handle->name          = name;
1982         handle->is_new        = FALSE;
1983         handle->dissector.old = dissector;
1984         handle->protocol      = find_protocol_by_id(proto);
1985
1986         g_hash_table_insert(registered_dissectors, (gpointer)name,
1987                             (gpointer) handle);
1988 }
1989
1990 void
1991 new_register_dissector(const char *name, new_dissector_t dissector, const int proto)
1992 {
1993         struct dissector_handle *handle;
1994
1995         /* Create our hash table if it doesn't already exist */
1996         if (registered_dissectors == NULL) {
1997                 registered_dissectors = g_hash_table_new(g_str_hash, g_str_equal);
1998                 g_assert(registered_dissectors != NULL);
1999         }
2000
2001         /* Make sure the registration is unique */
2002         g_assert(g_hash_table_lookup(registered_dissectors, name) == NULL);
2003
2004         handle                = g_malloc(sizeof (struct dissector_handle));
2005         handle->name          = name;
2006         handle->is_new        = TRUE;
2007         handle->dissector.new = dissector;
2008         handle->protocol      = find_protocol_by_id(proto);
2009
2010         g_hash_table_insert(registered_dissectors, (gpointer)name,
2011                             (gpointer) handle);
2012 }
2013
2014 /* Call a dissector through a handle but if the dissector rejected it
2015  * return 0.
2016  */
2017 int
2018 call_dissector_only(dissector_handle_t handle, tvbuff_t *tvb,
2019                     packet_info *pinfo, proto_tree *tree, void *data)
2020 {
2021         int ret;
2022
2023         g_assert(handle != NULL);
2024         ret = call_dissector_work(handle, tvb, pinfo, tree, TRUE, data);
2025         return ret;
2026 }
2027
2028 /* Call a dissector through a handle and if this fails call the "data"
2029  * dissector.
2030  */
2031 int
2032 call_dissector_with_data(dissector_handle_t handle, tvbuff_t *tvb,
2033                          packet_info *pinfo, proto_tree *tree, void *data)
2034 {
2035         int ret;
2036
2037         ret = call_dissector_only(handle, tvb, pinfo, tree, data);
2038         if (ret == 0) {
2039                 /*
2040                  * The protocol was disabled, or the dissector rejected
2041                  * it.  Just dissect this packet as data.
2042                  */
2043                 g_assert(data_handle != NULL);
2044                 g_assert(data_handle->protocol != NULL);
2045                 call_dissector_work(data_handle, tvb, pinfo, tree, TRUE, NULL);
2046                 return tvb_length(tvb);
2047         }
2048         return ret;
2049 }
2050
2051 int
2052 call_dissector(dissector_handle_t handle, tvbuff_t *tvb,
2053                packet_info *pinfo, proto_tree *tree)
2054 {
2055         return call_dissector_with_data(handle, tvb, pinfo, tree, NULL);
2056 }
2057
2058 /*
2059  * Dumps the "layer type"/"decode as" associations to stdout, similar
2060  * to the proto_registrar_dump_*() routines.
2061  *
2062  * There is one record per line. The fields are tab-delimited.
2063  *
2064  * Field 1 = layer type, e.g. "tcp.port"
2065  * Field 2 = selector in decimal
2066  * Field 3 = "decode as" name, e.g. "http"
2067  */
2068
2069
2070 static void
2071 dissector_dump_decodes_display(const gchar *table_name,
2072                                ftenum_t selector_type _U_, const gpointer key, const gpointer value,
2073                                gpointer user_data _U_)
2074 {
2075         guint32             selector       = (guint32)(unsigned long) key;
2076         dissector_table_t   sub_dissectors = find_dissector_table(table_name);
2077         dtbl_entry_t       *dtbl_entry;
2078         dissector_handle_t  handle;
2079         gint                proto_id;
2080         const gchar        *decode_as;
2081
2082         g_assert(sub_dissectors);
2083         switch (sub_dissectors->type) {
2084
2085                 case FT_UINT8:
2086                 case FT_UINT16:
2087                 case FT_UINT24:
2088                 case FT_UINT32:
2089                         dtbl_entry = value;
2090                         g_assert(dtbl_entry);
2091
2092                         handle   = dtbl_entry->current;
2093                         g_assert(handle);
2094
2095                         proto_id = dissector_handle_get_protocol_index(handle);
2096
2097                         if (proto_id != -1) {
2098                                 decode_as = proto_get_protocol_filter_name(proto_id);
2099                                 g_assert(decode_as != NULL);
2100                                 printf("%s\t%u\t%s\n", table_name, selector, decode_as);
2101                         }
2102                         break;
2103
2104         default:
2105                 break;
2106         }
2107 }
2108
2109 void
2110 dissector_dump_decodes(void)
2111 {
2112         dissector_all_tables_foreach(dissector_dump_decodes_display, NULL);
2113 }
2114
2115 static GPtrArray* post_dissectors = NULL;
2116 static guint num_of_postdissectors = 0;
2117
2118 void
2119 register_postdissector(dissector_handle_t handle)
2120 {
2121         if (!post_dissectors)
2122                 post_dissectors = g_ptr_array_new();
2123
2124         g_ptr_array_add(post_dissectors, handle);
2125         num_of_postdissectors++;
2126 }
2127
2128 gboolean
2129 have_postdissector(void)
2130 {
2131         guint i;
2132         dissector_handle_t handle;
2133
2134         for(i = 0; i < num_of_postdissectors; i++) {
2135                 handle = (dissector_handle_t) g_ptr_array_index(post_dissectors,i);
2136
2137                 if (handle->protocol != NULL
2138                     && proto_is_protocol_enabled(handle->protocol)) {
2139                         /* We have at least one enabled postdissector */
2140                         return TRUE;
2141                 }
2142         }
2143         return FALSE;
2144 }
2145
2146 void
2147 call_all_postdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2148 {
2149         guint i;
2150
2151         for(i = 0; i < num_of_postdissectors; i++) {
2152                 call_dissector_only((dissector_handle_t) g_ptr_array_index(post_dissectors,i),
2153                                     tvb,pinfo,tree, NULL);
2154         }
2155 }
2156
2157 /*
2158  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
2159  *
2160  * Local variables:
2161  * c-basic-offset: 8
2162  * tab-width: 8
2163  * indent-tabs-mode: t
2164  * End:
2165  *
2166  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
2167  * :indentSize=8:tabSize=8:noTabs=false:
2168  */