- moved host_t from util to network
[strongswan.git] / Source / charon / network / host.h
1 /**
2 * @file host.h
3 *
4 * @brief host object, identifies a host and defines some useful functions on it.
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 * @brief The logger object
37 */
38 typedef struct host_s host_t;
39 struct host_s {
40 /**
41 * @brief Build a clone of this host object.
42 *
43 * @param this object to clone
44 * @param [out]other address where to allocate the clone
45 * @return
46 * - SUCCESS, or
47 * - OUT_OF_RES
48 */
49
50 status_t (*clone) (host_t *this, host_t **other);
51 /**
52 * @brief Get a pointer to the internal sockaddr struct.
53 *
54 * This is used for sending and receiving via sockets.
55 *
56 * @param this object to clone
57 * @return pointer to the internal sockaddr structure
58 */
59 sockaddr_t *(*get_sockaddr) (host_t *this);
60
61 /**
62 * @brief Get the length of the sockaddr struct.
63 *
64 * Sepending on the family, the length of the sockaddr struct
65 * is different. Use this function to get the length of the sockaddr
66 * struct returned by get_sock_addr.
67 *
68 * This is used for sending and receiving via sockets.
69 *
70 * @param this object to clone
71 * @return length of the sockaddr struct
72 */
73 socklen_t *(*get_sockaddr_len) (host_t *this);
74
75 /**
76 * @brief get the address of this host
77 *
78 * Mostly used for debugging purposes.
79 * @warging string must NOT be freed
80 *
81 * @param this object to clone
82 * @return address string,
83 */
84 char* (*get_address) (host_t *this);
85
86 /**
87 * @brief get the port of this host
88 *
89 * Mostly used for debugging purposes.
90 *
91 * @param this object to clone
92 * @return port number
93 */
94 u_int16_t (*get_port) (host_t *this);
95
96 /**
97 * @brief Destroy this host object
98 *
99 * @param this calling
100 * @return SUCCESS in any case
101 */
102 status_t (*destroy) (host_t *this);
103 };
104
105 /**
106 * @brief Constructor to create a host_t object
107 *
108 * currently supports only IPv4!
109 *
110 * @param family Address family to use for this object, such as AF_INET or AF_INET6
111 * @param address string of an address, such as "152.96.193.130"
112 * @param port port number
113 * @return the host_t object or NULL, when
114 * not enough ressources, or
115 * family not supported.
116 */
117 host_t *host_create(int family, char *address, u_int16_t port);
118
119
120 #endif /*HOST_H_*/