]>
git.ipfire.org Git - people/ms/strongswan.git/blob - Source/lib/utils/host.h
4 * @brief Interface of host_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
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>
37 typedef struct host_t host_t
;
40 * @brief Representates a Host
42 * Host object, identifies a address:port pair and defines some
43 * useful functions on it.
47 * - host_create_from_chunk()
48 * - host_create_from_sockaddr()
50 * @todo Add IPv6 support
57 * @brief Build a clone of this host object.
59 * @param this object to clone
62 host_t
*(*clone
) (host_t
*this);
65 * @brief Get a pointer to the internal sockaddr struct.
67 * This is used for sending and receiving via sockets.
69 * @param this object to clone
70 * @return pointer to the internal sockaddr structure
72 sockaddr_t
*(*get_sockaddr
) (host_t
*this);
75 * @brief Get the length of the sockaddr struct.
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.
81 * This is used for sending and receiving via sockets.
83 * @param this object to clone
84 * @return length of the sockaddr struct
86 socklen_t
*(*get_sockaddr_len
) (host_t
*this);
89 * @brief Gets the address as xfrm_address_t.
91 * This function allows the conversion to an
92 * xfrm_address_t, used for netlink communication
95 * @see kernel_interface_t.
97 * @param this calling object
98 * @return address in xfrm_address_t format
100 xfrm_address_t (*get_xfrm_addr
) (host_t
*this);
103 * @brief Gets the family of the address
105 * @param this calling object
108 int (*get_family
) (host_t
*this);
111 * @brief get the address of this host
113 * Mostly used for debugging purposes.
114 * @warning string must NOT be freed
117 * @return address string,
119 char* (*get_address
) (host_t
*this);
122 * @brief Checks if the ip address of host is set to default route.
124 * @param this calling object
126 * - TRUE if host has IP 0.0.0.0 for default route
129 bool (*is_default_route
) (host_t
*this);
132 * @brief get the address of this host as chunk_t
134 * @warning returned chunk has to get destroyed by caller.
137 * @return address string,
139 chunk_t (*get_address_as_chunk
) (host_t
*this);
142 * @brief get the port of this host
144 * Mostly used for debugging purposes.
146 * @param this object to clone
147 * @return port number
149 u_int16_t (*get_port
) (host_t
*this);
152 * @brief Compare the ips of two hosts hosts.
154 * @param this object to compare
155 * @param other the other to compare
156 * @return TRUE if addresses are equal.
158 bool (*ip_equals
) (host_t
*this, host_t
*other
);
161 * @brief Compare two hosts, with port.
163 * @param this object to compare
164 * @param other the other to compare
165 * @return TRUE if addresses and ports are equal.
167 bool (*equals
) (host_t
*this, host_t
*other
);
170 * @brief Destroy this host object
172 * @param this calling
173 * @return SUCCESS in any case
175 void (*destroy
) (host_t
*this);
179 * @brief Constructor to create a host_t object from an address string
181 * Currently supports only IPv4!
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
188 * - NULL, if family not supported.
192 host_t
*host_create(int family
, char *address
, u_int16_t port
);
195 * @brief Constructor to create a host_t object from an address chunk
197 * Currently supports only IPv4!
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
204 * - NULL, if family not supported or chunk_t length not 4 bytes.
208 host_t
*host_create_from_chunk(int family
, chunk_t address
, u_int16_t port
);
211 * @brief Constructor to create a host_t object from a sockaddr struct
213 * Currently supports only IPv4!
215 * @param sockaddr sockaddr struct which contains family, address and port
218 * - NULL, if family not supported.
222 host_t
*host_create_from_sockaddr(sockaddr_t
*sockaddr
);