summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexander Sosedkin <asosedkin@redhat.com>2021-11-11 14:04:54 +0100
committerAlexander Sosedkin <asosedkin@redhat.com>2021-12-09 17:08:33 +0100
commit93d337b3b5471f95316cfd4bb3b02e3c02168a64 (patch)
treee27456ed13b2a27c9e1d125297593353e3c799e4 /tests
parent29eee975a62400231db28e3d0e0a53414e795ebd (diff)
downloadgnutls-93d337b3b5471f95316cfd4bb3b02e3c02168a64.tar.gz
tests: add tcp_connect to utils
Signed-off-by: Alexander Sosedkin <asosedkin@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/suite/eagain-cli.c4
-rw-r--r--tests/utils.c21
-rw-r--r--tests/utils.h2
3 files changed, 25 insertions, 2 deletions
diff --git a/tests/suite/eagain-cli.c b/tests/suite/eagain-cli.c
index cdd9ab7589..a79c722064 100644
--- a/tests/suite/eagain-cli.c
+++ b/tests/suite/eagain-cli.c
@@ -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);
diff --git a/tests/utils.c b/tests/utils.c
index 60cd79b359..b6899e2603 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -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
diff --git a/tests/utils.h b/tests/utils.h
index 3d8dcb7770..8efe9d299f 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -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);