/* Connects to the peer and returns a socket
* descriptor.
*/
-static int tcp_connect(void)
+static int _tcp_connect_eagain(void)
{
const char *PORT = getenv("PORT");
const char *SERVER = "127.0.0.1"; //verisign.com
gnutls_server_name_set(session, GNUTLS_NAME_DNS,
"localhost", strlen("localhost"));
- sd = tcp_connect();
+ sd = _tcp_connect_eagain();
/* associate gnutls with socket */
gnutls_transport_set_int(session, sd);
#ifndef _WIN32
#include <netinet/in.h>
#include <sys/socket.h>
+#include <arpa/inet.h>
#else
#include <windows.h> /* for Sleep */
#include <winbase.h>
p = next;
}
}
+
+
+#ifndef _WIN32
+int tcp_connect(const char* addr, unsigned port)
+{
+ int sock;
+ struct sockaddr_in sa = {0};
+ memset(&sa, 0, sizeof(sa));
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock == -1)
+ return -1;
+ sa.sin_family = AF_INET;
+ sa.sin_port = htons(port);
+ if (inet_pton(AF_INET, addr, &sa.sin_addr) != 1)
+ return -1;
+ if (connect(sock, (struct sockaddr*) &sa, sizeof(sa)) != 0)
+ return -1;
+ return sock;
+}
+#endif
void track_temp_files(void);
void delete_temp_files(void);
+int tcp_connect(const char* addr, unsigned port);
+
/* This must be implemented elsewhere. */
extern void doit(void);