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 */
29 * Ensure that string conforms to the IPv4 address format.
31 * \param address The address string to check.
33 * \return 1 if \a address conforms to the IPv4 address format, else 0.
35 _static_inline_ bool is_valid_ipv4_address(const char *address)
37 struct in_addr test_it;
39 return inet_pton(AF_INET, address, &test_it) != 0;
43 * Generic socket creation (passive and active sockets).
45 extern int makesock(unsigned l3type, unsigned l4type, int passive,
46 const char *host, unsigned short port_number);
47 extern struct in_addr extract_v4_addr(const struct sockaddr_storage *ss);
50 * Functions to support listening sockets.
52 /** How many pending connections queue of a listening server will hold. */
54 extern int para_listen(unsigned l3type, unsigned l4type, unsigned short port);
56 /** Pretty-printing of IPv4/6 socket addresses */
57 extern char *local_name(int sockfd);
58 extern char *remote_name(int sockfd);
60 /** used to crypt the communication between para_server and para_client */
61 typedef void crypt_function(unsigned long len,
62 const unsigned char *indata, unsigned char *outdata, void *private_data);
64 int send_buffer(int, const char *);
65 int send_bin_buffer(int, const char *, size_t);
66 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
67 int recv_buffer(int fd, char *buf, size_t size);
68 int recv_bin_buffer(int fd, char *buf, size_t size);
69 int para_accept(int, void *addr, socklen_t size);
70 int create_local_socket(const char *name, struct sockaddr_un *unix_addr,
72 int create_remote_socket(const char *name);
73 int recv_cred_buffer(int, char *, size_t);
74 ssize_t send_cred_buffer(int, char*);
75 int recv_pattern(int fd, const char *pattern, size_t bufsize);
76 void enable_crypt(int fd, crypt_function *recv_f, crypt_function *send_f,
78 void disable_crypt(int fd);