CURLINFO_PRIMARY_PORT.3 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. .\" generated by cd2nroff 0.1 from CURLINFO_PRIMARY_PORT.md
  2. .TH CURLINFO_PRIMARY_PORT 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_PRIMARY_PORT \- get the latest destination port number
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_PORT, long *portp);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a pointer to a long to receive the destination port of the most recent
  12. connection done with this \fBcurl\fP handle.
  13. This is the destination port of the actual TCP or UDP connection libcurl used.
  14. If a proxy was used for the most recent transfer, this is the port number of
  15. the proxy, if no proxy was used it is the port number of the most recently
  16. accessed URL.
  17. .SH PROTOCOLS
  18. This functionality affects all supported protocols
  19. .SH EXAMPLE
  20. .nf
  21. int main(void)
  22. {
  23. CURL *curl = curl_easy_init();
  24. if(curl) {
  25. CURLcode res;
  26. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  27. res = curl_easy_perform(curl);
  28. if(res == CURLE_OK) {
  29. long port;
  30. res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
  31. if(!res)
  32. printf("Connected to remote port: %ld\\n", port);
  33. }
  34. curl_easy_cleanup(curl);
  35. }
  36. }
  37. .fi
  38. .SH AVAILABILITY
  39. Added in curl 7.21.0
  40. .SH RETURN VALUE
  41. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  42. .SH SEE ALSO
  43. .BR CURLINFO_LOCAL_PORT (3),
  44. .BR CURLINFO_PRIMARY_IP (3),
  45. .BR curl_easy_getinfo (3),
  46. .BR curl_easy_setopt (3)