*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * 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
# include "config.h"
#endif
-#include <stdio.h>
-
-#include <string.h>
#include <glib.h>
#include "packet.h"
#include "circuit.h"
+#include "emem.h"
/*
* Hash table for circuits.
*/
static GHashTable *circuit_hashtable = NULL;
-static GMemChunk *circuit_key_chunk = NULL;
-static GMemChunk *circuit_chunk = NULL;
-
static guint32 new_index;
-static int circuit_init_count = 200;
-
/*
* Protocol-specific data attached to a circuit_t structure - protocol
* index and opaque pointer.
void *proto_data;
} circuit_proto_data;
-static GMemChunk *circuit_proto_data_area = NULL;
-
/*
* Compute the hash value for a circuit.
*/
}
/*
- * Initialize some variables every time a file is loaded or re-loaded.
- * Destroy all existing circuits, and create a new hash table
- * for the circuits in the new file.
+ * Destroy all existing circuits.
*/
void
-circuit_init(void)
+circuit_cleanup(void)
{
- if (circuit_hashtable != NULL)
- g_hash_table_destroy(circuit_hashtable);
- if (circuit_key_chunk != NULL)
- g_mem_chunk_destroy(circuit_key_chunk);
- if (circuit_chunk != NULL)
- g_mem_chunk_destroy(circuit_chunk);
-
/*
- * Free up any space allocated for circuit protocol data
- * areas.
+ * Free up any space allocated for the circuit hashtable.
*
- * We can free the space, as the structures it contains are
- * pointed to by circuit data structures that were freed
- * above.
+ * We can free the hash as the structures pointed to in the
+ * hash are in "seasonal" memory which is freed separately.
+ * Note: circuit_cleanup() must be called only when
+ * seasonal memory is also freed.
*/
- if (circuit_proto_data_area != NULL)
- g_mem_chunk_destroy(circuit_proto_data_area);
- circuit_hashtable = g_hash_table_new(circuit_hash, circuit_match);
- circuit_key_chunk = g_mem_chunk_new("circuit_key_chunk",
- sizeof(circuit_key),
- circuit_init_count * sizeof(struct circuit_key),
- G_ALLOC_AND_FREE);
- circuit_chunk = g_mem_chunk_new("circuit_chunk",
- sizeof(circuit_t),
- circuit_init_count * sizeof(circuit_t),
- G_ALLOC_AND_FREE);
+ if (circuit_hashtable != NULL)
+ g_hash_table_destroy(circuit_hashtable);
- /*
- * Allocate a new area for circuit protocol data items.
- */
- circuit_proto_data_area = g_mem_chunk_new("circuit_proto_data_area",
- sizeof(circuit_proto_data), 20 * sizeof(circuit_proto_data), /* FIXME*/
- G_ALLOC_ONLY);
+ circuit_hashtable = NULL;
+}
+
+/*
+ * Initialize some variables every time a file is loaded or re-loaded.
+ * Create a new hash table for the circuits in the new file.
+ */
+void
+circuit_init(void)
+{
+ circuit_hashtable = g_hash_table_new(circuit_hash, circuit_match);
/*
* Start the circuit indices over at 0.
circuit_t *circuit, *old_circuit;
circuit_key *new_key;
- new_key = g_mem_chunk_alloc(circuit_key_chunk);
+ new_key = se_alloc(sizeof(struct circuit_key));
new_key->ctype = ctype;
new_key->circuit_id = circuit_id;
- circuit = g_mem_chunk_alloc(circuit_chunk);
+ circuit = se_alloc(sizeof(circuit_t));
circuit->next = NULL;
circuit->first_frame = first_frame;
circuit->last_frame = 0; /* not known yet */
for (circuit = g_hash_table_lookup(circuit_hashtable, &key);
circuit != NULL; circuit = circuit->next) {
/*
- * The frame includes that frame number if:
+ * The circuit includes that frame number if:
*
* the circuit's first frame is unknown or is at or
* before that frame
void
circuit_add_proto_data(circuit_t *conv, int proto, void *proto_data)
{
- circuit_proto_data *p1 = g_mem_chunk_alloc(circuit_proto_data_area);
+ circuit_proto_data *p1 = se_alloc(sizeof(circuit_proto_data));
p1->proto = proto;
p1->proto_data = proto_data;
*/
gboolean
try_circuit_dissector(circuit_type ctype, guint32 circuit_id, guint32 frame,
- tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+ tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
circuit_t *circuit;