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