aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/connect.c37
-rw-r--r--lib/connect.h2
-rw-r--r--lib/url.c22
3 files changed, 40 insertions, 21 deletions
diff --git a/lib/connect.c b/lib/connect.c
index e4fd94815..34dd72c28 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -160,6 +160,8 @@ int waitconnect(int sockfd, /* socket */
CURLcode Curl_connecthost(struct connectdata *conn,
long timeout_ms,
+ Curl_addrinfo *remotehost,
+ int port,
int sockfd, /* input socket, or -1 if none */
int *socket)
{
@@ -177,7 +179,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,
/* don't use any previous one, it might be of wrong type */
sclose(sockfd);
sockfd = -1; /* none! */
- for (ai = conn->hp; ai; ai = ai->ai_next) {
+ for (ai = remotehost; ai; ai = ai->ai_next) {
sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sockfd < 0)
continue;
@@ -219,6 +221,14 @@ CURLcode Curl_connecthost(struct connectdata *conn,
* Connecting with IPv4-only support
*/
int aliasindex;
+ struct sockaddr_in serv_addr;
+
+ if(-1 == sockfd)
+ /* create an ordinary socket if none was provided */
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+ if(-1 == sockfd)
+ return CURLE_COULDNT_CONNECT; /* big time error */
/* non-block socket */
nonblock(sockfd, TRUE);
@@ -226,20 +236,20 @@ CURLcode Curl_connecthost(struct connectdata *conn,
/* This is the loop that attempts to connect to all IP-addresses we
know for the given host. One by one. */
for(rc=-1, aliasindex=0;
- rc && (struct in_addr *)conn->hp->h_addr_list[aliasindex];
+ rc && (struct in_addr *)remotehost->h_addr_list[aliasindex];
aliasindex++) {
/* copy this particular name info to the conn struct as it might
be used later in the krb4 "system" */
- memset((char *) &conn->serv_addr, '\0', sizeof(conn->serv_addr));
- memcpy((char *)&(conn->serv_addr.sin_addr),
- (struct in_addr *)conn->hp->h_addr_list[aliasindex],
+ memset((char *) &serv_addr, '\0', sizeof(serv_addr));
+ memcpy((char *)&(serv_addr.sin_addr),
+ (struct in_addr *)remotehost->h_addr_list[aliasindex],
sizeof(struct in_addr));
- conn->serv_addr.sin_family = conn->hp->h_addrtype;
- conn->serv_addr.sin_port = htons(conn->port);
+ serv_addr.sin_family = remotehost->h_addrtype;
+ serv_addr.sin_port = htons(port);
- rc = connect(sockfd, (struct sockaddr *)&(conn->serv_addr),
- sizeof(conn->serv_addr));
+ rc = connect(sockfd, (struct sockaddr *)&serv_addr,
+ sizeof(serv_addr));
if(-1 == rc) {
int error;
@@ -275,8 +285,13 @@ CURLcode Curl_connecthost(struct connectdata *conn,
before = after;
continue; /* try next address */
}
- else
- break;
+ else {
+ /* copy this particular name info to the conn struct as it might
+ be used later in the krb4 "system" */
+ memcpy((char *) &conn->serv_addr, &serv_addr,
+ sizeof(conn->serv_addr));
+ }
+ break;
}
if(-1 == rc) {
/* no good connect was made */
diff --git a/lib/connect.h b/lib/connect.h
index 40df23cc3..a0e3f068d 100644
--- a/lib/connect.h
+++ b/lib/connect.h
@@ -25,6 +25,8 @@
CURLcode Curl_connecthost(struct connectdata *conn,
long timeout, /* milliseconds */
+ Curl_addrinfo *host, /* connect to this */
+ long port, /* connect to this port number */
int sockfd, /* input socket, or -1 if none */
int *socket); /* not set if error is returned */
#endif
diff --git a/lib/url.c b/lib/url.c
index ec0e5110d..810c387a7 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -880,8 +880,8 @@ CURLcode Curl_disconnect(struct connectdata *conn)
free(conn->proto.generic);
#ifdef ENABLE_IPV6
- if(conn->hp) /* host name info */
- freeaddrinfo(conn->hp);
+ if(conn->hostaddr) /* host name info */
+ freeaddrinfo(conn->hostaddr);
#else
if(conn->hostent_buf) /* host name info */
free(conn->hostent_buf);
@@ -1276,6 +1276,8 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
*************************************************************/
return Curl_connecthost(conn,
max_time,
+ conn->hostaddr,
+ conn->port,
conn->firstsocket, /* might be bind()ed */
&conn->firstsocket);
}
@@ -2086,26 +2088,26 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->port = conn->remote_port; /* it is the same port */
/* Resolve target host right on */
- if(!conn->hp) {
+ if(!conn->hostaddr) {
/* it might already be set if reusing a connection */
- conn->hp = Curl_getaddrinfo(data, conn->name, conn->port,
+ conn->hostaddr = Curl_getaddrinfo(data, conn->name, conn->port,
&conn->hostent_buf);
}
- if(!conn->hp) {
+ if(!conn->hostaddr) {
failf(data, "Couldn't resolve host '%s'", conn->name);
return CURLE_COULDNT_RESOLVE_HOST;
}
}
- else if(!conn->hp) {
+ else if(!conn->hostaddr) {
/* This is a proxy that hasn't been resolved yet. It may be resolved
if we're reusing an existing connection. */
/* resolve proxy */
/* it might already be set if reusing a connection */
- conn->hp = Curl_getaddrinfo(data, conn->proxyhost, conn->port,
+ conn->hostaddr = Curl_getaddrinfo(data, conn->proxyhost, conn->port,
&conn->hostent_buf);
- if(!conn->hp) {
+ if(!conn->hostaddr) {
failf(data, "Couldn't resolve proxy '%s'", conn->proxyhost);
return CURLE_COULDNT_RESOLVE_PROXY;
}
@@ -2195,8 +2197,8 @@ static CURLcode CreateConnection(struct SessionHandle *data,
#else
{
struct in_addr in;
- (void) memcpy(&in.s_addr, *conn->hp->h_addr_list, sizeof (in.s_addr));
- infof(data, "Connected to %s (%s)\n", conn->hp->h_name, inet_ntoa(in));
+ (void) memcpy(&in.s_addr, *conn->hostaddr->h_addr_list, sizeof (in.s_addr));
+ infof(data, "Connected to %s (%s)\n", conn->hostaddr->h_name, inet_ntoa(in));
}
#endif