]> git.tuebingen.mpg.de Git - paraslash.git/blob - net.h
net: Make is_valid_ipv{4,6}_address() local to net.c.
[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_simple(unsigned l4type,
44                                       const char *host, uint16_t port)
45 {
46         return makesock(l4type, 0, host, port, NULL);
47 }
48
49 void extract_v4_addr(const struct sockaddr_storage *ss, struct in_addr *ia);
50 bool sockaddr_equal(const struct sockaddr *sa1, const struct sockaddr *sa2);
51
52 /**
53  * Functions to support listening sockets.
54  */
55 /** How many pending connections queue of a listening server will hold. */
56 #define BACKLOG 10
57
58 int para_listen(unsigned l4type, const char *addr, uint16_t port);
59 int para_listen_simple(unsigned l4type, uint16_t port);
60
61 /** Pretty-printing of IPv4/6 socket addresses */
62 char *remote_name(int sockfd);
63
64 /**
65  * Determining maximum payload (packet) size
66  */
67 int generic_max_transport_msg_size(int sockfd);
68
69 int recv_bin_buffer(int fd, char *buf, size_t size);
70 int recv_buffer(int fd, char *buf, size_t size);
71
72 int para_accept(int fd, void *addr, socklen_t size, int *new_fd);
73 int create_local_socket(const char *name);
74 int connect_local_socket(const char *name);
75 int recv_cred_buffer(int, char *, size_t);
76 ssize_t send_cred_buffer(int, char*);
77
78 /**
79  * Functions and definitions to support \p IPPROTO_DCCP
80  */
81 /** Hardcoded maximum number of separate CCID modules compiled into a host. */
82 #define DCCP_MAX_HOST_CCIDS     20
83 int dccp_available_ccids(uint8_t **ccid_array);