diff options
author | Guy Harris <guy@alum.mit.edu> | 1999-10-24 07:27:20 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 1999-10-24 07:27:20 +0000 |
commit | 1d72c68bc61aeffd53dfb73b4f89e510495e5653 (patch) | |
tree | f964a7c43be302b36e2f04cd329ba0d062b31e64 /conversation.c | |
parent | da1fdf005fd91fe48fca5857a64d1087dd67ff86 (diff) |
Export the data structure used to represent a conversation.
Replace "add_to_conversation()" with:
"conversation_new()", which creates a new conversation, given
source and destination addresses and ports, and returns a
pointer to the structure for the conversation;
"find_conversation()", which tries to find a conversation for
given source and destination addresses and ports, and returns a
pointer to the structure for the conversation if found, and a
null pointer if not found.
Add a private data pointer field to the conversation structure, and have
"conversation_new()" take an argument that specifies what to set that
pointer to; that lets clients of the conversation code hang arbitrary
data off the conversation (e.g., a hash table of protocol requests and
replies, in case the protocol is a request/reply protocol wherein the
reply doesn't say what type of request it's a reply to, and you need
that information to dissect the reply).
svn path=/trunk/; revision=920
Diffstat (limited to 'conversation.c')
-rw-r--r-- | conversation.c | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/conversation.c b/conversation.c index 0cef652d2e..3f60a2d906 100644 --- a/conversation.c +++ b/conversation.c @@ -1,7 +1,7 @@ /* conversation.c * Routines for building lists of packets that are part of a "conversation" * - * $Id: conversation.c,v 1.1 1999/10/22 07:17:28 guy Exp $ + * $Id: conversation.c,v 1.2 1999/10/24 07:27:17 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -40,10 +40,11 @@ #include <string.h> #include <glib.h> #include "packet.h" +#include "conversation.h" static GHashTable *conversation_hashtable = NULL; static GMemChunk *conversation_key_chunk = NULL; -static GMemChunk *conversation_val_chunk = NULL; +static GMemChunk *conversation_chunk = NULL; typedef struct conversation_key { struct conversation_key *next; @@ -60,11 +61,6 @@ typedef struct conversation_key { */ static conversation_key *conversation_keys; -typedef struct conversation_val { - struct conversation_val *next; - guint32 index; -} conversation_val; - static guint32 new_index; static int conversation_init_count = 200; @@ -207,8 +203,8 @@ conversation_init(void) g_hash_table_destroy(conversation_hashtable); if (conversation_key_chunk != NULL) g_mem_chunk_destroy(conversation_key_chunk); - if (conversation_val_chunk != NULL) - g_mem_chunk_destroy(conversation_val_chunk); + if (conversation_chunk != NULL) + g_mem_chunk_destroy(conversation_chunk); conversation_hashtable = g_hash_table_new(conversation_hash, conversation_equal); @@ -216,9 +212,9 @@ conversation_init(void) sizeof(conversation_key), conversation_init_count * sizeof(struct conversation_key), G_ALLOC_AND_FREE); - conversation_val_chunk = g_mem_chunk_new("conversation_val_chunk", - sizeof(conversation_val), - conversation_init_count * sizeof(struct conversation_val), + conversation_chunk = g_mem_chunk_new("conversation_chunk", + sizeof(conversation_t), + conversation_init_count * sizeof(conversation_t), G_ALLOC_AND_FREE); /* @@ -243,18 +239,45 @@ copy_address(address *to, address *from) } /* - * Given source and destination addresses and ports for a packet, add - * it to the conversation containing packets between those address/port - * pairs, creating a new conversation if none exists between them. - * - * Returns an index to use to refer to the conversation. + * Given source and destination addresses and ports for a packet, + * create a new conversation to contain packets between those address/port + * pairs. */ -guint32 -add_to_conversation(address *src, address *dst, port_type ptype, +conversation_t * +conversation_new(address *src, address *dst, port_type ptype, + guint16 src_port, guint16 dst_port, void *data) +{ + conversation_t *conversation; + conversation_key *new_key; + + new_key = g_mem_chunk_alloc(conversation_key_chunk); + new_key->next = conversation_keys; + conversation_keys = new_key; + copy_address(&new_key->src, src); + copy_address(&new_key->dst, dst); + new_key->ptype = ptype; + new_key->port_src = src_port; + new_key->port_dst = dst_port; + + conversation = g_mem_chunk_alloc(conversation_chunk); + conversation->index = new_index; + conversation->data = data; + new_index++; + + g_hash_table_insert(conversation_hashtable, new_key, conversation); + return conversation; +} + +/* + * Given source and destination addresses and ports for a packet, + * search for a conversation containing packets between those address/port + * pairs. Returns NULL if not found. + */ +conversation_t * +find_conversation(address *src, address *dst, port_type ptype, guint16 src_port, guint16 dst_port) { - conversation_val *conversation; - conversation_key key, *new_key; + conversation_key key; /* * We don't make a copy of the address data, we just copy the @@ -265,30 +288,5 @@ add_to_conversation(address *src, address *dst, port_type ptype, key.ptype = ptype; key.port_src = src_port; key.port_dst = dst_port; - conversation = - (conversation_val *)g_hash_table_lookup(conversation_hashtable, - &key); - if (conversation == NULL) { - /* - * No such conversation yet. - * Allocate a new one. - * Here, we *do* have to copy the address data. - */ - new_key = g_mem_chunk_alloc(conversation_key_chunk); - new_key->next = conversation_keys; - conversation_keys = new_key; - copy_address(&new_key->src, src); - copy_address(&new_key->dst, dst); - new_key->ptype = ptype; - new_key->port_src = src_port; - new_key->port_dst = dst_port; - - conversation = g_mem_chunk_alloc(conversation_val_chunk); - conversation->index = new_index; - new_index++; - - g_hash_table_insert(conversation_hashtable, new_key, - conversation); - } - return conversation->index; + return g_hash_table_lookup(conversation_hashtable, &key); } |