aboutsummaryrefslogtreecommitdiffstats
path: root/epan/capture_dissectors.c
blob: 738bacbc9019a256b58cc76af039e967deb302b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* capture_dissectors.c
 * Routines for handling capture dissectors
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <glib.h>
#include "packet.h"

#include "capture_dissectors.h"

struct capture_dissector_handle
{
    gint linktype;
    capture_dissector_t dissector;
    protocol_t* protocol;
};

static GHashTable *registered_capture_dissectors = NULL;

void capture_dissector_init(void)
{
    registered_capture_dissectors = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
}

void capture_dissector_cleanup(void)
{
    g_hash_table_destroy(registered_capture_dissectors);
    registered_capture_dissectors = NULL;
}

void register_capture_dissector(gint linktype, capture_dissector_t dissector, const int proto)
{
    struct capture_dissector_handle *handle;

    /* Make sure the registration is unique */
    g_assert(g_hash_table_lookup(registered_capture_dissectors, GUINT_TO_POINTER(linktype)) == NULL);

    handle                = wmem_new(wmem_epan_scope(), struct capture_dissector_handle);
    handle->linktype      = linktype;
    handle->dissector     = dissector;
    handle->protocol      = find_protocol_by_id(proto);

    g_hash_table_insert(registered_capture_dissectors, GUINT_TO_POINTER(linktype), (gpointer) handle);
}

void call_capture_dissector(gint linktype, const guchar *pd, int offset, int len, packet_counts *ld, const union wtap_pseudo_header *pseudo_header)
{
    struct capture_dissector_handle* handle = (struct capture_dissector_handle *)g_hash_table_lookup(registered_capture_dissectors, GUINT_TO_POINTER(linktype));
    if (handle == NULL)
        return;

    handle->dissector(pd, offset, len, ld, pseudo_header);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */