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