aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/network
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-11-29 08:08:03 +0000
committerMartin Willi <martin@strongswan.org>2005-11-29 08:08:03 +0000
commitdf3c59d0889a337eff9f994e92a5dc165ba1729f (patch)
tree7973747444155ea669e3f2dc1177b9b2eb3fc8a1 /Source/charon/network
parented37dee61daf5bb272c04b79787da282abaa9447 (diff)
downloadstrongswan-df3c59d0889a337eff9f994e92a5dc165ba1729f.tar.bz2
strongswan-df3c59d0889a337eff9f994e92a5dc165ba1729f.tar.xz
- changed allocation behavior
Diffstat (limited to 'Source/charon/network')
-rw-r--r--Source/charon/network/host.h13
-rw-r--r--Source/charon/network/packet.c50
-rw-r--r--Source/charon/network/packet.h23
-rw-r--r--Source/charon/network/socket.c17
-rw-r--r--Source/charon/network/socket.h26
5 files changed, 58 insertions, 71 deletions
diff --git a/Source/charon/network/host.h b/Source/charon/network/host.h
index cf9064afd..a430d7134 100644
--- a/Source/charon/network/host.h
+++ b/Source/charon/network/host.h
@@ -34,10 +34,13 @@
typedef struct host_t host_t;
+
/**
* @brief Representates a Host
*
* Host object, identifies a host and defines some useful functions on it.
+ *
+ * @ingroup network
*/
struct host_t {
/**
@@ -105,15 +108,17 @@ struct host_t {
/**
* @brief Constructor to create a host_t object
*
- * currently supports only IPv4!
+ * Currently supports only IPv4!
*
* @param family Address family to use for this object, such as AF_INET or AF_INET6
* @param address string of an address, such as "152.96.193.130"
* @param port port number
- * @return the host_t object or NULL, when
- * family not supported.
+ * @return
+ * - the host_t object, or
+ * - NULL, when family not supported.
+ *
+ * @ingroup network
*/
host_t *host_create(int family, char *address, u_int16_t port);
-
#endif /*HOST_H_*/
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);
}
diff --git a/Source/charon/network/packet.h b/Source/charon/network/packet.h
index 2e41e8a6c..bc8d3f5b6 100644
--- a/Source/charon/network/packet.h
+++ b/Source/charon/network/packet.h
@@ -1,7 +1,7 @@
/**
* @file packet.h
*
- * @brief UDP-Packet, contains data, sender and receiver.
+ * @brief Interface of packet_t.
*
*/
@@ -30,7 +30,9 @@
typedef struct packet_t packet_t;
/**
- * @brief UDP-Packet, contains data, sender and receiver
+ * @brief Abstraction of an UDP-Packet, contains data, sender and receiver.
+ *
+ * @ingroup network
*/
struct packet_t {
@@ -50,28 +52,27 @@ struct packet_t {
chunk_t data;
/**
- * @brief Clones a packet_t object
+ * @brief Clones a packet_t object.
*
- * @param packet calling object
+ * @param packet calling object
* @param clone pointer to a packet_t object pointer where the new object is stored
- * @return - SUCCESS if successful
- * - OUT_OF_RES
*/
- status_t (*clone) (packet_t *packet, packet_t **clone);
+ packet_t* (*clone) (packet_t *packet);
/**
- * @brief destroy the packet, freeing contained data
+ * @brief Destroy the packet, freeing contained data.
*
* @param packet packet to destroy
- * @return - SUCCESS
*/
- status_t (*destroy) (packet_t *packet);
+ void (*destroy) (packet_t *packet);
};
/**
* @brief create an empty packet
*
- * @return - NULL when family not supported
+ * @return created packet_t object
+ *
+ * @ingroup network
*/
packet_t *packet_create();
diff --git a/Source/charon/network/socket.c b/Source/charon/network/socket.c
index f56d22ade..41a2224b8 100644
--- a/Source/charon/network/socket.c
+++ b/Source/charon/network/socket.c
@@ -1,9 +1,7 @@
/**
* @file socket.c
*
- * @brief management of sockets
- *
- * receiver reads from here, sender writes to here
+ * @brief Implementation of socket_t.
*
*/
@@ -52,6 +50,7 @@ struct private_socket_t{
* currently we only have one socket, maybe more in the future ?
*/
int socket_fd;
+
/**
* logger for this socket
*/
@@ -137,13 +136,11 @@ status_t sender(private_socket_t *this, packet_t *packet)
/**
* implementation of socket_t.destroy
*/
-status_t destroy(private_socket_t *this)
+void destroy(private_socket_t *this)
{
close(this->socket_fd);
global_logger_manager->destroy_logger(global_logger_manager, this->logger);
allocator_free(this);
-
- return SUCCESS;
}
socket_t *socket_create(u_int16_t port)
@@ -154,15 +151,9 @@ socket_t *socket_create(u_int16_t port)
/* public functions */
this->public.send = (status_t(*)(socket_t*, packet_t*))sender;
this->public.receive = (status_t(*)(socket_t*, packet_t**))receiver;
- this->public.destroy = (status_t(*)(socket_t*))destroy;
-
+ this->public.destroy = (void(*)(socket_t*))destroy;
this->logger = global_logger_manager->create_logger(global_logger_manager, SOCKET, NULL);
- if (this->logger == NULL)
- {
- allocator_free(this);
- return NULL;
- }
/* create default ipv4 socket */
this->socket_fd = socket(PF_INET, SOCK_DGRAM, 0);
diff --git a/Source/charon/network/socket.h b/Source/charon/network/socket.h
index 97f59ac02..752e5d62b 100644
--- a/Source/charon/network/socket.h
+++ b/Source/charon/network/socket.h
@@ -1,9 +1,7 @@
/**
* @file socket.h
*
- * @brief management of sockets
- *
- * receiver reads from here, sender writes to here
+ * @brief Interface for socket_t.
*
*/
@@ -31,8 +29,11 @@
/**
- * maximum size of a packet
+ * @brief Maximum size of a packet.
+ *
* 3000 Bytes should be sufficient, see IKEv2 draft
+ *
+ * @ingroup network
*/
#define MAX_PACKET 3000
@@ -40,12 +41,15 @@
typedef struct socket_t socket_t;
/**
- * @brief abstraction of one (ipv4), or in future, of multiple sockets
+ * @brief Abstraction of one (ipv4), or in future, of multiple sockets.
+ *
+ * Receiver reads from here, sender writes to here.
*
+ * @ingroup network
*/
struct socket_t {
/**
- * @brief receive a packet
+ * @brief Receive a packet.
*
* reads a packet from one of the sockets.
* source will be set, dest not implemented
@@ -59,7 +63,7 @@ struct socket_t {
status_t (*receive) (socket_t *sock, packet_t **packet);
/**
- * @brief send a packet
+ * @brief Send a packet.
*
* sends a packet via desired socket.
* uses source and dest in packet.
@@ -72,24 +76,26 @@ struct socket_t {
status_t (*send) (socket_t *sock, packet_t *packet);
/**
- * @brief destroy sockets
+ * @brief Destroy sockets.
*
* close sockets and destroy socket_t object
*
* @param sock socket_t to destroy
* @return SUCCESS
*/
- status_t (*destroy) (socket_t *sock);
+ void (*destroy) (socket_t *sock);
};
/**
- * @brief socket_t constructor
+ * @brief socket_t constructor.
*
* currently creates one socket, listening on all addresses
* on port.
*
* @param port port to bind socket to
* @return the created socket, or NULL on error
+ *
+ * @ingroup network
*/
socket_t *socket_create(u_int16_t port);