first merge of NATT code

This commit is contained in:
Martin Willi
2006-06-22 06:36:28 +00:00
parent 6bf1352032
commit 1396815afb
46 changed files with 2973 additions and 772 deletions
+58 -1
View File
@@ -6,6 +6,7 @@
*/
/*
* Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -136,7 +137,7 @@ static chunk_t get_address_as_chunk(private_host_t *this)
{
case AF_INET:
{
/* allocate 4 bytes for IPV4 address*/
/* allocate 4 bytes for IPv4 address*/
address.ptr = malloc(4);
address.len = 4;
memcpy(address.ptr,&(this->address4.sin_addr.s_addr),4);
@@ -188,6 +189,24 @@ static u_int16_t get_port(private_host_t *this)
}
}
/**
* implements host_t.set_port
*/
static void set_port(private_host_t *this, u_int16_t port)
{
switch (this->family)
{
case AF_INET:
{
this->address4.sin_port = htons(port);
}
default:
{
/**/
}
}
}
/**
* Implements host_t.clone.
@@ -226,6 +245,26 @@ static bool ip_equals(private_host_t *this, private_host_t *other)
return FALSE;
}
/**
* Implements host_t.get_differences
*/
static int get_differences(private_host_t *this, private_host_t *other)
{
int ret = HOST_DIFF_NONE;
if (!this->public.ip_equals(&this->public, &other->public))
{
ret |= HOST_DIFF_ADDR;
}
if (this->public.get_port(&this->public) != other->public.get_port(&other->public))
{
ret |= HOST_DIFF_PORT;
}
return ret;
}
/**
* Impelements host_t.equals
*/
@@ -271,6 +310,8 @@ static private_host_t *host_create_empty(void)
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_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.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;
@@ -311,6 +352,22 @@ host_t *host_create(int family, char *address, u_int16_t port)
}
/*
* Described in header.
*/
host_t *host_create_from_hdr(u_long address, u_short port)
{
private_host_t *this = host_create_empty();
this->family = AF_INET;
this->address4.sin_family = AF_INET;
this->address4.sin_addr.s_addr = address;
this->address4.sin_port = port;
this->socklen = sizeof(struct sockaddr_in);
return &(this->public);
}
/*
* Described in header.
*/
+37 -2
View File
@@ -6,6 +6,7 @@
*/
/*
* Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
* Copyright (C) 2005 Jan Hutter, Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -34,6 +35,10 @@
#include <types.h>
#define HOST_DIFF_NONE 0
#define HOST_DIFF_ADDR 1
#define HOST_DIFF_PORT 2
typedef struct host_t host_t;
/**
@@ -141,12 +146,18 @@ struct host_t {
/**
* @brief get the port of this host
*
* Mostly used for debugging purposes.
*
* @param this object to clone
* @return port number
*/
u_int16_t (*get_port) (host_t *this);
/**
* @brief set the port of this host
*
* @param this object to clone
* @param port port numer
*/
void (*set_port) (host_t *this, u_int16_t port);
/**
* @brief Compare the ips of two hosts hosts.
@@ -165,6 +176,16 @@ struct host_t {
* @return TRUE if addresses and ports are equal.
*/
bool (*equals) (host_t *this, host_t *other);
/**
* @brief Compare two hosts and return the differences.
*
* @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
*/
int (*get_differences) (host_t *this, host_t *other);
/**
* @brief Destroy this host object
@@ -191,6 +212,20 @@ struct host_t {
*/
host_t *host_create(int family, char *address, u_int16_t port);
/**
* @brief Constructor to create a host_t object from raw header data
*
* only IPv4 (create host_create_from_hdr6 for IPv6)!
*
* @param address address in network byte order
* @param port port number in network byte order
* @return
* - host_t object
*
* @ingroup network
*/
host_t *host_create_from_hdr(u_long address, u_short port);
/**
* @brief Constructor to create a host_t object from an address chunk
*
+2 -2
View File
@@ -59,7 +59,7 @@ struct iterator_t {
* @param this calling object
* @param[out] value item
* @return
* - TRUE, if more elements are avaiable,
* - TRUE, if there was an element available,
* - FALSE otherwise
*/
bool (*iterate) (iterator_t *this, void** value);
@@ -72,7 +72,7 @@ struct iterator_t {
*
* @param this calling object
* @return
* - TRUE, if more elements are avaiable,
* - TRUE, if more elements are available,
* - FALSE otherwise
*/
bool (*has_next) (iterator_t *this);