edb273210c23c8ad42a83c9737dfd6f1b95cbd55
[strongswan.git] / Source / charon / socket.h
1 /**
2 * @file socket.h
3 *
4 * @brief management of sockets
5 *
6 * receiver reads from here, sender writes to here
7 *
8 */
9
10 /*
11 * Copyright (C) 2005 Jan Hutter, Martin Willi
12 * Hochschule fuer Technik Rapperswil
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #ifndef SOCKET_H_
26 #define SOCKET_H_
27
28
29 #include "types.h"
30 #include "packet.h"
31
32
33 /**
34 * maximum size of a packet
35 * 3000 Bytes should be sufficient, see IKEv2 draft
36 */
37 #define MAX_PACKET 3000
38
39
40 /**
41 * @brief abstraction of one (ipv4), or in future, of multiple sockets
42 *
43 */
44 typedef struct socket_s socket_t;
45 struct socket_s {
46 /**
47 * @brief receive a packet
48 *
49 * reads a packet from one of the sockets.
50 * source will be set, dest not implemented
51 *
52 *
53 * @param sock socket_t object to work on
54 * @param packet pinter gets address from allocated packet_t
55 * @return FAILED when unable to receive
56 * SUCCESS when packet successfully received
57 */
58 status_t (*receive) (socket_t *sock, packet_t **packet);
59
60 /**
61 * @brief send a packet
62 *
63 * sends a packet via desired socket.
64 * uses source and dest in packet.
65 *
66 * @param sock socket_t object to work on
67 * @param packet[out] packet_t to send
68 * @return FAILED when unable to send
69 * SUCCESS when packet successfully sent
70 */
71 status_t (*send) (socket_t *sock, packet_t *packet);
72
73 /**
74 * @brief destroy sockets
75 *
76 * close sockets and destroy socket_t object
77 *
78 * @param sock socket_t to destroy
79 * @return SUCCESS
80 */
81 status_t (*destroy) (socket_t *sock);
82 };
83
84 /**
85 * @brief socket_t constructor
86 *
87 * currently creates one socket, listening on all addresses
88 * on port.
89 *
90 * @param port port to bind socket to
91 * @return the created socket, or NULL on error
92 */
93 socket_t *socket_create(u_int16_t port);
94
95
96 #endif /*SOCKET_H_*/