07_flow-opt-support.diff
[paraslash.git] / net.h
1 /*
2 * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6 #include <stdbool.h>
7
8 /** \file net.h exported symbols from net.c */
9
10 /**
11 * the buffer size of the sun_path component of struct sockaddr_un
12 *
13 * While glibc doesn't define \p UNIX_PATH_MAX, it
14 * documents it has being limited to 108 bytes.
15 */
16 #ifndef UNIX_PATH_MAX
17 #define UNIX_PATH_MAX 108
18 #endif
19
20 /** \cond Userland defines for Linux DCCP support. */
21 #ifndef IPPROTO_DCCP
22 #define IPPROTO_DCCP 33 /* IANA assigned value */
23 #define SOCK_DCCP 6 /* Linux socket type */
24 #define SOL_DCCP 269 /* Linux socket level */
25 /* Per-connection CCID support (since v2.6.30-rc1) */
26 #define DCCP_SOCKOPT_AVAILABLE_CCIDS 12 /* List of supported CCIDs */
27 #define DCCP_SOCKOPT_CCID 13 /* Sets both TX/RX CCID */
28 #define DCCP_SOCKOPT_TX_CCID 14 /* Set/get the TX CCID */
29 #define DCCP_SOCKOPT_RX_CCID 15 /* Set/get the RX CCID */
30 #endif
31 /** \endcond */
32
33
34 /**
35 * Flowopts: Transport-layer independent encapsulation of socket options
36 * that need to be registered prior to setting up a connection.
37 */
38 struct flowopts;
39
40 extern struct flowopts *flowopt_new(void);
41 extern void flowopt_add(struct flowopts *fo, int level, int opt,
42 char *name, const void *val, int len);
43 extern void flowopt_add_bool(struct flowopts *fo, int lev, int opt,
44 char *optname, bool on_or_off);
45 /** Flowopt shortcut macros */
46 #define OPT_ADD(fo, lev, opt, val, len) flowopt_add(fo, lev, opt, #opt, val, len)
47 #define OPT_ENABLE(fo, lev, opt) flowopt_add_bool(fo, lev, opt, #opt, 1)
48 #define OPT_DISABLE(fo, lev, opt) flowopt_add_bool(fo, lev, opt, #opt, 0)
49
50 /**
51 * Functions to parse and validate (parts of) URLs.
52 */
53 extern char *parse_cidr(const char *cidr,
54 char *addr, ssize_t addrlen, int32_t *netmask);
55 extern char *parse_url(const char *url,
56 char *host, ssize_t hostlen, int32_t *port);
57 extern const char *stringify_port(int port, const char *transport);
58 /**
59 * Ensure that string conforms to the IPv4 address format.
60 *
61 * \param address The address string to check.
62 *
63 * \return 1 if \a address conforms to the IPv4 address format, else 0.
64 */
65 _static_inline_ bool is_valid_ipv4_address(const char *address)
66 {
67 struct in_addr test_it;
68
69 return inet_pton(AF_INET, address, &test_it) != 0;
70 }
71
72 /**
73 * Ensure that string conforms to IPv6 address format.
74 *
75 * \param address The address string to check.
76 *
77 * \return 1 if string has a valid IPv6 address syntax, 0 if not.
78 * \sa RFC 4291
79 */
80 _static_inline_ bool is_valid_ipv6_address(const char *address)
81 {
82 struct in6_addr test_it;
83
84 return inet_pton(AF_INET6, address, &test_it) != 0;
85 }
86
87 /**
88 * Generic socket creation (passive and active sockets).
89 */
90 extern int makesock(unsigned l3type, unsigned l4type, int passive,
91 const char *host, unsigned short port_number,
92 struct flowopts *fo);
93 extern struct in_addr extract_v4_addr(const struct sockaddr_storage *ss);
94
95 /**
96 * Functions to support listening sockets.
97 */
98 /** How many pending connections queue of a listening server will hold. */
99 #define BACKLOG 10
100 extern int para_listen(unsigned l3type, unsigned l4type, unsigned short port);
101
102 /** Pretty-printing of IPv4/6 socket addresses */
103 extern char *local_name(int sockfd);
104 extern char *remote_name(int sockfd);
105
106 int send_bin_buffer(int, const char *, size_t);
107 int send_buffer(int, const char *);
108 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
109
110 int recv_bin_buffer(int fd, char *buf, size_t size);
111 int recv_buffer(int fd, char *buf, size_t size);
112
113 int para_accept(int, void *addr, socklen_t size);
114 int create_local_socket(const char *name, struct sockaddr_un *unix_addr,
115 mode_t mode);
116 int create_remote_socket(const char *name);
117 int recv_cred_buffer(int, char *, size_t);
118 ssize_t send_cred_buffer(int, char*);
119 int recv_pattern(int fd, const char *pattern, size_t bufsize);
120
121 /**
122 * Functions and definitions to support \p IPPROTO_DCCP
123 */
124 /** Hardcoded maximum number of separate CCID modules compiled into a host */
125 #define DCCP_MAX_HOST_CCIDS 20
126 extern const uint8_t *dccp_available_ccids(uint8_t *ccids, uint8_t *nccids);