- new configuration support added to ike_sa and states
[strongswan.git] / Source / charon / network / 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
33 #include <types.h>
34
35
36 typedef struct host_t host_t;
37
38 /**
39 * @brief Representates a Host
40 *
41 * Host object, identifies a host and defines some useful functions on it.
42 *
43 * @ingroup network
44 */
45 struct host_t {
46 /**
47 * @brief Build a clone of this host object.
48 *
49 * @param this object to clone
50 * @return cloned host
51 */
52 host_t *(*clone) (host_t *this);
53
54 /**
55 * @brief Get a pointer to the internal sockaddr struct.
56 *
57 * This is used for sending and receiving via sockets.
58 *
59 * @param this object to clone
60 * @return pointer to the internal sockaddr structure
61 */
62 sockaddr_t *(*get_sockaddr) (host_t *this);
63
64 /**
65 * @brief Get the length of the sockaddr struct.
66 *
67 * Sepending on the family, the length of the sockaddr struct
68 * is different. Use this function to get the length of the sockaddr
69 * struct returned by get_sock_addr.
70 *
71 * This is used for sending and receiving via sockets.
72 *
73 * @param this object to clone
74 * @return length of the sockaddr struct
75 */
76 socklen_t *(*get_sockaddr_len) (host_t *this);
77
78 /**
79 * @brief get the address of this host
80 *
81 * Mostly used for debugging purposes.
82 * @warning string must NOT be freed
83 *
84 * @param this object
85 * @return address string,
86 */
87 char* (*get_address) (host_t *this);
88
89 /**
90 * @brief Checks if the ip address of host is set to default route.
91 *
92 * @param this calling object
93 * @return
94 * - TRUE if host has IP 0.0.0.0 for default route
95 * - FALSE otherwise
96 */
97 bool (*is_default_route) (host_t *this);
98
99 /**
100 * @brief get the address of this host as chunk_t
101 *
102 * @warning returned chunk has to get destroyed by caller.
103 *
104 * @param this object
105 * @return address string,
106 */
107 chunk_t (*get_address_as_chunk) (host_t *this);
108
109 /**
110 * @brief get the port of this host
111 *
112 * Mostly used for debugging purposes.
113 *
114 * @param this object to clone
115 * @return port number
116 */
117 u_int16_t (*get_port) (host_t *this);
118
119 /**
120 * @brief Compare the ips of two hosts hosts.
121 *
122 * @param this object to compare
123 * @param other the other to compare
124 * @return TRUE if addresses are equal.
125 */
126 bool (*ip_is_equal) (host_t *this, host_t *other);
127
128 /**
129 * @brief Destroy this host object
130 *
131 * @param this calling
132 * @return SUCCESS in any case
133 */
134 void (*destroy) (host_t *this);
135 };
136
137 /**
138 * @brief Constructor to create a host_t object
139 *
140 * Currently supports only IPv4!
141 *
142 * @param family Address family to use for this object, such as AF_INET or AF_INET6
143 * @param address string of an address, such as "152.96.193.130"
144 * @param port port number
145 * @return
146 * - the host_t object, or
147 * - NULL, when family not supported.
148 *
149 * @ingroup network
150 */
151 host_t *host_create(int family, char *address, u_int16_t port);
152
153 /**
154 * @brief Constructor to create a host_t object
155 *
156 * Currently supports only IPv4!
157 *
158 * @param family Address family to use for this object, such as AF_INET or AF_INET6
159 * @param address address as 4 byte chunk_t in networ order
160 * @param port port number
161 * @return
162 * - the host_t object, or
163 * - NULL, when family not supported or chunk_t length not 4 bytes.
164 *
165 * @ingroup network
166 */
167 host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port);
168 #endif /*HOST_H_*/