]> git.tuebingen.mpg.de Git - paraslash.git/blob - net.h
net: Make single-use macros local.
[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 IPPROTO_DCCP
7 #define IPPROTO_DCCP 33 /**< IANA assigned value. */
8 #endif
9
10 #ifndef SOL_DCCP
11 #define SOL_DCCP 269 /**< Linux socket level. */
12 #endif
13
14 /** The maximum length of the host component in an URL. */
15 #define MAX_HOSTLEN 256
16
17 /* Opaque, only known to net.c. */
18 struct flowopts;
19
20 struct flowopts *flowopt_new(void);
21 void flowopt_add(struct flowopts *fo, int level, int opt,
22                 const char *name, const void *val, int len);
23 void flowopt_cleanup(struct flowopts *fo);
24
25 /**
26  * Functions to parse and validate (parts of) URLs.
27  */
28 char *parse_cidr(const char *cidr,
29                 char *addr, ssize_t addrlen, int32_t *netmask);
30 char *parse_url(const char *url,
31                 char *host, ssize_t hostlen, int32_t *port);
32 char *format_url(const char *url, int default_port);
33 const char *stringify_port(int port, const char *transport);
34
35 /**
36  * Ensure that string conforms to the IPv4 address format.
37  *
38  * \param address The address string to check.
39  *
40  * \return 1 if \a address conforms to the IPv4 address format, else 0.
41  */
42 _static_inline_ bool is_valid_ipv4_address(const char *address)
43 {
44         struct in_addr test_it;
45
46         return inet_pton(AF_INET, address, &test_it) != 0;
47 }
48
49 /**
50  * Ensure that string conforms to IPv6 address format.
51  *
52  * \param address The address string to check.
53  *
54  * \return 1 if string has a valid IPv6 address syntax, 0 if not.
55  * \sa RFC 4291.
56  */
57 _static_inline_ bool is_valid_ipv6_address(const char *address)
58 {
59         struct in6_addr test_it;
60
61         return inet_pton(AF_INET6, address, &test_it) != 0;
62 }
63
64 int lookup_address(unsigned l4type, bool passive, const char *host,
65                 int port_number, struct addrinfo **result);
66
67 /**
68  * Generic socket creation (passive and active sockets).
69  */
70 int makesock(unsigned l4type, bool passive, const char *host,
71                 uint16_t port_number, struct flowopts *fo);
72
73 int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
74                 struct flowopts *fo);
75
76 static inline int para_connect_simple(unsigned l4type,
77                                       const char *host, uint16_t port)
78 {
79         return makesock(l4type, 0, host, port, NULL);
80 }
81
82 void extract_v4_addr(const struct sockaddr_storage *ss, struct in_addr *ia);
83 bool sockaddr_equal(const struct sockaddr *sa1, const struct sockaddr *sa2);
84
85 /**
86  * Functions to support listening sockets.
87  */
88 /** How many pending connections queue of a listening server will hold. */
89 #define BACKLOG 10
90
91 int para_listen(unsigned l4type, const char *addr, uint16_t port);
92 int para_listen_simple(unsigned l4type, uint16_t port);
93
94 /** Pretty-printing of IPv4/6 socket addresses */
95 char *remote_name(int sockfd);
96
97 /**
98  * Determining maximum payload (packet) size
99  */
100 int generic_max_transport_msg_size(int sockfd);
101
102 int recv_bin_buffer(int fd, char *buf, size_t size);
103 int recv_buffer(int fd, char *buf, size_t size);
104
105 int para_accept(int fd, void *addr, socklen_t size, int *new_fd);
106 int create_local_socket(const char *name);
107 int connect_local_socket(const char *name);
108 int recv_cred_buffer(int, char *, size_t);
109 ssize_t send_cred_buffer(int, char*);
110
111 /**
112  * Functions and definitions to support \p IPPROTO_DCCP
113  */
114 /** Hardcoded maximum number of separate CCID modules compiled into a host. */
115 #define DCCP_MAX_HOST_CCIDS     20
116 int dccp_available_ccids(uint8_t **ccid_array);