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