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