From 5e644203ec2251e04a609683209d6433030dc75c Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 23 Nov 2005 16:17:28 +0000 Subject: [PATCH] - moved host_t from util to network --- Source/charon/config/configuration_manager.h | 2 +- Source/charon/network/Makefile.network | 8 +- Source/charon/network/host.c | 171 +++++++++++++++++++++++++++ Source/charon/network/host.h | 120 +++++++++++++++++++ Source/charon/network/packet.h | 2 +- Source/charon/utils/Makefile.utils | 4 - Source/charon/utils/host.c | 171 --------------------------- Source/charon/utils/host.h | 120 ------------------- 8 files changed, 299 insertions(+), 299 deletions(-) create mode 100644 Source/charon/network/host.c create mode 100644 Source/charon/network/host.h delete mode 100644 Source/charon/utils/host.c delete mode 100644 Source/charon/utils/host.h diff --git a/Source/charon/config/configuration_manager.h b/Source/charon/config/configuration_manager.h index b192c0c..a3bc099 100644 --- a/Source/charon/config/configuration_manager.h +++ b/Source/charon/config/configuration_manager.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/Source/charon/network/Makefile.network b/Source/charon/network/Makefile.network index 3d600ac..0344683 100644 --- a/Source/charon/network/Makefile.network +++ b/Source/charon/network/Makefile.network @@ -18,7 +18,11 @@ NETWORK_DIR= $(MAIN_DIR)network/ OBJS+= $(BUILD_DIR)packet.o $(BUILD_DIR)packet.o : $(NETWORK_DIR)packet.c $(NETWORK_DIR)packet.h $(CC) $(CFLAGS) -c -o $@ $< - + OBJS+= $(BUILD_DIR)socket.o $(BUILD_DIR)socket.o : $(NETWORK_DIR)socket.c $(NETWORK_DIR)socket.h - $(CC) $(CFLAGS) -c -o $@ $< \ No newline at end of file + $(CC) $(CFLAGS) -c -o $@ $< + +OBJS+= $(BUILD_DIR)host.o +$(BUILD_DIR)host.o : $(NETWORK_DIR)host.c $(NETWORK_DIR)host.h + $(CC) $(CFLAGS) -c -o $@ $< \ No newline at end of file diff --git a/Source/charon/network/host.c b/Source/charon/network/host.c new file mode 100644 index 0000000..c2b01d1 --- /dev/null +++ b/Source/charon/network/host.c @@ -0,0 +1,171 @@ +/** + * @file host.c + * + * @brief host object, identifies a host and defines some useful functions on it. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "host.h" + +#include + +/** + * @brief The logger object. + */ +typedef struct private_host_s private_host_t; +struct private_host_s { + /** + * Public data + */ + host_t public; + + /** + * Address family to use, such as AF_INET or AF_INET6 + */ + int family; + + /** + * low-lewel structure, wich stores the address + */ + sockaddr_t address; + + /** + * length of address structure + */ + socklen_t socklen; +}; + + +/** + * implements host_t.get_sockaddr + */ +static sockaddr_t *get_sockaddr(private_host_t *this) +{ + return &(this->address); +} + +/** + * implements host_t.get_sockaddr_len + */ +static socklen_t *get_sockaddr_len(private_host_t *this) +{ + return &(this->socklen); +} + +/** + * implements host_t.get_address + */ +static char *get_address(private_host_t *this) +{ + switch (this->family) + { + case AF_INET: + { + struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address); + return inet_ntoa(sin->sin_addr); + } + default: + { + return "(family not supported)"; + } + } +} + +/** + * implements host_t.get_port + */ +static u_int16_t get_port(private_host_t *this) +{ + switch (this->family) + { + case AF_INET: + { + struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address); + return ntohs(sin->sin_port); + } + default: + { + return 0; + } + } +} + +/** + * Implements host_t.destroy + */ +static status_t destroy(private_host_t *this) +{ + allocator_free(this); + return SUCCESS; +} + +/** + * Implements host_t.clone. + */ +static status_t clone(private_host_t *this, host_t **other) +{ + private_host_t *new = allocator_alloc_thing(private_host_t); + + if (new == NULL) + { + return OUT_OF_RES; + } + + memcpy(new, this, sizeof(private_host_t)); + *other = (host_t*)new; + + return SUCCESS; +} + + +/* + * see header + */ +host_t *host_create(int family, char *address, u_int16_t port) +{ + private_host_t *this = allocator_alloc_thing(private_host_t); + if (this == NULL) + { + return NULL; + } + + this->public.get_sockaddr = (sockaddr_t* (*) (host_t*))get_sockaddr; + this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len; + this->public.clone = (status_t (*) (host_t*, host_t**))clone; + this->public.get_address = (char* (*) (host_t *))get_address; + this->public.get_port = (u_int16_t (*) (host_t *))get_port; + this->public.destroy = (status_t (*) (host_t*))destroy; + + this->family = family; + + switch (family) + { + /* IPv4 */ + case AF_INET: + { + struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address); + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = inet_addr(address); + sin->sin_port = htons(port); + this->socklen = sizeof(struct sockaddr_in); + return (host_t*)this; + } + } + allocator_free(this); + return NULL; +} diff --git a/Source/charon/network/host.h b/Source/charon/network/host.h new file mode 100644 index 0000000..f592e67 --- /dev/null +++ b/Source/charon/network/host.h @@ -0,0 +1,120 @@ +/** + * @file host.h + * + * @brief host object, identifies a host and defines some useful functions on it. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef HOST_H_ +#define HOST_H_ + +#include +#include +#include +#include +#include +#include + +#include + +/** + * @brief The logger object + */ +typedef struct host_s host_t; +struct host_s { + /** + * @brief Build a clone of this host object. + * + * @param this object to clone + * @param [out]other address where to allocate the clone + * @return + * - SUCCESS, or + * - OUT_OF_RES + */ + + status_t (*clone) (host_t *this, host_t **other); + /** + * @brief Get a pointer to the internal sockaddr struct. + * + * This is used for sending and receiving via sockets. + * + * @param this object to clone + * @return pointer to the internal sockaddr structure + */ + sockaddr_t *(*get_sockaddr) (host_t *this); + + /** + * @brief Get the length of the sockaddr struct. + * + * Sepending 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. + * + * This is used for sending and receiving via sockets. + * + * @param this object to clone + * @return length of the sockaddr struct + */ + socklen_t *(*get_sockaddr_len) (host_t *this); + + /** + * @brief get the address of this host + * + * Mostly used for debugging purposes. + * @warging string must NOT be freed + * + * @param this object to clone + * @return address string, + */ + char* (*get_address) (host_t *this); + + /** + * @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 Destroy this host object + * + * @param this calling + * @return SUCCESS in any case + */ + status_t (*destroy) (host_t *this); +}; + +/** + * @brief Constructor to create a host_t object + * + * 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 + * not enough ressources, or + * family not supported. + */ +host_t *host_create(int family, char *address, u_int16_t port); + + +#endif /*HOST_H_*/ diff --git a/Source/charon/network/packet.h b/Source/charon/network/packet.h index 10488e0..b91756a 100644 --- a/Source/charon/network/packet.h +++ b/Source/charon/network/packet.h @@ -25,7 +25,7 @@ #include -#include +#include diff --git a/Source/charon/utils/Makefile.utils b/Source/charon/utils/Makefile.utils index 20ea9f7..e66a060 100644 --- a/Source/charon/utils/Makefile.utils +++ b/Source/charon/utils/Makefile.utils @@ -23,10 +23,6 @@ OBJS+= $(BUILD_DIR)gmp_helper.o $(BUILD_DIR)gmp_helper.o : $(UTILS_DIR)gmp_helper.c $(UTILS_DIR)gmp_helper.h $(CC) $(CFLAGS) -c -o $@ $< -OBJS+= $(BUILD_DIR)host.o -$(BUILD_DIR)host.o : $(UTILS_DIR)host.c $(UTILS_DIR)host.h - $(CC) $(CFLAGS) -c -o $@ $< - OBJS+= $(BUILD_DIR)linked_list.o $(BUILD_DIR)linked_list.o : $(UTILS_DIR)linked_list.c $(UTILS_DIR)linked_list.h $(CC) $(CFLAGS) -c -o $@ $< diff --git a/Source/charon/utils/host.c b/Source/charon/utils/host.c deleted file mode 100644 index c2b01d1..0000000 --- a/Source/charon/utils/host.c +++ /dev/null @@ -1,171 +0,0 @@ -/** - * @file host.c - * - * @brief host object, identifies a host and defines some useful functions on it. - * - */ - -/* - * Copyright (C) 2005 Jan Hutter, Martin Willi - * Hochschule fuer Technik Rapperswil - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#include "host.h" - -#include - -/** - * @brief The logger object. - */ -typedef struct private_host_s private_host_t; -struct private_host_s { - /** - * Public data - */ - host_t public; - - /** - * Address family to use, such as AF_INET or AF_INET6 - */ - int family; - - /** - * low-lewel structure, wich stores the address - */ - sockaddr_t address; - - /** - * length of address structure - */ - socklen_t socklen; -}; - - -/** - * implements host_t.get_sockaddr - */ -static sockaddr_t *get_sockaddr(private_host_t *this) -{ - return &(this->address); -} - -/** - * implements host_t.get_sockaddr_len - */ -static socklen_t *get_sockaddr_len(private_host_t *this) -{ - return &(this->socklen); -} - -/** - * implements host_t.get_address - */ -static char *get_address(private_host_t *this) -{ - switch (this->family) - { - case AF_INET: - { - struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address); - return inet_ntoa(sin->sin_addr); - } - default: - { - return "(family not supported)"; - } - } -} - -/** - * implements host_t.get_port - */ -static u_int16_t get_port(private_host_t *this) -{ - switch (this->family) - { - case AF_INET: - { - struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address); - return ntohs(sin->sin_port); - } - default: - { - return 0; - } - } -} - -/** - * Implements host_t.destroy - */ -static status_t destroy(private_host_t *this) -{ - allocator_free(this); - return SUCCESS; -} - -/** - * Implements host_t.clone. - */ -static status_t clone(private_host_t *this, host_t **other) -{ - private_host_t *new = allocator_alloc_thing(private_host_t); - - if (new == NULL) - { - return OUT_OF_RES; - } - - memcpy(new, this, sizeof(private_host_t)); - *other = (host_t*)new; - - return SUCCESS; -} - - -/* - * see header - */ -host_t *host_create(int family, char *address, u_int16_t port) -{ - private_host_t *this = allocator_alloc_thing(private_host_t); - if (this == NULL) - { - return NULL; - } - - this->public.get_sockaddr = (sockaddr_t* (*) (host_t*))get_sockaddr; - this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len; - this->public.clone = (status_t (*) (host_t*, host_t**))clone; - this->public.get_address = (char* (*) (host_t *))get_address; - this->public.get_port = (u_int16_t (*) (host_t *))get_port; - this->public.destroy = (status_t (*) (host_t*))destroy; - - this->family = family; - - switch (family) - { - /* IPv4 */ - case AF_INET: - { - struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address); - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = inet_addr(address); - sin->sin_port = htons(port); - this->socklen = sizeof(struct sockaddr_in); - return (host_t*)this; - } - } - allocator_free(this); - return NULL; -} diff --git a/Source/charon/utils/host.h b/Source/charon/utils/host.h deleted file mode 100644 index f592e67..0000000 --- a/Source/charon/utils/host.h +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @file host.h - * - * @brief host object, identifies a host and defines some useful functions on it. - * - */ - -/* - * Copyright (C) 2005 Jan Hutter, Martin Willi - * Hochschule fuer Technik Rapperswil - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#ifndef HOST_H_ -#define HOST_H_ - -#include -#include -#include -#include -#include -#include - -#include - -/** - * @brief The logger object - */ -typedef struct host_s host_t; -struct host_s { - /** - * @brief Build a clone of this host object. - * - * @param this object to clone - * @param [out]other address where to allocate the clone - * @return - * - SUCCESS, or - * - OUT_OF_RES - */ - - status_t (*clone) (host_t *this, host_t **other); - /** - * @brief Get a pointer to the internal sockaddr struct. - * - * This is used for sending and receiving via sockets. - * - * @param this object to clone - * @return pointer to the internal sockaddr structure - */ - sockaddr_t *(*get_sockaddr) (host_t *this); - - /** - * @brief Get the length of the sockaddr struct. - * - * Sepending 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. - * - * This is used for sending and receiving via sockets. - * - * @param this object to clone - * @return length of the sockaddr struct - */ - socklen_t *(*get_sockaddr_len) (host_t *this); - - /** - * @brief get the address of this host - * - * Mostly used for debugging purposes. - * @warging string must NOT be freed - * - * @param this object to clone - * @return address string, - */ - char* (*get_address) (host_t *this); - - /** - * @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 Destroy this host object - * - * @param this calling - * @return SUCCESS in any case - */ - status_t (*destroy) (host_t *this); -}; - -/** - * @brief Constructor to create a host_t object - * - * 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 - * not enough ressources, or - * family not supported. - */ -host_t *host_create(int family, char *address, u_int16_t port); - - -#endif /*HOST_H_*/ -- 2.7.4