2 * Routines for packet disassembly
4 * $Id: frame_data.c,v 1.2 2002/08/02 21:29:39 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "frame_data.h"
35 /* Protocol-specific data attached to a frame_data structure - protocol
36 index and opaque pointer. */
37 typedef struct _frame_proto_data {
42 static GMemChunk *frame_proto_data_area = NULL;
45 * Free up any space allocated for frame proto data areas and then
46 * allocate a new area.
48 * We can free the area, as the structures it contains are pointed to by
49 * frames, that will be freed as well.
52 packet_init_protocol(void)
55 if (frame_proto_data_area)
56 g_mem_chunk_destroy(frame_proto_data_area);
58 frame_proto_data_area = g_mem_chunk_new("frame_proto_data_area",
59 sizeof(frame_proto_data),
60 20 * sizeof(frame_proto_data), /* FIXME*/
68 register_init_routine(&packet_init_protocol);
72 frame_data_cleanup(void)
74 /* this function intentionally left blank :) */
77 /* XXX - I declared this static, because it only seems to be used by
78 * p_get_proto_data and p_add_proto_data
80 static gint p_compare(gconstpointer a, gconstpointer b)
83 if (((frame_proto_data *)a) -> proto > ((frame_proto_data *)b) -> proto)
85 else if (((frame_proto_data *)a) -> proto == ((frame_proto_data *)b) -> proto)
94 p_add_proto_data(frame_data *fd, int proto, void *proto_data)
96 frame_proto_data *p1 = g_mem_chunk_alloc(frame_proto_data_area);
101 p1 -> proto_data = proto_data;
103 /* Add it to the GSLIST */
105 fd -> pfd = g_slist_insert_sorted(fd -> pfd,
112 p_get_proto_data(frame_data *fd, int proto)
114 frame_proto_data temp, *p1;
118 temp.proto_data = NULL;
120 item = g_slist_find_custom(fd->pfd, (gpointer *)&temp, p_compare);
123 p1 = (frame_proto_data *)item->data;
124 return p1->proto_data;
132 p_rem_proto_data(frame_data *fd, int proto)
134 frame_proto_data temp;
138 temp.proto_data = NULL;
140 item = g_slist_find_custom(fd->pfd, (gpointer *)&temp, p_compare);
144 fd->pfd = g_slist_remove(fd->pfd, item);