aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-07-18 12:53:54 +0000
committerMartin Willi <martin@strongswan.org>2006-07-18 12:53:54 +0000
commit92ee45a0eedfa4b58d5814d7ffad0671165f3f06 (patch)
tree7fa6af54ec8d0ef1e3be03917e0e94061499d845 /src/libstrongswan
parent623d3dcf78c0d96e44dbf2867b02acf10e51a812 (diff)
downloadstrongswan-92ee45a0eedfa4b58d5814d7ffad0671165f3f06.tar.bz2
strongswan-92ee45a0eedfa4b58d5814d7ffad0671165f3f06.tar.xz
cleanups in kernel interface code
added proper traffic selector to string conversion some cleanups here & there
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/utils/host.c44
-rw-r--r--src/libstrongswan/utils/host.h46
-rw-r--r--src/libstrongswan/utils/leak_detective.c1
3 files changed, 34 insertions, 57 deletions
diff --git a/src/libstrongswan/utils/host.c b/src/libstrongswan/utils/host.c
index 1f928f5aa..763358e5c 100644
--- a/src/libstrongswan/utils/host.c
+++ b/src/libstrongswan/utils/host.c
@@ -100,9 +100,9 @@ static bool is_anyaddr(private_host_t *this)
}
/**
- * implements host_t.get_address
+ * implements host_t.get_string
*/
-static char *get_address(private_host_t *this)
+static char *get_string(private_host_t *this)
{
switch (this->family)
{
@@ -128,9 +128,9 @@ static char *get_address(private_host_t *this)
}
/**
- * Implementation of host_t.get_address_as_chunk.
+ * Implementation of host_t.get_address.
*/
-static chunk_t get_address_as_chunk(private_host_t *this)
+static chunk_t get_address(private_host_t *this)
{
chunk_t address = CHUNK_INITIALIZER;
@@ -139,9 +139,8 @@ static chunk_t get_address_as_chunk(private_host_t *this)
case AF_INET:
{
/* allocate 4 bytes for IPv4 address*/
- address.ptr = malloc(4);
+ address.ptr = (char*)&(this->address4.sin_addr.s_addr);
address.len = 4;
- memcpy(address.ptr,&(this->address4.sin_addr.s_addr),4);
}
default:
{
@@ -151,22 +150,9 @@ static chunk_t get_address_as_chunk(private_host_t *this)
}
}
-static xfrm_address_t get_xfrm_addr(private_host_t *this)
-{
- switch (this->family)
- {
- case AF_INET:
- {
- return (xfrm_address_t)(this->address4.sin_addr.s_addr);
- }
- default:
- {
- /* todo */
- return (xfrm_address_t)(this->address4.sin_addr.s_addr);
- }
- }
-}
-
+/**
+ * implements host_t.get_family
+ */
static int get_family(private_host_t *this)
{
return this->family;
@@ -203,12 +189,11 @@ static void set_port(private_host_t *this, u_int16_t port)
}
default:
{
- /**/
+ /*TODO*/
}
}
}
-
/**
* Implements host_t.clone.
*/
@@ -249,9 +234,9 @@ static bool ip_equals(private_host_t *this, private_host_t *other)
/**
* Implements host_t.get_differences
*/
-static int get_differences(private_host_t *this, private_host_t *other)
+static host_diff_t get_differences(private_host_t *this, private_host_t *other)
{
- int ret = HOST_DIFF_NONE;
+ host_diff_t ret = HOST_DIFF_NONE;
if (!this->public.ip_equals(&this->public, &other->public))
{
@@ -307,12 +292,11 @@ static private_host_t *host_create_empty(void)
this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len;
this->public.clone = (host_t* (*) (host_t*))clone;
this->public.get_family = (int (*) (host_t*))get_family;
- this->public.get_xfrm_addr = (xfrm_address_t (*) (host_t *))get_xfrm_addr;
- this->public.get_address = (char* (*) (host_t *))get_address;
- this->public.get_address_as_chunk = (chunk_t (*) (host_t *)) get_address_as_chunk;
+ this->public.get_string = (char* (*) (host_t *))get_string;
+ this->public.get_address = (chunk_t (*) (host_t *)) get_address;
this->public.get_port = (u_int16_t (*) (host_t *))get_port;
this->public.set_port = (void (*) (host_t *,u_int16_t))set_port;
- this->public.get_differences = (int (*) (host_t *,host_t *)) get_differences;
+ this->public.get_differences = (host_diff_t (*) (host_t *,host_t *)) get_differences;
this->public.ip_equals = (bool (*) (host_t *,host_t *)) ip_equals;
this->public.equals = (bool (*) (host_t *,host_t *)) equals;
this->public.is_anyaddr = (bool (*) (host_t *)) is_anyaddr;
diff --git a/src/libstrongswan/utils/host.h b/src/libstrongswan/utils/host.h
index 6a72f52e4..54f3b55bb 100644
--- a/src/libstrongswan/utils/host.h
+++ b/src/libstrongswan/utils/host.h
@@ -35,10 +35,17 @@
#include <types.h>
+typedef enum host_diff_t host_diff_t;
-#define HOST_DIFF_NONE 0
-#define HOST_DIFF_ADDR 1
-#define HOST_DIFF_PORT 2
+/**
+ * Differences between two hosts. They differ in
+ * address, port, or both.
+ */
+enum host_diff_t {
+ HOST_DIFF_NONE = 0,
+ HOST_DIFF_ADDR = 1,
+ HOST_DIFF_PORT = 2,
+};
typedef struct host_t host_t;
@@ -80,7 +87,7 @@ struct host_t {
/**
* @brief Get the length of the sockaddr struct.
*
- * Sepending on the family, the length of the sockaddr struct
+ * Depending on the family, the length of the sockaddr struct
* is different. Use this function to get the length of the sockaddr
* struct returned by get_sock_addr.
*
@@ -92,20 +99,6 @@ struct host_t {
socklen_t *(*get_sockaddr_len) (host_t *this);
/**
- * @brief Gets the address as xfrm_address_t.
- *
- * This function allows the conversion to an
- * xfrm_address_t, used for netlink communication
- * with the kernel.
- *
- * @see kernel_interface_t.
- *
- * @param this calling object
- * @return address in xfrm_address_t format
- */
- xfrm_address_t (*get_xfrm_addr) (host_t *this);
-
- /**
* @brief Gets the family of the address
*
* @param this calling object
@@ -114,15 +107,15 @@ struct host_t {
int (*get_family) (host_t *this);
/**
- * @brief get the address of this host
+ * @brief Get the address of this host as a string
*
- * Mostly used for debugging purposes.
- * @warning string must NOT be freed
+ * Mostly used for debugging purposes. String
+ * points to internal data.
*
* @param this object
* @return address string,
*/
- char* (*get_address) (host_t *this);
+ char* (*get_string) (host_t *this);
/**
* @brief Checks if the ip address of host is set to default route.
@@ -137,12 +130,12 @@ struct host_t {
/**
* @brief get the address of this host as chunk_t
*
- * @warning returned chunk has to get destroyed by caller.
+ * Returned chunk points to internal data.
*
* @param this object
* @return address string,
*/
- chunk_t (*get_address_as_chunk) (host_t *this);
+ chunk_t (*get_address) (host_t *this);
/**
* @brief get the port of this host
@@ -183,10 +176,9 @@ struct host_t {
*
* @param this object to compare
* @param other the other to compare
- * @return a combination of HOST_DIFF_NONE,
- * HOST_DIFF_ADDR and HOST_DIFF_PORT
+ * @return differences in a combination of host_diff_t's
*/
- int (*get_differences) (host_t *this, host_t *other);
+ host_diff_t (*get_differences) (host_t *this, host_t *other);
/**
* @brief Destroy this host object
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c
index 3a5f48f3f..fbcd7d933 100644
--- a/src/libstrongswan/utils/leak_detective.c
+++ b/src/libstrongswan/utils/leak_detective.c
@@ -174,6 +174,7 @@ whitelist_t whitelist[] = {
{inet_ntoa, 0xFF},
{strerror, 0xFF},
{getprotobynumber, 0xFF},
+ {getservbyport, 0xFF},
};
/**