]> git.ipfire.org Git - thirdparty/strongswan.git/blob - Source/charon/network/host.h
- changed allocation behavior
[thirdparty/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 * @warging string must NOT be freed
83 *
84 * @param this object to clone
85 * @return address string,
86 */
87 char* (*get_address) (host_t *this);
88
89 /**
90 * @brief get the port of this host
91 *
92 * Mostly used for debugging purposes.
93 *
94 * @param this object to clone
95 * @return port number
96 */
97 u_int16_t (*get_port) (host_t *this);
98
99 /**
100 * @brief Destroy this host object
101 *
102 * @param this calling
103 * @return SUCCESS in any case
104 */
105 void (*destroy) (host_t *this);
106 };
107
108 /**
109 * @brief Constructor to create a host_t object
110 *
111 * Currently supports only IPv4!
112 *
113 * @param family Address family to use for this object, such as AF_INET or AF_INET6
114 * @param address string of an address, such as "152.96.193.130"
115 * @param port port number
116 * @return
117 * - the host_t object, or
118 * - NULL, when family not supported.
119 *
120 * @ingroup network
121 */
122 host_t *host_create(int family, char *address, u_int16_t port);
123
124 #endif /*HOST_H_*/