]> git.tuebingen.mpg.de Git - paraslash.git/blob - net.h
10_set-client-ccid.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 l4type, bool passive,
91                     const char *host, uint16_t port_number,
92                     struct flowopts *fo);
93
94 static inline int para_connect_simple(unsigned l4type,
95                                       const char *host, uint16_t port)
96 {
97         return makesock(l4type, 0, host, port, NULL);
98 }
99
100 extern struct in_addr extract_v4_addr(const struct sockaddr_storage *ss);
101
102 /**
103  * Functions to support listening sockets.
104  */
105 /** How many pending connections queue of a listening server will hold. */
106 #define BACKLOG 10
107 extern int para_listen(unsigned l4type, uint16_t port, struct flowopts *fo);
108
109 static inline int para_listen_simple(unsigned l4type, uint16_t port)
110 {
111         return para_listen(l4type, port, NULL);
112 }
113
114 /** Pretty-printing of IPv4/6 socket addresses */
115 extern char *local_name(int sockfd);
116 extern char *remote_name(int sockfd);
117
118 int send_bin_buffer(int, const char *, size_t);
119 int send_buffer(int, const char *);
120 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
121
122 int recv_bin_buffer(int fd, char *buf, size_t size);
123 int recv_buffer(int fd, char *buf, size_t size);
124
125 int para_accept(int, void *addr, socklen_t size);
126 int create_local_socket(const char *name, struct sockaddr_un *unix_addr,
127         mode_t mode);
128 int create_remote_socket(const char *name);
129 int recv_cred_buffer(int, char *, size_t);
130 ssize_t send_cred_buffer(int, char*);
131 int recv_pattern(int fd, const char *pattern, size_t bufsize);
132
133 /**
134  * Functions and definitions to support \p IPPROTO_DCCP
135  */
136 /** Hardcoded maximum number of separate CCID modules compiled into a host */
137 #define DCCP_MAX_HOST_CCIDS     20
138 extern const uint8_t *dccp_available_ccids(uint8_t *ccids, uint8_t *nccids);