diff options
Diffstat (limited to 'Source/charon/network/packet.c')
-rw-r--r-- | Source/charon/network/packet.c | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/Source/charon/network/packet.c b/Source/charon/network/packet.c index f2d7ef721..6d245365b 100644 --- a/Source/charon/network/packet.c +++ b/Source/charon/network/packet.c @@ -1,7 +1,7 @@ /** * @file packet.c * - * @brief UDP-Packet, contains data, sender and receiver. + * @brief Implementation of packet_t. * */ @@ -40,10 +40,9 @@ struct private_packet_t { }; /** - * Implements packet_t's destroy function. - * See #packet_s.destroy for description. + * Implements packet_t.destroy. */ -static status_t destroy(private_packet_t *this) +static void destroy(private_packet_t *this) { if (this->public.source != NULL) { @@ -53,32 +52,24 @@ static status_t destroy(private_packet_t *this) { this->public.destination->destroy(this->public.destination); } - if (this->public.data.ptr != NULL) - { - allocator_free(this->public.data.ptr); - } + allocator_free(this->public.data.ptr); allocator_free(this); - return SUCCESS; } /** - * Implements packet_t's clone function. - * See #packet_s.clone for description. + * Implements packet_t.clone. */ -static status_t clone (private_packet_t *this, packet_t **clone) +static packet_t *clone (private_packet_t *this) { packet_t *other; other = packet_create(); - if (other == NULL) - { - return OUT_OF_RES; - } - + if (this->public.destination != NULL) { other->destination = this->public.destination->clone(this->public.destination); } - else { + else + { other->destination = NULL; } @@ -86,7 +77,8 @@ static status_t clone (private_packet_t *this, packet_t **clone) { other->source = this->public.source->clone(this->public.source); } - else { + else + { other->source = NULL; } @@ -94,20 +86,13 @@ static status_t clone (private_packet_t *this, packet_t **clone) if (this->public.data.ptr != NULL) { other->data.ptr = allocator_clone_bytes(this->public.data.ptr,this->public.data.len); - if (other->data.ptr == NULL) - { - other->destroy(other); - return OUT_OF_RES; - } other->data.len = this->public.data.len; } else { - other->data.ptr = NULL; - other->data.len = 0; + other->data = CHUNK_INITIALIZER; } - *clone = other; - return SUCCESS; + return other; } @@ -118,13 +103,12 @@ packet_t *packet_create() { private_packet_t *this = allocator_alloc_thing(private_packet_t); - this->public.destroy = (status_t(*) (packet_t *)) destroy; - this->public.clone = (status_t(*) (packet_t *,packet_t**))clone; + this->public.destroy = (void(*) (packet_t *)) destroy; + this->public.clone = (packet_t*(*) (packet_t *))clone; this->public.destination = NULL; this->public.source = NULL; - - this->public.data.len = 0; - this->public.data.ptr = NULL; + this->public.data = CHUNK_INITIALIZER; + return &(this->public); } |