]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: add tcp_connect to utils
authorAlexander Sosedkin <asosedkin@redhat.com>
Thu, 11 Nov 2021 13:04:54 +0000 (14:04 +0100)
committerAlexander Sosedkin <asosedkin@redhat.com>
Thu, 9 Dec 2021 16:08:33 +0000 (17:08 +0100)
Signed-off-by: Alexander Sosedkin <asosedkin@redhat.com>
tests/suite/eagain-cli.c
tests/utils.c
tests/utils.h

index cdd9ab7589bd0e1f735f2a7bf888898f1d3c1475..a79c7220644b3add38f8ebcd6d56274bb504c960 100644 (file)
@@ -50,7 +50,7 @@ static const char
 /* 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
@@ -222,7 +222,7 @@ static void try(const char *name, const char *prio)
                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);
index 60cd79b3596e7cc1f3be66c8300f562e264f46cb..b6899e2603ae2d798109e6c21b9b65495b72f9d7 100644 (file)
@@ -34,6 +34,7 @@
 #ifndef _WIN32
 #include <netinet/in.h>
 #include <sys/socket.h>
+#include <arpa/inet.h>
 #else
 #include <windows.h>           /* for Sleep */
 #include <winbase.h>
@@ -325,3 +326,23 @@ void delete_temp_files(void)
                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
index 3d8dcb7770ae5212e40254a776f22b653c7f5ce8..8efe9d299f2888f4a592c926b91ba4ea5f7f99a5 100644 (file)
@@ -147,6 +147,8 @@ char *get_tmpname(char s[TMPNAME_SIZE]);
 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);