4 * @brief Interface of host_t.
9 * Copyright (C) 2006-2007 Tobias Brunner
10 * Copyright (C) 2006 Daniel Roethlisberger
11 * Copyright (C) 2005-2006 Martin Willi
12 * Copyright (C) 2005 Jan Hutter
13 * Hochschule fuer Technik Rapperswil
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 typedef enum host_diff_t host_diff_t
;
30 typedef struct host_t host_t
;
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
42 * Differences between two hosts. They differ in
43 * address, port, or both.
52 * @brief Representates a Host
54 * Host object, identifies a address:port pair and defines some
55 * useful functions on it.
59 * - host_create_from_chunk()
60 * - host_create_from_sockaddr()
62 * @todo Add IPv6 support
69 * @brief Build a clone of this host object.
71 * @param this object to clone
74 host_t
*(*clone
) (host_t
*this);
77 * @brief Get a pointer to the internal sockaddr struct.
79 * This is used for sending and receiving via sockets.
81 * @param this object to clone
82 * @return pointer to the internal sockaddr structure
84 sockaddr_t
*(*get_sockaddr
) (host_t
*this);
87 * @brief Get the length of the sockaddr struct.
89 * Depending on the family, the length of the sockaddr struct
90 * is different. Use this function to get the length of the sockaddr
91 * struct returned by get_sock_addr.
93 * This is used for sending and receiving via sockets.
95 * @param this object to clone
96 * @return length of the sockaddr struct
98 socklen_t
*(*get_sockaddr_len
) (host_t
*this);
101 * @brief Gets the family of the address
103 * @param this calling object
106 int (*get_family
) (host_t
*this);
109 * @brief Checks if the ip address of host is set to default route.
111 * @param this calling object
113 * - TRUE if host has IP 0.0.0.0 for default route
116 bool (*is_anyaddr
) (host_t
*this);
119 * @brief get the address of this host as chunk_t
121 * Returned chunk points to internal data.
124 * @return address string,
126 chunk_t (*get_address
) (host_t
*this);
129 * @brief get the port of this host
131 * @param this object to clone
132 * @return port number
134 u_int16_t (*get_port
) (host_t
*this);
137 * @brief set the port of this host
139 * @param this object to clone
140 * @param port port numer
142 void (*set_port
) (host_t
*this, u_int16_t port
);
145 * @brief Compare the ips of two hosts hosts.
147 * @param this object to compare
148 * @param other the other to compare
149 * @return TRUE if addresses are equal.
151 bool (*ip_equals
) (host_t
*this, host_t
*other
);
154 * @brief Compare two hosts, with port.
156 * @param this object to compare
157 * @param other the other to compare
158 * @return TRUE if addresses and ports are equal.
160 bool (*equals
) (host_t
*this, host_t
*other
);
163 * @brief Compare two hosts and return the differences.
165 * @param this object to compare
166 * @param other the other to compare
167 * @return differences in a combination of host_diff_t's
169 host_diff_t (*get_differences
) (host_t
*this, host_t
*other
);
172 * @brief Destroy this host object
174 * @param this calling
175 * @return SUCCESS in any case
177 void (*destroy
) (host_t
*this);
181 * @brief Constructor to create a host_t object from an address string.
183 * @param string string of an address, such as "152.96.193.130"
184 * @param port port number
187 * - NULL, if string not an address.
191 host_t
*host_create_from_string(char *string
, u_int16_t port
);
194 * @brief Constructor to create a host_t object from an address chunk
196 * @param family Address family to use for this object, such as AF_INET or AF_INET6
197 * @param address address as 4 byte chunk_t in networ order
198 * @param port port number
201 * - NULL, if family not supported or chunk_t length not 4 bytes.
205 host_t
*host_create_from_chunk(int family
, chunk_t address
, u_int16_t port
);
208 * @brief Constructor to create a host_t object from a sockaddr struct
210 * @param sockaddr sockaddr struct which contains family, address and port
213 * - NULL, if family not supported.
217 host_t
*host_create_from_sockaddr(sockaddr_t
*sockaddr
);
220 * @brief Create a host without an address, a "any" host.
222 * @param family family of the any host
225 * - NULL, if family not supported.
229 host_t
*host_create_any(int family
);