summaryrefslogtreecommitdiff
path: root/src/tls_test.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2006-05-07 12:45:06 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2006-05-07 12:45:06 +0000
commit16b9dc43197e5e7b476d51d409e7c52654de0303 (patch)
tree1788ab300775b457a167aedd9f5812562e617d80 /src/tls_test.c
parent88b52b8f26b28cddab566fcdc5c6db1e82844e5d (diff)
downloadgnutls-16b9dc43197e5e7b476d51d409e7c52654de0303.tar.gz
some changes for IPv6. Based on patch by Remi Denis-Courmont, sent to Debian bug tracking system.
Diffstat (limited to 'src/tls_test.c')
-rw-r--r--src/tls_test.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/tls_test.c b/src/tls_test.c
index 43365ff876..8f06385610 100644
--- a/src/tls_test.c
+++ b/src/tls_test.c
@@ -155,18 +155,6 @@ static const TLS_TEST tls_tests[] = {
static int tt = 0;
const char *ip;
-#define CONNECT() \
- sd = socket(AF_INET, SOCK_STREAM, 0); \
- ERR(sd, "socket"); \
- memset(&sa, '\0', sizeof(sa)); \
- sa.sin_family = AF_INET; \
- sa.sin_port = htons(port); \
- sa.sin_addr.s_addr = *((unsigned int *) server_host->h_addr); \
- ip = inet_ntop(AF_INET, &sa.sin_addr, buffer, MAX_BUF); \
- if (tt++ == 0) printf("Connecting to '%s:%d'...\n", ip, port); \
- err = connect(sd, (SA *) & sa, sizeof(sa)); \
- ERR(err, "connect")
-
static void gaa_parser (int argc, char **argv);
int
@@ -174,10 +162,10 @@ main (int argc, char **argv)
{
int err, ret;
int sd, i;
- struct sockaddr_in sa;
gnutls_session state;
char buffer[MAX_BUF + 1];
- struct hostent *server_host;
+ char portname[6];
+ struct addrinfo hints, *res, *ptr;
gaa_parser (argc, argv);
@@ -204,10 +192,14 @@ main (int argc, char **argv)
printf ("Resolving '%s'...\n", hostname);
/* get server name */
- server_host = gethostbyname (hostname);
- if (server_host == NULL)
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_NUMERICSERV;
+ snprintf (portname, sizeof (portname), "%d", port);
+ if ((err = getaddrinfo (hostname, portname, &hints, &res)) != 0)
{
- fprintf (stderr, "Cannot resolve %s\n", hostname);
+ fprintf (stderr, "Cannot resolve %s: %s\n", hostname,
+ gai_strerror (err));
exit (1);
}
@@ -253,7 +245,27 @@ main (int argc, char **argv)
break;
}
- CONNECT ();
+ sd = -1;
+ for (ptr = res; ptr != NULL; ptr = ptr->ai_next)
+ {
+ sd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
+ if (sd == -1)
+ {
+ continue;
+ }
+
+ getnameinfo (ptr->ai_addr, ptr->ai_addrlen, buffer, MAX_BUF,
+ NULL, 0, NI_NUMERICHOST);
+ if (tt++ == 0) printf("Connecting to '%s:%d'...\n", buffer, port);
+ if ((err = connect(sd, ptr->ai_addr, ptr->ai_addrlen)) != 0)
+ {
+ close (sd);
+ sd = -1;
+ continue;
+ }
+ }
+ ERR(err, "connect")
+
gnutls_init (&state, GNUTLS_CLIENT);
gnutls_transport_set_ptr (state, (gnutls_transport_ptr) sd);
@@ -286,6 +298,8 @@ main (int argc, char **argv)
}
while (1);
+ freeaddrinfo (res);
+
#ifdef ENABLE_SRP
gnutls_srp_free_client_credentials (srp_cred);
#endif