2 * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file net.h exported symbols from net.c */
10 * the buffer size of the sun_path component of struct sockaddr_un
12 * While glibc doesn't define \p UNIX_PATH_MAX, it
13 * documents it has being limited to 108 bytes.
16 #define UNIX_PATH_MAX 108
19 /** used to crypt the communication between para_server and para_client */
20 typedef void crypt_function(unsigned long len,
21 const unsigned char *indata, unsigned char *outdata, void *private_data);
23 int tcp_connect(char *host, int port);
24 int get_stream_socket(int domain);
25 int send_buffer(int, const char *);
26 int send_bin_buffer(int, const char *, size_t);
27 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
28 int recv_buffer(int fd, char *buf, size_t size);
29 int recv_bin_buffer(int fd, char *buf, size_t size);
30 int para_accept(int, void *addr, socklen_t size);
31 int create_local_socket(const char *name, struct sockaddr_un *unix_addr,
33 int init_unix_addr(struct sockaddr_un *, const char *);
34 int recv_cred_buffer(int, char *, size_t);
35 ssize_t send_cred_buffer(int, char*);
36 int recv_pattern(int fd, const char *pattern, size_t bufsize);
37 int init_tcp_socket(int port);
38 void enable_crypt(int fd, crypt_function *recv_f, crypt_function *send_f,
40 void disable_crypt(int fd);
43 * A wrapper around connect(2).
45 * \param fd The file descriptor.
46 * \param addr The address to connect.
47 * \param len The size of \a addr.
49 * This should not be called directly. Always use the PARA_CONNECT macro.
51 * \return \p -E_CONNECT on errors, 1 on success.
53 * \sa connect(2), PARA_CONNECT.
55 static inline int _para_connect(int fd, void *addr, socklen_t len)
57 if (connect(fd, (struct sockaddr *)addr, len) == -1)
62 /** A macro for connect() which does not need a \a len parameter. */
63 #define PARA_CONNECT(fd, addr) _para_connect(fd, addr, sizeof(*(addr)))