f592e67ebdf989ee69eee2ab6d7184fd706d4a1c
4 * @brief host object, identifies a host and defines some useful functions on it.
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>
36 * @brief The logger object
38 typedef struct host_s host_t
;
41 * @brief Build a clone of this host object.
43 * @param this object to clone
44 * @param [out]other address where to allocate the clone
50 status_t (*clone
) (host_t
*this, host_t
**other
);
52 * @brief Get a pointer to the internal sockaddr struct.
54 * This is used for sending and receiving via sockets.
56 * @param this object to clone
57 * @return pointer to the internal sockaddr structure
59 sockaddr_t
*(*get_sockaddr
) (host_t
*this);
62 * @brief Get the length of the sockaddr struct.
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.
68 * This is used for sending and receiving via sockets.
70 * @param this object to clone
71 * @return length of the sockaddr struct
73 socklen_t
*(*get_sockaddr_len
) (host_t
*this);
76 * @brief get the address of this host
78 * Mostly used for debugging purposes.
79 * @warging string must NOT be freed
81 * @param this object to clone
82 * @return address string,
84 char* (*get_address
) (host_t
*this);
87 * @brief get the port of this host
89 * Mostly used for debugging purposes.
91 * @param this object to clone
94 u_int16_t (*get_port
) (host_t
*this);
97 * @brief Destroy this host object
100 * @return SUCCESS in any case
102 status_t (*destroy
) (host_t
*this);
106 * @brief Constructor to create a host_t object
108 * currently supports only IPv4!
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.
117 host_t
*host_create(int family
, char *address
, u_int16_t port
);