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>
38 #include <linux/xfrm.h>
43 * Differences between two hosts. They differ in
44 * address, port, or both.
53 * @brief Representates a Host
55 * Host object, identifies a address:port pair and defines some
56 * useful functions on it.
60 * - host_create_from_chunk()
61 * - host_create_from_sockaddr()
63 * @todo Add IPv6 support
70 * @brief Build a clone of this host object.
72 * @param this object to clone
75 host_t
*(*clone
) (host_t
*this);
78 * @brief Get a pointer to the internal sockaddr struct.
80 * This is used for sending and receiving via sockets.
82 * @param this object to clone
83 * @return pointer to the internal sockaddr structure
85 sockaddr_t
*(*get_sockaddr
) (host_t
*this);
88 * @brief Get the length of the sockaddr struct.
90 * Depending on the family, the length of the sockaddr struct
91 * is different. Use this function to get the length of the sockaddr
92 * struct returned by get_sock_addr.
94 * This is used for sending and receiving via sockets.
96 * @param this object to clone
97 * @return length of the sockaddr struct
99 socklen_t
*(*get_sockaddr_len
) (host_t
*this);
102 * @brief Gets the family of the address
104 * @param this calling object
107 int (*get_family
) (host_t
*this);
110 * @brief Checks if the ip address of host is set to default route.
112 * @param this calling object
114 * - TRUE if host has IP 0.0.0.0 for default route
117 bool (*is_anyaddr
) (host_t
*this);
120 * @brief get the address of this host as chunk_t
122 * Returned chunk points to internal data.
125 * @return address string,
127 chunk_t (*get_address
) (host_t
*this);
130 * @brief get the port of this host
132 * @param this object to clone
133 * @return port number
135 u_int16_t (*get_port
) (host_t
*this);
138 * @brief set the port of this host
140 * @param this object to clone
141 * @param port port numer
143 void (*set_port
) (host_t
*this, u_int16_t port
);
146 * @brief Compare the ips of two hosts hosts.
148 * @param this object to compare
149 * @param other the other to compare
150 * @return TRUE if addresses are equal.
152 bool (*ip_equals
) (host_t
*this, host_t
*other
);
155 * @brief Compare two hosts, with port.
157 * @param this object to compare
158 * @param other the other to compare
159 * @return TRUE if addresses and ports are equal.
161 bool (*equals
) (host_t
*this, host_t
*other
);
164 * @brief Compare two hosts and return the differences.
166 * @param this object to compare
167 * @param other the other to compare
168 * @return differences in a combination of host_diff_t's
170 host_diff_t (*get_differences
) (host_t
*this, host_t
*other
);
173 * @brief Destroy this host object
175 * @param this calling
176 * @return SUCCESS in any case
178 void (*destroy
) (host_t
*this);
182 * @brief Constructor to create a host_t object from an address string.
184 * @param string string of an address, such as "152.96.193.130"
185 * @param port port number
188 * - NULL, if string not an address.
192 host_t
*host_create_from_string(char *string
, u_int16_t port
);
195 * @brief Constructor to create a host_t object from an address chunk
197 * @param family Address family to use for this object, such as AF_INET or AF_INET6
198 * @param address address as 4 byte chunk_t in networ order
199 * @param port port number
202 * - NULL, if family not supported or chunk_t length not 4 bytes.
206 host_t
*host_create_from_chunk(int family
, chunk_t address
, u_int16_t port
);
209 * @brief Constructor to create a host_t object from a sockaddr struct
211 * @param sockaddr sockaddr struct which contains family, address and port
214 * - NULL, if family not supported.
218 host_t
*host_create_from_sockaddr(sockaddr_t
*sockaddr
);
221 * @brief Create a host without an address, a "any" host.
223 * @param family family of the any host
226 * - NULL, if family not supported.
230 host_t
*host_create_any(int family
);