1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_LASTSOCKET 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_ACTIVESOCKET (3) 9 - CURLOPT_CONNECT_ONLY (3) 10 - curl_easy_getinfo (3) 11 - curl_easy_setopt (3) 12Protocol: 13 - All 14Added-in: 7.15.2 15--- 16 17# NAME 18 19CURLINFO_LASTSOCKET - get the last socket used 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LASTSOCKET, long *socket); 27~~~ 28 29# DESCRIPTION 30 31Deprecated since 7.45.0. Use CURLINFO_ACTIVESOCKET(3) instead. 32 33Pass a pointer to a long to receive the last socket used by this curl 34session. If the socket is no longer valid, -1 is returned. When you finish 35working with the socket, you must call curl_easy_cleanup(3) as usual and 36let libcurl close the socket and cleanup other resources associated with the 37handle. This is typically used in combination with 38CURLOPT_CONNECT_ONLY(3). 39 40NOTE: this API is deprecated since it is not working on win64 where the SOCKET 41type is 64 bits large while its 'long' is 32 bits. Use the 42CURLINFO_ACTIVESOCKET(3) instead, if possible. 43 44# %PROTOCOLS% 45 46# EXAMPLE 47 48~~~c 49int main(void) 50{ 51 CURL *curl = curl_easy_init(); 52 if(curl) { 53 CURLcode res; 54 long sockfd; /* does not work on win64 */ 55 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 56 57 /* Do not do the transfer - only connect to host */ 58 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); 59 res = curl_easy_perform(curl); 60 if(res != CURLE_OK) { 61 printf("Error: %s\n", curl_easy_strerror(res)); 62 curl_easy_cleanup(curl); 63 return 1; 64 } 65 66 /* Extract the socket from the curl handle */ 67 res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd); 68 if(!res && sockfd != -1) { 69 /* operate on sockfd */ 70 } 71 72 curl_easy_cleanup(curl); 73 } 74} 75~~~ 76 77# %AVAILABILITY% 78 79# RETURN VALUE 80 81Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 82