aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/network/host.h
blob: a430d7134a061a1a73a91a4bdb28b24d1c29b573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * @file host.h
 *
 * @brief Interface of host_t.
 *
 */

/*
 * Copyright (C) 2005 Jan Hutter, Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#ifndef HOST_H_
#define HOST_H_

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <types.h>


typedef struct host_t host_t;

/**
 * @brief Representates a Host
 * 
 * Host object, identifies a host and defines some useful functions on it.
 * 
 * @ingroup network
 */
struct host_t {
	/** 
	 * @brief Build a clone of this host object.
	 * 
	 * @param this			object to clone
	 * @return				cloned host
	 */
	host_t *(*clone) (host_t *this);
	
	/** 
	 * @brief Get a pointer to the internal sockaddr struct.
	 * 
	 * This is used for sending and receiving via sockets.
	 * 
	 * @param this			object to clone
	 * @return				pointer to the internal sockaddr structure
	 */
	sockaddr_t  *(*get_sockaddr) (host_t *this);
	
	/** 
	 * @brief Get the length of the sockaddr struct.
	 * 
	 * Sepending on the family, the length of the sockaddr struct
	 * is different. Use this function to get the length of the sockaddr
	 * struct returned by get_sock_addr.
	 * 
	 * This is used for sending and receiving via sockets.
	 * 
	 * @param this			object to clone
	 * @return				length of the sockaddr struct
	 */
	socklen_t *(*get_sockaddr_len) (host_t *this);
	
	/** 
	 * @brief get the address of this host
	 * 
	 * Mostly used for debugging purposes. 
	 * @warging string must NOT be freed
	 * 
	 * @param this			object to clone
	 * @return				address string, 
	 */
	char* (*get_address) (host_t *this);
		
	/** 
	 * @brief get the port of this host
	 * 
	 * Mostly used for debugging purposes. 
	 * 
	 * @param this			object to clone
	 * @return				port number
	 */
	u_int16_t (*get_port) (host_t *this);
	
	/** 
	 * @brief Destroy this host object
	 * 
	 * @param this			calling
	 * @return				SUCCESS in any case
	 */
	void (*destroy) (host_t *this);
};

/**
 * @brief Constructor to create a host_t object
 * 
 * Currently supports only IPv4!
 *
 * @param family 		Address family to use for this object, such as AF_INET or AF_INET6
 * @param address		string of an address, such as "152.96.193.130"
 * @param port			port number
 * @return 				
 * 						- the host_t object, or 
 * 						- NULL, when family not supported.
 * 
 * @ingroup network
 */
host_t *host_create(int family, char *address, u_int16_t port);

#endif /*HOST_H_*/