cURL / Mailing Lists / curl-users / Single Mail

curl-users

[ curl-Bugs-815696 ] Connect problem to server with multiple IP addresses from DN

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Wed, 01 Oct 2003 01:23:26 -0700

Bugs item #815696, was opened at 2003-10-01 08:23
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=815696&group_id=976

Category: libcurl
Group: bad behaviour
Status: Open
Resolution: None
Priority: 5
Submitted By: Frank Ticheler (fticheler)
Assigned to: Daniel Stenberg (bagder)
Summary: Connect problem to server with multiple IP addresses from DN

Initial Comment:
The problem appears when connecting to a hostname,

from which the DNS returns more than one IP address.

Well, normally this is not a problem, but with a particular

server, one of the IP addresses did not respond at all.

So to that address no connection was possible.

We're using curl-7.10.8-pre1 (--enabled-ares), running

on Compaq Alpha 4.0f (OSF1 hostname V4.0 1229 alpha).

What is happening:

- gethostbyname for a hostname results in let's say IP1

and IP2.

- calling socket returns a file descriptor fd.

- connect uses this fd to connect to IP1.

- IP1 is not reachable and connect returns an error. (in

fact, waitconnect returns 0 but socketerror returns 60,

ETIMEDOUT)

- connect is called again, using the same fd.

- connect fails, with errno EINVAL on IP2.

- no connection is established.

If IP2 is returned first from the DNS, everything works

just fine as then the connection is made to IP2.

Refering to Richard Stevens's Unix Network Programming,

Vol. 1, 2nd Edition, Section 4.3, Connect function/ 11.8,

TCP Connect function, it is stated there that the socket

is not longer usable if the connect fails. This means that

the socket fd needs to be closed and that socket needs

to be called again.

We made changes to the file lib/connect.c. What we did

is moving the socket call into the for loop and close the

socket after an unsuccessfull connect.

As we use the ares library with Curl, we do not have

IPV6 enabled. The IPV6 code already has the socket call

inside the for-loop.

> diff connect.c.ORG connect.c.CHANGED

612,617d611

< /* create an IPv4 TCP socket */

< sockfd = socket(AF_INET, SOCK_STREAM, 0);

< if(-1 == sockfd) {

< failf(data, "couldn't create socket");

< return CURLE_COULDNT_CONNECT; /* big time error

*/

< }

619,629d612

< if(conn->data->set.device) {

< /* user selected to bind the outgoing socket to a

specified "device"

< before doing connect */

< CURLcode res = bindlocal(conn, sockfd);

< if(res)

< return res;

< }

<

< /* Convert socket to non-blocking type */

< Curl_nonblock(sockfd, TRUE);

<

635a619,625

>

> /* create an IPv4 TCP socket */

> sockfd = socket(AF_INET, SOCK_STREAM, 0);

> if(-1 == sockfd) {

> failf(data, "couldn't create socket");

> return CURLE_COULDNT_CONNECT; /* big time

error */

> }

636a627,637

> if(conn->data->set.device) {

> /* user selected to bind the outgoing socket to a

specified "device"

> before doing connect */

> CURLcode res = bindlocal(conn, sockfd);

> if(res)

> return res;

> }

>

> /* Convert socket to non-blocking type */

> Curl_nonblock(sockfd, TRUE);

>

693a695

> sclose(sockfd);

704a707

> sclose(sockfd);

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=815696&group_id=976

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-10-01