2 * Copyright (C) 2006-2013 Tobias Brunner
3 * Copyright (C) 2005-2010 Martin Willi
4 * Copyright (C) 2006 Daniel Roethlisberger
5 * Copyright (C) 2005 Jan Hutter
6 * HSR Hochschule fuer Technik Rapperswil
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * @defgroup socket socket
27 typedef struct socket_t socket_t
;
28 typedef enum socket_family_t socket_family_t
;
31 #include <networking/packet.h>
32 #include <collections/enumerator.h>
33 #include <plugins/plugin.h>
36 * Constructor prototype for sockets.
38 typedef socket_t
*(*socket_constructor_t
)();
41 * Address families supported by socket implementations.
43 enum socket_family_t
{
45 * No address families supported
47 SOCKET_FAMILY_NONE
= 0,
52 SOCKET_FAMILY_IPV4
= (1 << 0),
57 SOCKET_FAMILY_IPV6
= (1 << 1),
60 * Both address families supported
62 SOCKET_FAMILY_BOTH
= (1 << 2) - 1,
66 * Socket interface definition.
73 * Reads a packet from the socket and sets source/dest
76 * @param packet pinter gets address from allocated packet_t
78 * - SUCCESS when packet successfully received
79 * - FAILED when unable to receive
81 status_t (*receive
)(socket_t
*this, packet_t
**packet
);
86 * Sends a packet to the net using source and destination addresses of
89 * @param packet packet_t to send
91 * - SUCCESS when packet successfully sent
92 * - FAILED when unable to send
94 status_t (*send
)(socket_t
*this, packet_t
*packet
);
97 * Get the port this socket is listening on.
99 * @param nat_t TRUE to get the port used to float in case of NAT-T
102 uint16_t (*get_port
)(socket_t
*this, bool nat_t
);
105 * Get the address families this socket is listening on.
107 * @return supported families
109 socket_family_t (*supported_families
)(socket_t
*this);
112 * Destroy a socket implementation.
114 void (*destroy
)(socket_t
*this);
118 * Helper function to (un-)register socket interfaces from plugin features.
120 * This function is a plugin_feature_callback_t and can be used with the
121 * PLUGIN_CALLBACK macro to register an socket interface constructor.
123 * @param plugin plugin registering the socket interface
124 * @param feature associated plugin feature
125 * @param reg TRUE to register, FALSE to unregister
126 * @param data data passed to callback, a socket_constructor_t
128 bool socket_register(plugin_t
*plugin
, plugin_feature_t
*feature
,
129 bool reg
, void *data
);
131 #endif /** SOCKET_H_ @}*/