]> git.ipfire.org Git - people/ms/strongswan.git/blob - Source/lib/utils/host.h
- renamed get_block_size of hasher
[people/ms/strongswan.git] / Source / lib / utils / host.h
1 /**
2 * @file host.h
3 *
4 * @brief Interface of host_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #ifndef HOST_H_
24 #define HOST_H_
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <linux/xfrm.h>
33
34 #include <types.h>
35
36
37 typedef struct host_t host_t;
38
39 /**
40 * @brief Representates a Host
41 *
42 * Host object, identifies a address:port pair and defines some
43 * useful functions on it.
44 *
45 * @b Constructors:
46 * - host_create()
47 * - host_create_from_chunk()
48 * - host_create_from_sockaddr()
49 *
50 * @todo Add IPv6 support
51 *
52 * @ingroup network
53 */
54 struct host_t {
55
56 /**
57 * @brief Build a clone of this host object.
58 *
59 * @param this object to clone
60 * @return cloned host
61 */
62 host_t *(*clone) (host_t *this);
63
64 /**
65 * @brief Get a pointer to the internal sockaddr struct.
66 *
67 * This is used for sending and receiving via sockets.
68 *
69 * @param this object to clone
70 * @return pointer to the internal sockaddr structure
71 */
72 sockaddr_t *(*get_sockaddr) (host_t *this);
73
74 /**
75 * @brief Get the length of the sockaddr struct.
76 *
77 * Sepending on the family, the length of the sockaddr struct
78 * is different. Use this function to get the length of the sockaddr
79 * struct returned by get_sock_addr.
80 *
81 * This is used for sending and receiving via sockets.
82 *
83 * @param this object to clone
84 * @return length of the sockaddr struct
85 */
86 socklen_t *(*get_sockaddr_len) (host_t *this);
87
88 /**
89 * @brief Gets the address as xfrm_address_t.
90 *
91 * This function allows the conversion to an
92 * xfrm_address_t, used for netlink communication
93 * with the kernel.
94 *
95 * @see kernel_interface_t.
96 *
97 * @param this calling object
98 * @return address in xfrm_address_t format
99 */
100 xfrm_address_t (*get_xfrm_addr) (host_t *this);
101
102 /**
103 * @brief Gets the family of the address
104 *
105 * @param this calling object
106 * @return family
107 */
108 int (*get_family) (host_t *this);
109
110 /**
111 * @brief get the address of this host
112 *
113 * Mostly used for debugging purposes.
114 * @warning string must NOT be freed
115 *
116 * @param this object
117 * @return address string,
118 */
119 char* (*get_address) (host_t *this);
120
121 /**
122 * @brief Checks if the ip address of host is set to default route.
123 *
124 * @param this calling object
125 * @return
126 * - TRUE if host has IP 0.0.0.0 for default route
127 * - FALSE otherwise
128 */
129 bool (*is_default_route) (host_t *this);
130
131 /**
132 * @brief get the address of this host as chunk_t
133 *
134 * @warning returned chunk has to get destroyed by caller.
135 *
136 * @param this object
137 * @return address string,
138 */
139 chunk_t (*get_address_as_chunk) (host_t *this);
140
141 /**
142 * @brief get the port of this host
143 *
144 * Mostly used for debugging purposes.
145 *
146 * @param this object to clone
147 * @return port number
148 */
149 u_int16_t (*get_port) (host_t *this);
150
151 /**
152 * @brief Compare the ips of two hosts hosts.
153 *
154 * @param this object to compare
155 * @param other the other to compare
156 * @return TRUE if addresses are equal.
157 */
158 bool (*ip_equals) (host_t *this, host_t *other);
159
160 /**
161 * @brief Compare two hosts, with port.
162 *
163 * @param this object to compare
164 * @param other the other to compare
165 * @return TRUE if addresses and ports are equal.
166 */
167 bool (*equals) (host_t *this, host_t *other);
168
169 /**
170 * @brief Destroy this host object
171 *
172 * @param this calling
173 * @return SUCCESS in any case
174 */
175 void (*destroy) (host_t *this);
176 };
177
178 /**
179 * @brief Constructor to create a host_t object from an address string
180 *
181 * Currently supports only IPv4!
182 *
183 * @param family Address family to use for this object, such as AF_INET or AF_INET6
184 * @param address string of an address, such as "152.96.193.130"
185 * @param port port number
186 * @return
187 * - host_t object
188 * - NULL, if family not supported.
189 *
190 * @ingroup network
191 */
192 host_t *host_create(int family, char *address, u_int16_t port);
193
194 /**
195 * @brief Constructor to create a host_t object from an address chunk
196 *
197 * Currently supports only IPv4!
198 *
199 * @param family Address family to use for this object, such as AF_INET or AF_INET6
200 * @param address address as 4 byte chunk_t in networ order
201 * @param port port number
202 * @return
203 * - host_t object
204 * - NULL, if family not supported or chunk_t length not 4 bytes.
205 *
206 * @ingroup network
207 */
208 host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port);
209
210 /**
211 * @brief Constructor to create a host_t object from a sockaddr struct
212 *
213 * Currently supports only IPv4!
214 *
215 * @param sockaddr sockaddr struct which contains family, address and port
216 * @return
217 * - host_t object
218 * - NULL, if family not supported.
219 *
220 * @ingroup network
221 */
222 host_t *host_create_from_sockaddr(sockaddr_t *sockaddr);
223
224
225 #endif /*HOST_H_*/