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 IPPROTO_DCCP 33 /**< IANA assigned value. */
11 #define SOL_DCCP 269 /**< Linux socket level. */
14 /** The maximum length of the host component in an URL. */
15 #define MAX_HOSTLEN 256
17 /* Opaque, only known to net.c. */
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);
26 * Functions to parse and validate (parts of) URLs.
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);
36 * Ensure that string conforms to the IPv4 address format.
38 * \param address The address string to check.
40 * \return 1 if \a address conforms to the IPv4 address format, else 0.
42 _static_inline_ bool is_valid_ipv4_address(const char *address)
44 struct in_addr test_it;
46 return inet_pton(AF_INET, address, &test_it) != 0;
50 * Ensure that string conforms to IPv6 address format.
52 * \param address The address string to check.
54 * \return 1 if string has a valid IPv6 address syntax, 0 if not.
57 _static_inline_ bool is_valid_ipv6_address(const char *address)
59 struct in6_addr test_it;
61 return inet_pton(AF_INET6, address, &test_it) != 0;
64 int lookup_address(unsigned l4type, bool passive, const char *host,
65 int port_number, struct addrinfo **result);
68 * Generic socket creation (passive and active sockets).
70 int makesock(unsigned l4type, bool passive, const char *host,
71 uint16_t port_number, struct flowopts *fo);
73 int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
76 static inline int para_connect_simple(unsigned l4type,
77 const char *host, uint16_t port)
79 return makesock(l4type, 0, host, port, NULL);
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);
86 * Functions to support listening sockets.
88 /** How many pending connections queue of a listening server will hold. */
91 int para_listen(unsigned l4type, const char *addr, uint16_t port);
92 int para_listen_simple(unsigned l4type, uint16_t port);
94 /** Pretty-printing of IPv4/6 socket addresses */
95 char *remote_name(int sockfd);
98 * Determining maximum payload (packet) size
100 int generic_max_transport_msg_size(int sockfd);
102 int recv_bin_buffer(int fd, char *buf, size_t size);
103 int recv_buffer(int fd, char *buf, size_t size);
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*);
112 * Functions and definitions to support \p IPPROTO_DCCP
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);