aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/network/packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'Source/charon/network/packet.c')
-rw-r--r--Source/charon/network/packet.c117
1 files changed, 97 insertions, 20 deletions
diff --git a/Source/charon/network/packet.c b/Source/charon/network/packet.c
index 6d245365b..b6501d8ae 100644
--- a/Source/charon/network/packet.c
+++ b/Source/charon/network/packet.c
@@ -37,45 +37,116 @@ struct private_packet_t {
* Public part of a packet_t object.
*/
packet_t public;
+
+ /**
+ * source address
+ */
+ host_t *source;
+
+ /**
+ * destination address
+ */
+ host_t *destination;
+
+ /**
+ * message data
+ */
+ chunk_t data;
};
/**
+ * Implements packet_t.get_source
+ */
+static void set_source(private_packet_t *this, host_t *source)
+{
+ if (this->source)
+ {
+ this->source->destroy(this->source);
+ }
+ this->source = source;
+}
+
+/**
+ * Implements packet_t.set_destination
+ */
+static void set_destination(private_packet_t *this, host_t *destination)
+{
+ if (this->destination)
+ {
+ this->destination->destroy(this->destination);
+ }
+ this->destination = destination;
+}
+
+/**
+ * Implements packet_t.get_source
+ */
+static host_t *get_source(private_packet_t *this)
+{
+ return this->source;
+}
+
+/**
+ * Implements packet_t.get_destination
+ */
+static host_t *get_destination(private_packet_t *this)
+{
+ return this->destination;
+}
+
+/**
+ * Implements packet_t.get_data
+ */
+static chunk_t get_data(private_packet_t *this)
+{
+ return this->data;
+}
+
+/**
+ * Implements packet_t.set_data
+ */
+static void set_data(private_packet_t *this, chunk_t data)
+{
+ allocator_free(this->data.ptr);
+ this->data = data;
+}
+
+/**
* Implements packet_t.destroy.
*/
static void destroy(private_packet_t *this)
{
- if (this->public.source != NULL)
+ if (this->source != NULL)
{
- this->public.source->destroy(this->public.source);
+ this->source->destroy(this->source);
}
- if (this->public.destination != NULL)
+ if (this->destination != NULL)
{
- this->public.destination->destroy(this->public.destination);
+ this->destination->destroy(this->destination);
}
- allocator_free(this->public.data.ptr);
+ allocator_free(this->data.ptr);
allocator_free(this);
}
/**
* Implements packet_t.clone.
*/
-static packet_t *clone (private_packet_t *this)
+static packet_t *clone(private_packet_t *this)
{
- packet_t *other;
- other = packet_create();
+ private_packet_t *other = (private_packet_t*)packet_create();
- if (this->public.destination != NULL)
+ if (this->destination != NULL)
{
- other->destination = this->public.destination->clone(this->public.destination);
+ other->destination = this->destination->clone(this->destination);
}
else
{
other->destination = NULL;
}
- if (this->public.source != NULL)
+ if (this->source != NULL)
{
- other->source = this->public.source->clone(this->public.source);
+ other->source = this->source->clone(this->source);
}
else
{
@@ -83,16 +154,16 @@ static packet_t *clone (private_packet_t *this)
}
/* only clone existing chunks :-) */
- if (this->public.data.ptr != NULL)
+ if (this->data.ptr != NULL)
{
- other->data.ptr = allocator_clone_bytes(this->public.data.ptr,this->public.data.len);
- other->data.len = this->public.data.len;
+ other->data.ptr = allocator_clone_bytes(this->data.ptr,this->data.len);
+ other->data.len = this->data.len;
}
else
{
other->data = CHUNK_INITIALIZER;
}
- return other;
+ return &(other->public);
}
@@ -103,12 +174,18 @@ packet_t *packet_create()
{
private_packet_t *this = allocator_alloc_thing(private_packet_t);
- this->public.destroy = (void(*) (packet_t *)) destroy;
+ this->public.set_data = (void(*) (packet_t *,chunk_t)) set_data;
+ this->public.get_data = (chunk_t(*) (packet_t *)) get_data;
+ this->public.set_source = (void(*) (packet_t *,host_t*)) set_source;
+ this->public.get_source = (host_t*(*) (packet_t *)) get_source;
+ this->public.set_destination = (void(*) (packet_t *,host_t*)) set_destination;
+ this->public.get_destination = (host_t*(*) (packet_t *)) get_destination;
this->public.clone = (packet_t*(*) (packet_t *))clone;
+ this->public.destroy = (void(*) (packet_t *)) destroy;
- this->public.destination = NULL;
- this->public.source = NULL;
- this->public.data = CHUNK_INITIALIZER;
+ this->destination = NULL;
+ this->source = NULL;
+ this->data = CHUNK_INITIALIZER;
return &(this->public);
}