4 * @brief Interface of host_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
36 typedef struct host_t host_t
;
39 * @brief Representates a Host
41 * Host object, identifies a host and defines some useful functions on it.
47 * @brief Build a clone of this host object.
49 * @param this object to clone
52 host_t
*(*clone
) (host_t
*this);
55 * @brief Get a pointer to the internal sockaddr struct.
57 * This is used for sending and receiving via sockets.
59 * @param this object to clone
60 * @return pointer to the internal sockaddr structure
62 sockaddr_t
*(*get_sockaddr
) (host_t
*this);
65 * @brief Get the length of the sockaddr struct.
67 * Sepending on the family, the length of the sockaddr struct
68 * is different. Use this function to get the length of the sockaddr
69 * struct returned by get_sock_addr.
71 * This is used for sending and receiving via sockets.
73 * @param this object to clone
74 * @return length of the sockaddr struct
76 socklen_t
*(*get_sockaddr_len
) (host_t
*this);
79 * @brief get the address of this host
81 * Mostly used for debugging purposes.
82 * @warning string must NOT be freed
85 * @return address string,
87 char* (*get_address
) (host_t
*this);
90 * @brief Checks if the ip address of host is set to default route.
92 * @param this calling object
94 * - TRUE if host has IP 0.0.0.0 for default route
97 bool (*is_default_route
) (host_t
*this);
100 * @brief get the address of this host as chunk_t
102 * @warning returned chunk has to get destroyed by caller.
105 * @return address string,
107 chunk_t (*get_address_as_chunk
) (host_t
*this);
110 * @brief get the port of this host
112 * Mostly used for debugging purposes.
114 * @param this object to clone
115 * @return port number
117 u_int16_t (*get_port
) (host_t
*this);
120 * @brief Compare the ips of two hosts hosts.
122 * @param this object to compare
123 * @param other the other to compare
124 * @return TRUE if addresses are equal.
126 bool (*ip_is_equal
) (host_t
*this, host_t
*other
);
129 * @brief Destroy this host object
131 * @param this calling
132 * @return SUCCESS in any case
134 void (*destroy
) (host_t
*this);
138 * @brief Constructor to create a host_t object
140 * Currently supports only IPv4!
142 * @param family Address family to use for this object, such as AF_INET or AF_INET6
143 * @param address string of an address, such as "152.96.193.130"
144 * @param port port number
146 * - the host_t object, or
147 * - NULL, when family not supported.
151 host_t
*host_create(int family
, char *address
, u_int16_t port
);
154 * @brief Constructor to create a host_t object
156 * Currently supports only IPv4!
158 * @param family Address family to use for this object, such as AF_INET or AF_INET6
159 * @param address address as 4 byte chunk_t in networ order
160 * @param port port number
162 * - the host_t object, or
163 * - NULL, when family not supported or chunk_t length not 4 bytes.
167 host_t
*host_create_from_chunk(int family
, chunk_t address
, u_int16_t port
);