mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
conn->hp is now conn->hostaddr
changed the Curl_connethost() proto again
This commit is contained in:
parent
9d342bbf07
commit
6918427fae
@ -160,6 +160,8 @@ int waitconnect(int sockfd, /* socket */
|
|||||||
|
|
||||||
CURLcode Curl_connecthost(struct connectdata *conn,
|
CURLcode Curl_connecthost(struct connectdata *conn,
|
||||||
long timeout_ms,
|
long timeout_ms,
|
||||||
|
Curl_addrinfo *remotehost,
|
||||||
|
int port,
|
||||||
int sockfd, /* input socket, or -1 if none */
|
int sockfd, /* input socket, or -1 if none */
|
||||||
int *socket)
|
int *socket)
|
||||||
{
|
{
|
||||||
@ -177,7 +179,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,
|
|||||||
/* don't use any previous one, it might be of wrong type */
|
/* don't use any previous one, it might be of wrong type */
|
||||||
sclose(sockfd);
|
sclose(sockfd);
|
||||||
sockfd = -1; /* none! */
|
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);
|
sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||||
if (sockfd < 0)
|
if (sockfd < 0)
|
||||||
continue;
|
continue;
|
||||||
@ -219,6 +221,14 @@ CURLcode Curl_connecthost(struct connectdata *conn,
|
|||||||
* Connecting with IPv4-only support
|
* Connecting with IPv4-only support
|
||||||
*/
|
*/
|
||||||
int aliasindex;
|
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 */
|
/* non-block socket */
|
||||||
nonblock(sockfd, TRUE);
|
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
|
/* This is the loop that attempts to connect to all IP-addresses we
|
||||||
know for the given host. One by one. */
|
know for the given host. One by one. */
|
||||||
for(rc=-1, aliasindex=0;
|
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++) {
|
aliasindex++) {
|
||||||
|
|
||||||
/* copy this particular name info to the conn struct as it might
|
/* copy this particular name info to the conn struct as it might
|
||||||
be used later in the krb4 "system" */
|
be used later in the krb4 "system" */
|
||||||
memset((char *) &conn->serv_addr, '\0', sizeof(conn->serv_addr));
|
memset((char *) &serv_addr, '\0', sizeof(serv_addr));
|
||||||
memcpy((char *)&(conn->serv_addr.sin_addr),
|
memcpy((char *)&(serv_addr.sin_addr),
|
||||||
(struct in_addr *)conn->hp->h_addr_list[aliasindex],
|
(struct in_addr *)remotehost->h_addr_list[aliasindex],
|
||||||
sizeof(struct in_addr));
|
sizeof(struct in_addr));
|
||||||
conn->serv_addr.sin_family = conn->hp->h_addrtype;
|
serv_addr.sin_family = remotehost->h_addrtype;
|
||||||
conn->serv_addr.sin_port = htons(conn->port);
|
serv_addr.sin_port = htons(port);
|
||||||
|
|
||||||
rc = connect(sockfd, (struct sockaddr *)&(conn->serv_addr),
|
rc = connect(sockfd, (struct sockaddr *)&serv_addr,
|
||||||
sizeof(conn->serv_addr));
|
sizeof(serv_addr));
|
||||||
|
|
||||||
if(-1 == rc) {
|
if(-1 == rc) {
|
||||||
int error;
|
int error;
|
||||||
@ -275,8 +285,13 @@ CURLcode Curl_connecthost(struct connectdata *conn,
|
|||||||
before = after;
|
before = after;
|
||||||
continue; /* try next address */
|
continue; /* try next address */
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
break;
|
/* 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) {
|
if(-1 == rc) {
|
||||||
/* no good connect was made */
|
/* no good connect was made */
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
CURLcode Curl_connecthost(struct connectdata *conn,
|
CURLcode Curl_connecthost(struct connectdata *conn,
|
||||||
long timeout, /* milliseconds */
|
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 sockfd, /* input socket, or -1 if none */
|
||||||
int *socket); /* not set if error is returned */
|
int *socket); /* not set if error is returned */
|
||||||
#endif
|
#endif
|
||||||
|
22
lib/url.c
22
lib/url.c
@ -880,8 +880,8 @@ CURLcode Curl_disconnect(struct connectdata *conn)
|
|||||||
free(conn->proto.generic);
|
free(conn->proto.generic);
|
||||||
|
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
if(conn->hp) /* host name info */
|
if(conn->hostaddr) /* host name info */
|
||||||
freeaddrinfo(conn->hp);
|
freeaddrinfo(conn->hostaddr);
|
||||||
#else
|
#else
|
||||||
if(conn->hostent_buf) /* host name info */
|
if(conn->hostent_buf) /* host name info */
|
||||||
free(conn->hostent_buf);
|
free(conn->hostent_buf);
|
||||||
@ -1276,6 +1276,8 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
|
|||||||
*************************************************************/
|
*************************************************************/
|
||||||
return Curl_connecthost(conn,
|
return Curl_connecthost(conn,
|
||||||
max_time,
|
max_time,
|
||||||
|
conn->hostaddr,
|
||||||
|
conn->port,
|
||||||
conn->firstsocket, /* might be bind()ed */
|
conn->firstsocket, /* might be bind()ed */
|
||||||
&conn->firstsocket);
|
&conn->firstsocket);
|
||||||
}
|
}
|
||||||
@ -2086,26 +2088,26 @@ static CURLcode CreateConnection(struct SessionHandle *data,
|
|||||||
conn->port = conn->remote_port; /* it is the same port */
|
conn->port = conn->remote_port; /* it is the same port */
|
||||||
|
|
||||||
/* Resolve target host right on */
|
/* Resolve target host right on */
|
||||||
if(!conn->hp) {
|
if(!conn->hostaddr) {
|
||||||
/* it might already be set if reusing a connection */
|
/* 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);
|
&conn->hostent_buf);
|
||||||
}
|
}
|
||||||
if(!conn->hp) {
|
if(!conn->hostaddr) {
|
||||||
failf(data, "Couldn't resolve host '%s'", conn->name);
|
failf(data, "Couldn't resolve host '%s'", conn->name);
|
||||||
return CURLE_COULDNT_RESOLVE_HOST;
|
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
|
/* This is a proxy that hasn't been resolved yet. It may be resolved
|
||||||
if we're reusing an existing connection. */
|
if we're reusing an existing connection. */
|
||||||
|
|
||||||
/* resolve proxy */
|
/* resolve proxy */
|
||||||
/* it might already be set if reusing a connection */
|
/* 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);
|
&conn->hostent_buf);
|
||||||
|
|
||||||
if(!conn->hp) {
|
if(!conn->hostaddr) {
|
||||||
failf(data, "Couldn't resolve proxy '%s'", conn->proxyhost);
|
failf(data, "Couldn't resolve proxy '%s'", conn->proxyhost);
|
||||||
return CURLE_COULDNT_RESOLVE_PROXY;
|
return CURLE_COULDNT_RESOLVE_PROXY;
|
||||||
}
|
}
|
||||||
@ -2195,8 +2197,8 @@ static CURLcode CreateConnection(struct SessionHandle *data,
|
|||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
(void) memcpy(&in.s_addr, *conn->hp->h_addr_list, sizeof (in.s_addr));
|
(void) memcpy(&in.s_addr, *conn->hostaddr->h_addr_list, sizeof (in.s_addr));
|
||||||
infof(data, "Connected to %s (%s)\n", conn->hp->h_name, inet_ntoa(in));
|
infof(data, "Connected to %s (%s)\n", conn->hostaddr->h_name, inet_ntoa(in));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user