aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-16 16:07:55 +0000
committerMartin Willi <martin@strongswan.org>2005-11-16 16:07:55 +0000
commit90c50445db96b49c57b98fe079a2518c37deccb0 (patch)
tree19032cc594ca10960b8b9da710755577a232ee00
parent60a6167a064bf9037885d9237f2606c4dd9c4630 (diff)
downloadstrongswan-90c50445db96b49c57b98fe079a2518c37deccb0.tar.bz2
strongswan-90c50445db96b49c57b98fe079a2518c37deccb0.tar.xz
- packet uses host_t to store addresses now
-rw-r--r--Source/charon/packet.c123
-rw-r--r--Source/charon/packet.h45
2 files changed, 47 insertions, 121 deletions
diff --git a/Source/charon/packet.c b/Source/charon/packet.c
index 5587daa77..a3c5f6225 100644
--- a/Source/charon/packet.c
+++ b/Source/charon/packet.c
@@ -37,21 +37,6 @@ struct private_packet_s {
* Public part of a packet_t object
*/
packet_t public;
-
- /* private functions */
-
- /**
- * @brief helper function to set address used by set_dest & set_source.
- *
- * @param this calling object_t
- * @param family address family
- * @param saddr source address
- * @param address address as string
- * @return
- * - SUCCESS if successfuly
- * - NOT_SUPPORTED if family is not supported
- */
- status_t (*set_addr) (private_packet_t *this, int family, struct sockaddr *saddr, char *address, u_int16_t port);
};
/**
@@ -60,6 +45,14 @@ struct private_packet_s {
*/
static status_t destroy(private_packet_t *this)
{
+ if (this->public.source != NULL)
+ {
+ this->public.source->destroy(this->public.source);
+ }
+ if (this->public.destination != NULL)
+ {
+ this->public.destination->destroy(this->public.destination);
+ }
if (this->public.data.ptr != NULL)
{
allocator_free(this->public.data.ptr);
@@ -72,96 +65,64 @@ static status_t destroy(private_packet_t *this)
* Implements packet_t's clone function.
* See #packet_s.clone for description.
*/
-static status_t clone (private_packet_t *packet, packet_t **clone)
+static status_t clone (private_packet_t *this, packet_t **clone)
{
- *clone = packet_create(packet->public.family);
- if ((*clone) == NULL)
+ packet_t *other;
+ other = packet_create();
+ if (other == NULL)
{
-
return OUT_OF_RES;
}
-
- (*clone)->sockaddr_len = packet->public.sockaddr_len;
- (*clone)->source = packet->public.source;
- (*clone)->destination = packet->public.destination;
+ if (this->public.destination != NULL)
+ {
+ this->public.destination->clone(this->public.destination, &(other->destination));
+ }
+ else {
+ other->destination = NULL;
+ }
+
+ if (this->public.source != NULL)
+ {
+ this->public.source->clone(this->public.source, &(other->source));
+ }
+ else {
+ other->source = NULL;
+ }
+
/* only clone existing chunks :-) */
- if (packet->public.data.ptr != NULL)
+ if (this->public.data.ptr != NULL)
{
- (*clone)->data.ptr = allocator_clone_bytes(packet->public.data.ptr,packet->public.data.len);
- if ((*clone)->data.ptr == NULL)
+ other->data.ptr = allocator_clone_bytes(this->public.data.ptr,this->public.data.len);
+ if (other->data.ptr == NULL)
{
- (*clone)->destroy((*clone));
+ other->destroy(other);
return OUT_OF_RES;
}
- (*clone)->data.len = packet->public.data.len;
+ other->data.len = this->public.data.len;
}
- return SUCCESS;
-}
-
-/**
- * Implements private_packet_t's set_addr function.
- * See #private_packet_t.set_addr for description.
- */
-static status_t set_addr(int family, struct sockaddr *saddr, char *address, u_int16_t port)
-{
- switch (family)
+ else
{
- /* IPv4 */
- case AF_INET:
- {
- struct sockaddr_in *sin = (struct sockaddr_in*)saddr;
- sin->sin_family = AF_INET;
- sin->sin_addr.s_addr = inet_addr("127.0.0.1");
- sin->sin_port = htons(port);
- return SUCCESS;;
- }
+ other->data.ptr = NULL;
+ other->data.len = 0;
}
- return NOT_SUPPORTED;
-}
-
-/**
- * Implements packet_t's set_destination function.
- * See #packet_t.set_destination for description.
- */
-static status_t set_destination(packet_t *this, char *address, u_int16_t port)
-{
- struct sockaddr *saddr = &(this->destination);
- return set_addr(this->family, saddr, address, port);
+ *clone = other;
+ return SUCCESS;
}
-/**
- * Implements packet_t's set_source function.
- * See #packet_t.set_source for description.
- */
-static status_t set_source(packet_t *this, char *address, u_int16_t port)
-{
- struct sockaddr *saddr = &(this->source);
- return set_addr(this->family, saddr, address, port);
-}
/*
* Documented in header
*/
-packet_t *packet_create(int family)
+packet_t *packet_create()
{
private_packet_t *this = allocator_alloc_thing(private_packet_t);
this->public.destroy = (status_t(*) (packet_t *)) destroy;
- this->public.set_destination = set_destination;
- this->public.set_source = set_source;
this->public.clone = (status_t(*) (packet_t *,packet_t**))clone;
-
- this->public.family = family;
- switch (family)
- {
- case AF_INET:
- this->public.sockaddr_len = sizeof(struct sockaddr_in);
- break;
- default: /* not supported */
- allocator_free(this);
- return NULL;
- }
+
+ this->public.destination = NULL;
+ this->public.source = NULL;
this->public.data.len = 0;
this->public.data.ptr = NULL;
diff --git a/Source/charon/packet.h b/Source/charon/packet.h
index 1e0785c79..b586440b6 100644
--- a/Source/charon/packet.h
+++ b/Source/charon/packet.h
@@ -25,12 +25,8 @@
#include "types.h"
+#include "utils/host.h"
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdlib.h>
/**
@@ -38,25 +34,16 @@
*/
typedef struct packet_s packet_t;
struct packet_s {
- /**
- * Address family, such as AF_INET
- */
- int family;
-
- /**
- *
- */
- size_t sockaddr_len;
-
+
/**
* source address structure
*/
- struct sockaddr source;
+ host_t *source;
/**
* destination address structure
*/
- struct sockaddr destination;
+ host_t *destination;
/**
* message data
@@ -64,28 +51,6 @@ struct packet_s {
chunk_t data;
/**
- * @brief set destination of packet, using address string
- *
- * @param packet calling object
- * @param address ip address string
- * @param port port number
- * @return - SUCCESS
- * - NOT_SUPPORTED
- */
- status_t (*set_destination) (packet_t *packet, char *address, u_int16_t port);
-
- /**
- * @brief set destination of packet, using address string
- *
- * @param packet calling object
- * @param address ip address string
- * @param port port number
- * @return - SUCCESS
- * - NOT_SUPPORTED
- */
- status_t (*set_source) (packet_t *packet, char *address, u_int16_t port);
-
- /**
* @brief Clones a packet_t object
*
* @param packet calling object
@@ -110,6 +75,6 @@ struct packet_s {
* @param family address-family, such as AF_INET
* @return - NULL when family not supported
*/
-packet_t *packet_create(int family);
+packet_t *packet_create();
#endif /*PACKET_H_*/