Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURLINFO_LOCAL_IP and CURLINFO_LOCAL_PORT do not work on reused connections. #7660

Closed
maxdymond opened this issue Sep 2, 2021 · 2 comments
Closed

Comments

@maxdymond
Copy link
Contributor

@maxdymond maxdymond commented Sep 2, 2021

I did this

$ cat demo.c
#include <stdio.h>
#include <curl/curl.h>

int main()
{
  CURL *curl;
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
    curl_easy_perform(curl);
    curl_easy_perform(curl);

    {
      char *ip;
      long port;
      curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip);
      curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
      printf("We used local IP and port: %s : %ld\n", ip, port);
    }
    curl_easy_cleanup(curl);
  }
  return 0;
}

I expected the following

<website contents>
We used local IP and port: 172.19.45.229 : 43382

(I get this with my system library at 7.68)

What I actually get is:

<website contents>
We used local IP and port:  : -1

curl/libcurl version

master

operating system

Linux 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

@maxdymond
Copy link
Contributor Author

@maxdymond maxdymond commented Sep 2, 2021

According to git bisect this was regressed in d6a37c2 committed on the 27th Jan 2021.

@maxdymond
Copy link
Contributor Author

@maxdymond maxdymond commented Sep 2, 2021

Looks like the logic in Curl_updateconninfo was subtly changed in that commit to blank out the IP and port. Presumably before then the connection information wasn't being zeroed out.

bagder added a commit that referenced this issue Sep 2, 2021
In d6a37c2 (7.75.0) we removed the duplicated storage (connection +
easy handle), so this info needs be extract again even for re-used
connections.

Add test 435 to verify

Reported-by: Max Dymond
Fixes #7660
Closes #
@bagder bagder closed this in 424051d Sep 2, 2021
jbrownsw added a commit to jbrownsw/curl that referenced this issue Sep 3, 2021
Regression. In d6a37c2 (7.75.0) we removed the duplicated storage
(connection + easy handle), so this info needs be extracted again even
for re-used connections.

Add test 435 to verify

Reported-by: Max Dymond
Fixes curl#7660
Closes curl#7662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant