4 * @brief Interface for socket_t.
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
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>.
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
30 #include <network/packet.h>
31 #include <utils/host.h>
32 #include <utils/linked_list.h>
36 * @brief Maximum size of a packet.
38 * 3000 Bytes should be sufficient, see IKEv2 RFC.
42 #define MAX_PACKET 3000
45 typedef struct socket_t socket_t
;
48 * @brief Abstraction of all sockets (IPv6/IPv6 send/receive).
50 * All available sockets are bound and the receive function
51 * reads from them. To allow binding of other daemons (pluto) to
52 * UDP/500, this implementation uses RAW sockets. An installed
53 * "Linux socket filter" filters out all non-IKEv2 traffic and handles
54 * just IKEv2 messages. An other daemon (pluto) must handle all traffic
55 * seperatly, e.g. ignore IKEv2 traffic, since charon handles that.
65 * @brief Receive a packet.
67 * Reads a packet from the socket and sets source/dest
70 * @param this socket_t object to work on
71 * @param packet pinter gets address from allocated packet_t
73 * - SUCCESS when packet successfully received
74 * - FAILED when unable to receive
76 status_t (*receive
) (socket_t
*this, packet_t
**packet
);
79 * @brief Send a packet.
81 * Sends a packet to the net using destination from the packet.
82 * Packet is sent using default routing mechanisms, thus the
83 * source address in packet is ignored.
85 * @param this socket_t object to work on
86 * @param packet[out] packet_t to send
88 * - SUCCESS when packet successfully sent
89 * - FAILED when unable to send
91 status_t (*send
) (socket_t
*this, packet_t
*packet
);
94 * @brief Check if an address is an address of this host.
96 * @param this socket_t object to work on
97 * @param host address to check
98 * @return TRUE if local address, FALSE otherwise
100 bool (*is_local_address
) (socket_t
*this, host_t
*host
);
103 * @brief Create a list of hosts with all local addresses.
105 * @param this socket_t object to work on
106 * @return list with host_t objects
108 linked_list_t
*(*create_local_address_list
) (socket_t
*this);
111 * @brief Destroy sockets.
113 * close sockets and destroy socket_t object
115 * @param this socket_t to destroy
117 void (*destroy
) (socket_t
*this);
121 * @brief Create a socket_t, wich binds multiple sockets.
123 * @param port port to bind socket to
124 * @param natt_port port to float to in NAT-T
125 * @return socket_t object
129 socket_t
*socket_create(u_int16_t port
, u_int16_t natt_port
);