8a00e88b0f85ec4528bc5435645c4bc73d4a93d7
[strongswan.git] / Source / charon / network / socket.h
1 /**
2 * @file socket.h
3 *
4 * @brief Interface for socket_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 SOCKET_H_
24 #define SOCKET_H_
25
26
27 #include <types.h>
28 #include <network/packet.h>
29
30
31 /**
32 * @brief Maximum size of a packet.
33 *
34 * 3000 Bytes should be sufficient, see IKEv2 draft.
35 *
36 * @ingroup network
37 */
38 #define MAX_PACKET 3000
39
40
41 typedef struct socket_t socket_t;
42
43 /**
44 * @brief Abstraction of one (ipv4), or in future, of multiple sockets.
45 *
46 * Receiver reads from here, sender writes to here.
47 *
48 * @b Constructors:
49 * - socket_create()
50 *
51 * @todo add IPv6 support
52 *
53 * @todo allow listening/sending to multiple sockets, depending on address
54 *
55 * @ingroup network
56 */
57 struct socket_t {
58 /**
59 * @brief Receive a packet.
60 *
61 * reads a packet from one of the sockets.
62 * source will be set, dest not implemented
63 *
64 *
65 * @param sock socket_t object to work on
66 * @param packet pinter gets address from allocated packet_t
67 * @return
68 * - SUCCESS when packet successfully received
69 * - FAILED when unable to receive
70 */
71 status_t (*receive) (socket_t *sock, packet_t **packet);
72
73 /**
74 * @brief Send a packet.
75 *
76 * sends a packet via desired socket.
77 * uses source and dest in packet.
78 *
79 * @param sock socket_t object to work on
80 * @param packet[out] packet_t to send
81 * @return
82 * - SUCCESS when packet successfully sent
83 * - FAILED when unable to send
84 */
85 status_t (*send) (socket_t *sock, packet_t *packet);
86
87 /**
88 * @brief Destroy sockets.
89 *
90 * close sockets and destroy socket_t object
91 *
92 * @param sock socket_t to destroy
93 */
94 void (*destroy) (socket_t *sock);
95 };
96
97 /**
98 * @brief socket_t constructor.
99 *
100 * currently creates one socket, listening on all addresses
101 * on port.
102 *
103 * @param port port to bind socket to
104 * @return socket_t object
105 *
106 * @ingroup network
107 */
108 socket_t *socket_create(u_int16_t port);
109
110
111 #endif /*SOCKET_H_*/