Annotation of embedaddon/strongswan/src/libcharon/network/socket.h, revision 1.1.1.1
1.1 misho 1: /*
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
7: *
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>.
12: *
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
16: * for more details.
17: */
18:
19: /**
20: * @defgroup socket socket
21: * @{ @ingroup network
22: */
23:
24: #ifndef SOCKET_H_
25: #define SOCKET_H_
26:
27: typedef struct socket_t socket_t;
28: typedef enum socket_family_t socket_family_t;
29:
30: #include <library.h>
31: #include <networking/packet.h>
32: #include <collections/enumerator.h>
33: #include <plugins/plugin.h>
34:
35: /**
36: * Constructor prototype for sockets.
37: */
38: typedef socket_t *(*socket_constructor_t)();
39:
40: /**
41: * Address families supported by socket implementations.
42: */
43: enum socket_family_t {
44: /**
45: * No address families supported
46: */
47: SOCKET_FAMILY_NONE = 0,
48:
49: /**
50: * IPv4
51: */
52: SOCKET_FAMILY_IPV4 = (1 << 0),
53:
54: /**
55: * IPv6
56: */
57: SOCKET_FAMILY_IPV6 = (1 << 1),
58:
59: /**
60: * Both address families supported
61: */
62: SOCKET_FAMILY_BOTH = (1 << 2) - 1,
63: };
64:
65: /**
66: * Socket interface definition.
67: */
68: struct socket_t {
69:
70: /**
71: * Receive a packet.
72: *
73: * Reads a packet from the socket and sets source/dest
74: * appropriately.
75: *
76: * @param packet pinter gets address from allocated packet_t
77: * @return
78: * - SUCCESS when packet successfully received
79: * - FAILED when unable to receive
80: */
81: status_t (*receive)(socket_t *this, packet_t **packet);
82:
83: /**
84: * Send a packet.
85: *
86: * Sends a packet to the net using source and destination addresses of
87: * the packet.
88: *
89: * @param packet packet_t to send
90: * @return
91: * - SUCCESS when packet successfully sent
92: * - FAILED when unable to send
93: */
94: status_t (*send)(socket_t *this, packet_t *packet);
95:
96: /**
97: * Get the port this socket is listening on.
98: *
99: * @param nat_t TRUE to get the port used to float in case of NAT-T
100: * @return the port
101: */
102: uint16_t (*get_port)(socket_t *this, bool nat_t);
103:
104: /**
105: * Get the address families this socket is listening on.
106: *
107: * @return supported families
108: */
109: socket_family_t (*supported_families)(socket_t *this);
110:
111: /**
112: * Destroy a socket implementation.
113: */
114: void (*destroy)(socket_t *this);
115: };
116:
117: /**
118: * Helper function to (un-)register socket interfaces from plugin features.
119: *
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.
122: *
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
127: */
128: bool socket_register(plugin_t *plugin, plugin_feature_t *feature,
129: bool reg, void *data);
130:
131: #endif /** SOCKET_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>