Daniel Stenberg wrote:
> So can you provide us with a full example source code to a
> small app that seems to show this problem for you?

My sequence of steps listed in my first email didn't actually match my
code.  Step 6 should have said: Do 'connect only", then do HTTP GET
using socket I/O.

Here's a very stripped down example that will always fail the 2nd time
through the loop and send the hello.txt GET to the wrong IP.  IP
addresses are hard coded just to eliminate DNS caching as a contributor
to the problem.  The getpeername() call is set for Windows; I believe
the arg type differs for Linux?  Or you can just delete the
getpeername() block and just use a net sniffer to see the hello.txt GET
going to the wrong IP.

Tested in Windows 2003 Server in curl 7.19.2 and 7.19.4.

#include <assert.h>
#include <stdio.h>
#include <curl.h>

int main()
{
    CURLcode curlRes;

    curl_global_init(CURL_GLOBAL_ALL);
    CURL* curl = curl_easy_init();

    int i;
    for (i = 0; i < 2; i++)
    {
        printf("* 1 **************\n");
        curl_easy_reset(curl);
        curl_easy_setopt(curl, CURLOPT_URL, "http://74.125.67.100";);
// http://google.com

        curlRes = curl_easy_perform(curl);
        assert(curlRes == CURLE_OK);

        printf("* #2 **************\n");
        curl_easy_reset(curl);
        curl_easy_setopt(curl, CURLOPT_URL, "http://206.190.60.37";);
//http://yahoo.com
        curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);

        curlRes = curl_easy_perform(curl);
        assert(curlRes == CURLE_OK);

        // ask curl for IP address
        char* ip1;
        curlRes = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip1);
        assert(curlRes == CURLE_OK);
        
        // get raw socket handle
        int sockfd;
        curlRes = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
        assert(curlRes == CURLE_OK);

        // ask socket for IP address
        sockaddr sockad;
        int len = sizeof(sockad);
        int rc = getpeername(sockfd, &sockad, &len);
        char ip2[20];
        sprintf(ip2, "%u.%u.%u.%u", (unsigned char)sockad.sa_data[2],
(unsigned char)sockad.sa_data[3], (unsigned char)sockad.sa_data[4],
(unsigned char)sockad.sa_data[5] );

        // Send HTTP GET request. 
        const char* request = "GET /hello.txt HTTP/1.1\r\nHost:
206.190.60.37\r\n\r\n";         // http://yahoo.com
        size_t sentCount = 0;
        curlRes = curl_easy_send(curl, request, strlen(request),
&sentCount);
        assert(sentCount == strlen(request));
        assert(curlRes == CURLE_OK);

        if (strcmp(ip1, ip2))
        {
            printf("FAILED.  getpeername() returns %s, but
CURLINFO_PRIMARY_IP returns %s\n", ip2, ip1);
            break;
        }
    }
    if (i == 2)
        printf("SUCCESS\n");

    curl_easy_cleanup(curl);
    curl_global_cleanup();
    return 0;
}

-Jim
___________________________________________________________________

This electronic mail message, including any attachments or embedded documents, 
is intended 
only for the addressee and may contain privileged and/or confidential 
information. Unless 
expressly indicated, this electronic mail message is confidential and 
privileged information 
of Nirvanix, Inc. Any use, dissemination, copying or distribution in any form, 
and any action 
taken based up this email is strictly prohibited unless expressly indicated. If 
you have 
received this message by error, please immediately delete it and any copies of 
it, including 
any attachments hereto, and notify the sender at Nirvanix, Inc. by reply 
electronic mail 
message or phone. Thank you.


Reply via email to