diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-11-26 19:42:10 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2012-11-26 19:42:10 +0100 |
commit | 5da62fb671474b1ffaad5dd3062895ca109c47bf (patch) | |
tree | fdb543f40ee1fcd8ce9b57bf2f4eda5e234a6df0 /src | |
parent | eec31cce141049544a512c8e55211f434c691820 (diff) | |
download | gnutls-5da62fb671474b1ffaad5dd3062895ca109c47bf.tar.gz |
gnutls-cli will try to cannot to all possible returned addresses.
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.c | 2 | ||||
-rw-r--r-- | src/ocsptool-common.c | 1 | ||||
-rw-r--r-- | src/socket.c | 58 | ||||
-rw-r--r-- | src/socket.h | 1 |
4 files changed, 26 insertions, 36 deletions
@@ -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 835ccbfc2b..5aa265d5b2 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 c50488528d..f90148213b 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 141bacb829..9f98faf458 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); |