2 * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
8 /** \file net.h exported symbols from net.c */
11 * the buffer size of the sun_path component of struct sockaddr_un
13 * While glibc doesn't define \p UNIX_PATH_MAX, it
14 * documents it has being limited to 108 bytes.
17 #define UNIX_PATH_MAX 108
20 /** \cond Userland defines for Linux DCCP support. */
22 #define IPPROTO_DCCP 33 /* IANA assigned value */
23 #define SOCK_DCCP 6 /* Linux socket type */
24 #define SOL_DCCP 269 /* Linux socket level */
25 /* Per-connection CCID support (since v2.6.30-rc1) */
26 #define DCCP_SOCKOPT_AVAILABLE_CCIDS 12 /* List of supported CCIDs */
27 #define DCCP_SOCKOPT_CCID 13 /* Sets both TX/RX CCID */
28 #define DCCP_SOCKOPT_TX_CCID 14 /* Set/get the TX CCID */
29 #define DCCP_SOCKOPT_RX_CCID 15 /* Set/get the RX CCID */
35 * Flowopts: Transport-layer independent encapsulation of socket options
36 * that need to be registered prior to setting up a connection.
40 extern struct flowopts *flowopt_new(void);
41 extern void flowopt_add(struct flowopts *fo, int level, int opt,
42 char *name, const void *val, int len);
43 extern void flowopt_add_bool(struct flowopts *fo, int lev, int opt,
44 char *optname, bool on_or_off);
45 /** Flowopt shortcut macros */
46 #define OPT_ADD(fo, lev, opt, val, len) flowopt_add(fo, lev, opt, #opt, val, len)
47 #define OPT_ENABLE(fo, lev, opt) flowopt_add_bool(fo, lev, opt, #opt, 1)
48 #define OPT_DISABLE(fo, lev, opt) flowopt_add_bool(fo, lev, opt, #opt, 0)
51 * Functions to parse and validate (parts of) URLs.
53 extern char *parse_cidr(const char *cidr,
54 char *addr, ssize_t addrlen, int32_t *netmask);
55 extern char *parse_url(const char *url,
56 char *host, ssize_t hostlen, int32_t *port);
57 extern const char *stringify_port(int port, const char *transport);
59 * Ensure that string conforms to the IPv4 address format.
61 * \param address The address string to check.
63 * \return 1 if \a address conforms to the IPv4 address format, else 0.
65 _static_inline_ bool is_valid_ipv4_address(const char *address)
67 struct in_addr test_it;
69 return inet_pton(AF_INET, address, &test_it) != 0;
73 * Ensure that string conforms to IPv6 address format.
75 * \param address The address string to check.
77 * \return 1 if string has a valid IPv6 address syntax, 0 if not.
80 _static_inline_ bool is_valid_ipv6_address(const char *address)
82 struct in6_addr test_it;
84 return inet_pton(AF_INET6, address, &test_it) != 0;
88 * Generic socket creation (passive and active sockets).
90 extern int makesock(unsigned l4type, bool passive,
91 const char *host, uint16_t port_number,
94 static inline int para_connect_simple(unsigned l4type,
95 const char *host, uint16_t port)
97 return makesock(l4type, 0, host, port, NULL);
100 extern struct in_addr extract_v4_addr(const struct sockaddr_storage *ss);
103 * Functions to support listening sockets.
105 /** How many pending connections queue of a listening server will hold. */
107 extern int para_listen(unsigned l4type, uint16_t port, struct flowopts *fo);
109 static inline int para_listen_simple(unsigned l4type, uint16_t port)
111 return para_listen(l4type, port, NULL);
114 /** Pretty-printing of IPv4/6 socket addresses */
115 extern char *local_name(int sockfd);
116 extern char *remote_name(int sockfd);
118 int send_bin_buffer(int, const char *, size_t);
119 int send_buffer(int, const char *);
120 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
122 int recv_bin_buffer(int fd, char *buf, size_t size);
123 int recv_buffer(int fd, char *buf, size_t size);
125 int para_accept(int, void *addr, socklen_t size);
126 int create_local_socket(const char *name, struct sockaddr_un *unix_addr,
128 int create_remote_socket(const char *name);
129 int recv_cred_buffer(int, char *, size_t);
130 ssize_t send_cred_buffer(int, char*);
131 int recv_pattern(int fd, const char *pattern, size_t bufsize);
134 * Functions and definitions to support \p IPPROTO_DCCP
136 /** Hardcoded maximum number of separate CCID modules compiled into a host */
137 #define DCCP_MAX_HOST_CCIDS 20
138 extern const uint8_t *dccp_available_ccids(uint8_t *ccids, uint8_t *nccids);