CURLcode Curl_connecthost(struct connectdata *conn,
long timeout_ms,
+ Curl_addrinfo *remotehost,
+ int port,
int sockfd, /* input socket, or -1 if none */
int *socket)
{
/* 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;
* 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);
/* 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;
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 */
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
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);
*************************************************************/
return Curl_connecthost(conn,
max_time,
+ conn->hostaddr,
+ conn->port,
conn->firstsocket, /* might be bind()ed */
&conn->firstsocket);
}
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;
}
#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