]> git.tuebingen.mpg.de Git - paraslash.git/blob - net.h
net: Remove IPPROTO_DCCP define.
[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 /**
32  * Ensure that string conforms to the IPv4 address format.
33  *
34  * \param address The address string to check.
35  *
36  * \return 1 if \a address conforms to the IPv4 address format, else 0.
37  */
38 _static_inline_ bool is_valid_ipv4_address(const char *address)
39 {
40         struct in_addr test_it;
41
42         return inet_pton(AF_INET, address, &test_it) != 0;
43 }
44
45 /**
46  * Ensure that string conforms to IPv6 address format.
47  *
48  * \param address The address string to check.
49  *
50  * \return 1 if string has a valid IPv6 address syntax, 0 if not.
51  * \sa RFC 4291.
52  */
53 _static_inline_ bool is_valid_ipv6_address(const char *address)
54 {
55         struct in6_addr test_it;
56
57         return inet_pton(AF_INET6, address, &test_it) != 0;
58 }
59
60 int lookup_address(unsigned l4type, bool passive, const char *host,
61                 int port_number, struct addrinfo **result);
62
63 /**
64  * Generic socket creation (passive and active sockets).
65  */
66 int makesock(unsigned l4type, bool passive, const char *host,
67                 uint16_t port_number, struct flowopts *fo);
68
69 int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
70                 struct flowopts *fo);
71
72 static inline int para_connect_simple(unsigned l4type,
73                                       const char *host, uint16_t port)
74 {
75         return makesock(l4type, 0, host, port, NULL);
76 }
77
78 void extract_v4_addr(const struct sockaddr_storage *ss, struct in_addr *ia);
79 bool sockaddr_equal(const struct sockaddr *sa1, const struct sockaddr *sa2);
80
81 /**
82  * Functions to support listening sockets.
83  */
84 /** How many pending connections queue of a listening server will hold. */
85 #define BACKLOG 10
86
87 int para_listen(unsigned l4type, const char *addr, uint16_t port);
88 int para_listen_simple(unsigned l4type, uint16_t port);
89
90 /** Pretty-printing of IPv4/6 socket addresses */
91 char *remote_name(int sockfd);
92
93 /**
94  * Determining maximum payload (packet) size
95  */
96 int generic_max_transport_msg_size(int sockfd);
97
98 int recv_bin_buffer(int fd, char *buf, size_t size);
99 int recv_buffer(int fd, char *buf, size_t size);
100
101 int para_accept(int fd, void *addr, socklen_t size, int *new_fd);
102 int create_local_socket(const char *name);
103 int connect_local_socket(const char *name);
104 int recv_cred_buffer(int, char *, size_t);
105 ssize_t send_cred_buffer(int, char*);
106
107 /**
108  * Functions and definitions to support \p IPPROTO_DCCP
109  */
110 /** Hardcoded maximum number of separate CCID modules compiled into a host. */
111 #define DCCP_MAX_HOST_CCIDS     20
112 int dccp_available_ccids(uint8_t **ccid_array);