1 /* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2 /** \file net.h exported symbols from net.c */
4 /* Userland defines for Linux DCCP support. */
7 #define SOL_DCCP 269 /**< Linux socket level. */
10 /** The maximum length of the host component in an URL. */
11 #define MAX_HOSTLEN 256
13 /* Opaque, only known to net.c. */
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);
22 * Functions to parse and validate (parts of) URLs.
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);
32 * Ensure that string conforms to the IPv4 address format.
34 * \param address The address string to check.
36 * \return 1 if \a address conforms to the IPv4 address format, else 0.
38 _static_inline_ bool is_valid_ipv4_address(const char *address)
40 struct in_addr test_it;
42 return inet_pton(AF_INET, address, &test_it) != 0;
46 * Ensure that string conforms to IPv6 address format.
48 * \param address The address string to check.
50 * \return 1 if string has a valid IPv6 address syntax, 0 if not.
53 _static_inline_ bool is_valid_ipv6_address(const char *address)
55 struct in6_addr test_it;
57 return inet_pton(AF_INET6, address, &test_it) != 0;
60 int lookup_address(unsigned l4type, bool passive, const char *host,
61 int port_number, struct addrinfo **result);
64 * Generic socket creation (passive and active sockets).
66 int makesock(unsigned l4type, bool passive, const char *host,
67 uint16_t port_number, struct flowopts *fo);
69 int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
72 static inline int para_connect_simple(unsigned l4type,
73 const char *host, uint16_t port)
75 return makesock(l4type, 0, host, port, NULL);
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);
82 * Functions to support listening sockets.
84 /** How many pending connections queue of a listening server will hold. */
87 int para_listen(unsigned l4type, const char *addr, uint16_t port);
88 int para_listen_simple(unsigned l4type, uint16_t port);
90 /** Pretty-printing of IPv4/6 socket addresses */
91 char *remote_name(int sockfd);
94 * Determining maximum payload (packet) size
96 int generic_max_transport_msg_size(int sockfd);
98 int recv_bin_buffer(int fd, char *buf, size_t size);
99 int recv_buffer(int fd, char *buf, size_t size);
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*);
108 * Functions and definitions to support \p IPPROTO_DCCP
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);