1CURLINFO_LASTSOCKET(3) curl_easy_getinfo options CURLINFO_LASTSOCKET(3)
2
3
4
6 CURLINFO_LASTSOCKET - get the last socket used
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LASTSOCKET, long *socket);
12
14 Deprecated since 7.45.0. Use CURLINFO_ACTIVESOCKET(3) instead.
15
16 Pass a pointer to a long to receive the last socket used by this curl
17 session. If the socket is no longer valid, -1 is returned. When you
18 finish working with the socket, you must call curl_easy_cleanup() as
19 usual and let libcurl close the socket and cleanup other resources as‐
20 sociated with the handle. This is typically used in combination with
21 CURLOPT_CONNECT_ONLY(3).
22
23 NOTE: this API is deprecated since it is not working on win64 where the
24 SOCKET type is 64 bits large while its 'long' is 32 bits. Use the
25 CURLINFO_ACTIVESOCKET(3) instead, if possible.
26
28 All
29
31 CURL *curl = curl_easy_init();
32 if(curl) {
33 long sockfd; /* does not work on win64! */
34 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
35
36 /* Do not do the transfer - only connect to host */
37 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
38 res = curl_easy_perform(curl);
39
40 /* Extract the socket from the curl handle */
41 res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
42
43 if(res != CURLE_OK) {
44 printf("Error: %s\n", curl_easy_strerror(res));
45 return 1;
46 }
47 }
48
50 Added in 7.15.2
51
53 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION
54 if not.
55
57 curl_easy_getinfo(3), curl_easy_setopt(3), CURLINFO_ACTIVESOCKET(3),
58
59
60
61libcurl 8.0.1 January 02, 2023 CURLINFO_LASTSOCKET(3)