]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - net.h
Introduce tcp_connect().
[paraslash.git] / net.h
diff --git a/net.h b/net.h
index 1695504caa87408be9e8e53b08330a6bc1c721f0..6613d3f93d606cfe2daa81323298c86cefb670f7 100644 (file)
--- a/net.h
+++ b/net.h
 typedef void crypt_function(unsigned long len,
        const unsigned char *indata, unsigned char *outdata, void *private_data);
 
-#include <netdb.h> /* hostent */
-int get_host_info(char *host, struct hostent **ret);
-int get_socket(void);
-void init_sockaddr(struct sockaddr_in*, int, const struct hostent*);
-int para_connect(int, struct sockaddr_in *);
+int tcp_connect(char *host, int port);
+int get_stream_socket(int domain);
 int send_buffer(int, const char *);
 int send_bin_buffer(int, const char *, size_t);
 __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...);
@@ -42,3 +39,25 @@ void enable_crypt(int fd, crypt_function *recv_f, crypt_function *send_f,
        void *private_data);
 void disable_crypt(int fd);
 
+/**
+ * A wrapper around connect(2).
+ *
+ * \param fd The file descriptor.
+ * \param addr The address to connect.
+ * \param len The size of \a addr.
+ *
+ * This should not be called directly. Always use the PARA_CONNECT macro.
+ *
+ * \return \p -E_CONNECT on errors, 1 on success.
+ *
+ * \sa connect(2), PARA_CONNECT.
+ */
+static inline int _para_connect(int fd, void *addr, socklen_t len)
+{
+       if (connect(fd, (struct sockaddr *)addr, len) == -1)
+               return -E_CONNECT;
+       return 1;
+}
+
+/** A macro for connect() which does not need a \a len parameter. */
+#define PARA_CONNECT(fd, addr) _para_connect(fd, addr, sizeof(*(addr)))