2 * Protocol-specific data
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/epan.h>
29 #include <wiretap/wtap.h>
31 #include <epan/wmem/wmem.h>
32 #include <epan/packet_info.h>
33 #include <epan/proto_data.h>
34 #include <epan/proto.h>
36 #include <epan/packet.h>
39 #include <epan/timestamp.h>
42 /* Protocol-specific data attached to a frame_data structure - protocol
43 index and opaque pointer. */
44 typedef struct _proto_data {
51 p_compare(gconstpointer a, gconstpointer b)
53 const proto_data_t *ap = (const proto_data_t *)a;
54 const proto_data_t *bp = (const proto_data_t *)b;
56 if (ap -> proto > bp -> proto) {
58 } else if (ap -> proto == bp -> proto) {
59 if (ap->key > bp->key){
61 } else if (ap -> key == bp -> key) {
71 p_add_proto_data(wmem_allocator_t *tmp_scope, struct _packet_info* pinfo, int proto, guint32 key, void *proto_data)
75 wmem_allocator_t *scope;
77 if (tmp_scope == pinfo->pool) {
79 proto_list = &pinfo->proto_data;
80 } else if (tmp_scope == wmem_file_scope()) {
81 scope = wmem_file_scope();
82 proto_list = &pinfo->fd->pfd;
84 DISSECTOR_ASSERT(!"invalid wmem scope");
87 p1 = (proto_data_t *)wmem_alloc(scope, sizeof(proto_data_t));
91 p1->proto_data = proto_data;
93 /* Add it to the GSLIST */
94 *proto_list = g_slist_prepend(*proto_list, p1);
98 p_get_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key)
100 proto_data_t temp, *p1;
105 temp.proto_data = NULL;
107 if (scope == pinfo->pool) {
108 item = g_slist_find_custom(pinfo->proto_data, &temp, p_compare);
109 } else if (scope == wmem_file_scope()) {
110 item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
112 DISSECTOR_ASSERT(!"invalid wmem scope");
116 p1 = (proto_data_t *)item->data;
117 return p1->proto_data;
124 p_remove_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key)
132 temp.proto_data = NULL;
134 if (scope == pinfo->pool) {
135 item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
136 proto_list = &pinfo->proto_data;
137 } else if (scope == wmem_file_scope()) {
138 item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
139 proto_list = &pinfo->fd->pfd;
141 DISSECTOR_ASSERT(!"invalid wmem scope");
145 *proto_list = g_slist_remove(*proto_list, item->data);
150 p_get_proto_name_and_key(wmem_allocator_t *scope, struct _packet_info* pinfo, guint pfd_index){
153 if (scope == pinfo->pool) {
154 temp = (proto_data_t *)g_slist_nth_data(pinfo->proto_data, pfd_index);
155 } else if (scope == wmem_file_scope()) {
156 temp = (proto_data_t *)g_slist_nth_data(pinfo->fd->pfd, pfd_index);
158 DISSECTOR_ASSERT(!"invalid wmem scope");
161 return wmem_strdup_printf(wmem_packet_scope(),"[%s, key %u]",proto_get_protocol_name(temp->proto), temp->key);
165 * Editor modelines - http://www.wireshark.org/tools/modelines.html
170 * indent-tabs-mode: nil
173 * vi: set shiftwidth=2 tabstop=8 expandtab:
174 * :indentSize=2:tabSize=8:noTabs=true: