Merge topic branch t/ff-compat into master
[paraslash.git] / net.h
1 /* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2 /** \file net.h exported symbols from net.c */
3
4 /* Userland defines for Linux DCCP support. */
5
6 #ifndef SOL_DCCP
7 #define SOL_DCCP 269 /**< Linux socket level. */
8 #endif
9
10 /** The maximum length of the host component in an URL. */
11 #define MAX_HOSTLEN 256
12
13 /* Opaque, only known to net.c. */
14 struct flowopts;
15
16 struct flowopts *flowopt_new(void);
17 void flowopt_add(struct flowopts *fo, int level, int opt,
18 const char *name, const void *val, int len);
19 void flowopt_cleanup(struct flowopts *fo);
20
21 /**
22 * Functions to parse and validate (parts of) URLs.
23 */
24 char *parse_cidr(const char *cidr,
25 char *addr, ssize_t addrlen, int32_t *netmask);
26 char *parse_url(const char *url,
27 char *host, ssize_t hostlen, int32_t *port);
28 char *format_url(const char *url, int default_port);
29 const char *stringify_port(int port, const char *transport);
30
31 int lookup_address(unsigned l4type, bool passive, const char *host,
32 int port_number, struct addrinfo **result);
33
34 /**
35 * Generic socket creation (passive and active sockets).
36 */
37 int makesock(unsigned l4type, bool passive, const char *host,
38 uint16_t port_number, struct flowopts *fo);
39
40 int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
41 struct flowopts *fo);
42
43 static inline int para_connect(unsigned l4type, const char *host, uint16_t port)
44 {
45 return makesock(l4type, false, host, port, NULL);
46 }
47
48 void extract_v4_addr(const struct sockaddr_storage *ss, struct in_addr *ia);
49 bool sockaddr_equal(const struct sockaddr *sa1, const struct sockaddr *sa2);
50
51 /**
52 * Functions to support listening sockets.
53 */
54 /** How many pending connections queue of a listening server will hold. */
55 #define BACKLOG 10
56
57 int para_listen(unsigned l4type, const char *addr, uint16_t port);
58 int para_listen_simple(unsigned l4type, uint16_t port);
59
60 /** Pretty-printing of IPv4/6 socket addresses */
61 char *remote_name(int sockfd);
62
63 /**
64 * Determining maximum payload (packet) size
65 */
66 int generic_max_transport_msg_size(int sockfd);
67
68 int recv_bin_buffer(int fd, char *buf, size_t size);
69 int recv_buffer(int fd, char *buf, size_t size);
70
71 int para_accept(int fd, void *addr, socklen_t size, int *new_fd);
72 int create_local_socket(const char *name);
73 int connect_local_socket(const char *name);
74 int recv_cred_buffer(int, char *, size_t);
75 ssize_t send_cred_buffer(int, char*);
76
77 /**
78 * Functions and definitions to support \p IPPROTO_DCCP
79 */
80 /** Hardcoded maximum number of separate CCID modules compiled into a host. */
81 #define DCCP_MAX_HOST_CCIDS 20
82 int dccp_available_ccids(uint8_t **ccid_array);