05_DCCP-Remove-Unused.diff
[paraslash.git] / net.h
1 /*
2  * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file net.h exported symbols from net.c */
8
9 /**
10  * the buffer size of the sun_path component of struct sockaddr_un
11  *
12  * While glibc doesn't define \p UNIX_PATH_MAX, it
13  * documents it has being limited to 108 bytes.
14  */
15 #ifndef UNIX_PATH_MAX
16 #define UNIX_PATH_MAX 108
17 #endif
18
19 /** \cond Userland defines for Linux DCCP support. */
20 #ifndef IPPROTO_DCCP
21 #define IPPROTO_DCCP    33      /**< IANA assigned value */
22 #define SOCK_DCCP       6       /**< Linux socket type   */
23 #define SOL_DCCP        269     /**< Linux socket level  */
24 #endif
25 /** \endcond */
26
27 /**
28  * Generic socket creation (passive and active sockets).
29  */
30 extern int makesock(unsigned l3type, unsigned l4type, int passive,
31                     const char *host, unsigned short port_number);
32
33 /**
34  * Functions to support listening sockets.
35  */
36 /** How many pending connections queue of a listening server will hold. */
37 #define BACKLOG 10
38 extern int para_listen(unsigned l3type, unsigned l4type, unsigned short port);
39
40 /** Pretty-printing of IPv4/6 socket addresses */
41 extern char *host_and_port(struct sockaddr *sa, socklen_t len);
42 extern char *local_name(int sockfd);
43 extern char *remote_name(int sockfd);
44
45 /** used to crypt the communication between para_server and para_client */
46 typedef void crypt_function(unsigned long len,
47         const unsigned char *indata, unsigned char *outdata, void *private_data);
48
49 int get_stream_socket(int domain);
50 int send_buffer(int, const char *);
51 int send_bin_buffer(int, const char *, size_t);
52 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
53 int recv_buffer(int fd, char *buf, size_t size);
54 int recv_bin_buffer(int fd, char *buf, size_t size);
55 int para_accept(int, void *addr, socklen_t size);
56 int create_local_socket(const char *name, struct sockaddr_un *unix_addr,
57         mode_t mode);
58 int init_unix_addr(struct sockaddr_un *, const char *);
59 int recv_cred_buffer(int, char *, size_t);
60 ssize_t send_cred_buffer(int, char*);
61 int recv_pattern(int fd, const char *pattern, size_t bufsize);
62 void enable_crypt(int fd, crypt_function *recv_f, crypt_function *send_f,
63         void *private_data);
64 void disable_crypt(int fd);
65
66 /**
67  * A wrapper around connect(2).
68  *
69  * \param fd The file descriptor.
70  * \param addr The address to connect.
71  * \param len The size of \a addr.
72  *
73  * This should not be called directly. Always use the PARA_CONNECT macro.
74  *
75  * \return \p -E_CONNECT on errors, 1 on success.
76  *
77  * \sa connect(2), PARA_CONNECT.
78  */
79 static inline int _para_connect(int fd, void *addr, socklen_t len)
80 {
81         if (connect(fd, (struct sockaddr *)addr, len) == -1)
82                 return -E_CONNECT;
83         return 1;
84 }
85
86 /** A macro for connect() which does not need a \a len parameter. */
87 #define PARA_CONNECT(fd, addr) _para_connect(fd, addr, sizeof(*(addr)))