removed unneded includes
[strongswan.git] / src / libstrongswan / utils / host.h
1 /**
2 * @file host.h
3 *
4 * @brief Interface of host_t.
5 *
6 */
7
8 /*
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
14 *
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>.
19 *
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
23 * for more details.
24 */
25
26 #ifndef HOST_H_
27 #define HOST_H_
28
29 typedef enum host_diff_t host_diff_t;
30 typedef struct host_t host_t;
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38
39 #include <library.h>
40
41 /**
42 * Differences between two hosts. They differ in
43 * address, port, or both.
44 */
45 enum host_diff_t {
46 HOST_DIFF_NONE = 0,
47 HOST_DIFF_ADDR = 1,
48 HOST_DIFF_PORT = 2,
49 };
50
51 /**
52 * @brief Representates a Host
53 *
54 * Host object, identifies a address:port pair and defines some
55 * useful functions on it.
56 *
57 * @b Constructors:
58 * - host_create()
59 * - host_create_from_chunk()
60 * - host_create_from_sockaddr()
61 *
62 * @todo Add IPv6 support
63 *
64 * @ingroup utils
65 */
66 struct host_t {
67
68 /**
69 * @brief Build a clone of this host object.
70 *
71 * @param this object to clone
72 * @return cloned host
73 */
74 host_t *(*clone) (host_t *this);
75
76 /**
77 * @brief Get a pointer to the internal sockaddr struct.
78 *
79 * This is used for sending and receiving via sockets.
80 *
81 * @param this object to clone
82 * @return pointer to the internal sockaddr structure
83 */
84 sockaddr_t *(*get_sockaddr) (host_t *this);
85
86 /**
87 * @brief Get the length of the sockaddr struct.
88 *
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.
92 *
93 * This is used for sending and receiving via sockets.
94 *
95 * @param this object to clone
96 * @return length of the sockaddr struct
97 */
98 socklen_t *(*get_sockaddr_len) (host_t *this);
99
100 /**
101 * @brief Gets the family of the address
102 *
103 * @param this calling object
104 * @return family
105 */
106 int (*get_family) (host_t *this);
107
108 /**
109 * @brief Checks if the ip address of host is set to default route.
110 *
111 * @param this calling object
112 * @return
113 * - TRUE if host has IP 0.0.0.0 for default route
114 * - FALSE otherwise
115 */
116 bool (*is_anyaddr) (host_t *this);
117
118 /**
119 * @brief get the address of this host as chunk_t
120 *
121 * Returned chunk points to internal data.
122 *
123 * @param this object
124 * @return address string,
125 */
126 chunk_t (*get_address) (host_t *this);
127
128 /**
129 * @brief get the port of this host
130 *
131 * @param this object to clone
132 * @return port number
133 */
134 u_int16_t (*get_port) (host_t *this);
135
136 /**
137 * @brief set the port of this host
138 *
139 * @param this object to clone
140 * @param port port numer
141 */
142 void (*set_port) (host_t *this, u_int16_t port);
143
144 /**
145 * @brief Compare the ips of two hosts hosts.
146 *
147 * @param this object to compare
148 * @param other the other to compare
149 * @return TRUE if addresses are equal.
150 */
151 bool (*ip_equals) (host_t *this, host_t *other);
152
153 /**
154 * @brief Compare two hosts, with port.
155 *
156 * @param this object to compare
157 * @param other the other to compare
158 * @return TRUE if addresses and ports are equal.
159 */
160 bool (*equals) (host_t *this, host_t *other);
161
162 /**
163 * @brief Compare two hosts and return the differences.
164 *
165 * @param this object to compare
166 * @param other the other to compare
167 * @return differences in a combination of host_diff_t's
168 */
169 host_diff_t (*get_differences) (host_t *this, host_t *other);
170
171 /**
172 * @brief Destroy this host object
173 *
174 * @param this calling
175 * @return SUCCESS in any case
176 */
177 void (*destroy) (host_t *this);
178 };
179
180 /**
181 * @brief Constructor to create a host_t object from an address string.
182 *
183 * @param string string of an address, such as "152.96.193.130"
184 * @param port port number
185 * @return
186 * - host_t object
187 * - NULL, if string not an address.
188 *
189 * @ingroup network
190 */
191 host_t *host_create_from_string(char *string, u_int16_t port);
192
193 /**
194 * @brief Constructor to create a host_t object from an address chunk
195 *
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
199 * @return
200 * - host_t object
201 * - NULL, if family not supported or chunk_t length not 4 bytes.
202 *
203 * @ingroup network
204 */
205 host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port);
206
207 /**
208 * @brief Constructor to create a host_t object from a sockaddr struct
209 *
210 * @param sockaddr sockaddr struct which contains family, address and port
211 * @return
212 * - host_t object
213 * - NULL, if family not supported.
214 *
215 * @ingroup network
216 */
217 host_t *host_create_from_sockaddr(sockaddr_t *sockaddr);
218
219 /**
220 * @brief Create a host without an address, a "any" host.
221 *
222 * @param family family of the any host
223 * @return
224 * - host_t object
225 * - NULL, if family not supported.
226 *
227 * @ingroup network
228 */
229 host_t *host_create_any(int family);
230
231 #endif /*HOST_H_*/