1 /*
2 * Copyright (c) 2002-2014 Balabit
3 * Copyright (c) 1998-2013 Balázs Scheidler
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * As an additional exemption you are allowed to compile & link against the
19 * OpenSSL libraries as published by the OpenSSL project. See the file
20 * COPYING for details.
21 *
22 */
23 #ifndef SOCKET_OPTIONS_H_INCLUDED
24 #define SOCKET_OPTIONS_H_INCLUDED
25
26 #include "gsockaddr.h"
27
28 typedef enum
29 {
30 AFSOCKET_DIR_RECV = 0x01,
31 AFSOCKET_DIR_SEND = 0x02,
32 } AFSocketDirection;
33
34 typedef struct _SocketOptions SocketOptions;
35
36 struct _SocketOptions
37 {
38 /* socket options */
39 gint so_sndbuf;
40 gint so_rcvbuf;
41 gint so_broadcast;
42 gint so_keepalive;
43 gboolean so_reuseport;
44 gboolean (*setup_socket)(SocketOptions *s, gint sock, GSockAddr *bind_addr, AFSocketDirection dir);
45 gboolean (*setup_peer_socket)(SocketOptions *s, gint sock, GSockAddr *bind_addr);
46 void (*free)(gpointer s);
47 };
48
49 gboolean socket_options_setup_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr, AFSocketDirection dir);
50 gboolean socket_options_setup_peer_socket_method(SocketOptions *self, gint fd, GSockAddr *bind_addr);
51 void socket_options_init_instance(SocketOptions *self);
52 SocketOptions *socket_options_new(void);
53
54 static inline gboolean
socket_options_setup_socket(SocketOptions * s,gint sock,GSockAddr * bind_addr,AFSocketDirection dir)55 socket_options_setup_socket(SocketOptions *s, gint sock, GSockAddr *bind_addr, AFSocketDirection dir)
56 {
57 return s->setup_socket(s, sock, bind_addr, dir);
58 }
59
60 static inline gboolean
socket_options_setup_peer_socket(SocketOptions * s,gint sock,GSockAddr * bind_addr)61 socket_options_setup_peer_socket(SocketOptions *s, gint sock, GSockAddr *bind_addr)
62 {
63 return s->setup_peer_socket(s, sock, bind_addr);
64 }
65
66 static inline void
socket_options_free(SocketOptions * s)67 socket_options_free(SocketOptions *s)
68 {
69 s->free(s);
70 }
71
72 #endif
73