From 5da62fb671474b1ffaad5dd3062895ca109c47bf Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 26 Nov 2012 19:42:10 +0100 Subject: [PATCH] gnutls-cli will try to cannot to all possible returned addresses. --- src/cli.c | 2 -- src/ocsptool-common.c | 1 - src/socket.c | 58 +++++++++++++++++++++++---------------------------- src/socket.h | 1 - 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/cli.c b/src/cli.c index 95fe8e0ce..142c8831d 100644 --- a/src/cli.c +++ b/src/cli.c @@ -843,7 +843,6 @@ main (int argc, char **argv) init_global_tls_stuff (); socket_open (&hd, hostname, service, udp); - socket_connect (&hd); hd.session = init_tls_session (hostname); if (starttls) @@ -897,7 +896,6 @@ main (int argc, char **argv) printf ("\n\n- Connecting again- trying to resume previous session\n"); socket_open (&hd, hostname, service, udp); - socket_connect (&hd); } else { diff --git a/src/ocsptool-common.c b/src/ocsptool-common.c index 835ccbfc2..5aa265d5b 100644 --- a/src/ocsptool-common.c +++ b/src/ocsptool-common.c @@ -191,7 +191,6 @@ socket_st hd; headers_size = strlen(headers); socket_open(&hd, hostname, service, 0); - socket_connect (&hd); socket_send(&hd, headers, headers_size); socket_send(&hd, req.data, req.size); diff --git a/src/socket.c b/src/socket.c index c50488528..f90148213 100644 --- a/src/socket.c +++ b/src/socket.c @@ -126,22 +126,6 @@ socket_bye (socket_st * socket) } void -socket_connect (const socket_st * hd) -{ - int err; - - printf ("Connecting to '%s:%s'...\n", hd->ip, hd->service); - - err = connect (hd->fd, hd->ptr->ai_addr, hd->ptr->ai_addrlen); - if (err < 0) - { - fprintf (stderr, "Cannot connect to %s:%s: %s\n", hd->hostname, - hd->service, strerror (errno)); - exit (1); - } -} - -void socket_open (socket_st * hd, const char *hostname, const char *service, int udp) { struct addrinfo hints, *res, *ptr; @@ -176,30 +160,40 @@ socket_open (socket_st * hd, const char *hostname, const char *service, int udp) exit (1); } + if (hints.ai_socktype == SOCK_DGRAM) + { +#if defined(IP_DONTFRAG) + int yes = 1; + if (setsockopt (sd, IPPROTO_IP, IP_DONTFRAG, + (const void *) &yes, sizeof (yes)) < 0) + perror ("setsockopt(IP_DF) failed"); +#elif defined(IP_MTU_DISCOVER) + int yes = IP_PMTUDISC_DO; + if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, + (const void*) &yes, sizeof (yes)) < 0) + perror ("setsockopt(IP_DF) failed"); +#endif + } + + + printf ("Connecting to '%s:%s'...\n", hostname, portname); + + err = connect (sd, ptr->ai_addr, ptr->ai_addrlen); + if (err < 0) + { + fprintf (stderr, "Cannot connect to %s:%s: %s\n", hostname, + portname, strerror (errno)); + exit (1); + } break; } if (sd == -1) { - fprintf (stderr, "socket(): %s\n", strerror (errno)); + fprintf (stderr, "Could not find a supported socket\n"); exit (1); } - if (hints.ai_socktype == SOCK_DGRAM) - { -#if defined(IP_DONTFRAG) - int yes = 1; - if (setsockopt (sd, IPPROTO_IP, IP_DONTFRAG, - (const void *) &yes, sizeof (yes)) < 0) - perror ("setsockopt(IP_DF) failed"); -#elif defined(IP_MTU_DISCOVER) - int yes = IP_PMTUDISC_DO; - if (setsockopt(sd, IPPROTO_IP, IP_MTU_DISCOVER, - (const void*) &yes, sizeof (yes)) < 0) - perror ("setsockopt(IP_DF) failed"); -#endif - } - hd->secure = 0; hd->fd = sd; hd->hostname = strdup (hostname); diff --git a/src/socket.h b/src/socket.h index 141bacb82..9f98faf45 100644 --- a/src/socket.h +++ b/src/socket.h @@ -16,7 +16,6 @@ ssize_t socket_recv (const socket_st * socket, void *buffer, int buffer_size); ssize_t socket_send (const socket_st * socket, const void *buffer, int buffer_size); void socket_open (socket_st * hd, const char *hostname, const char *service, int udp); -void socket_connect (const socket_st * hd); void socket_bye (socket_st * socket); void sockets_init (void); -- 2.11.4.GIT