1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_ACTIVESOCKET 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_LASTSOCKET (3) 9 - CURLOPT_CONNECT_ONLY (3) 10 - curl_easy_getinfo (3) 11 - curl_easy_setopt (3) 12--- 13 14# NAME 15 16CURLINFO_ACTIVESOCKET - get the active socket 17 18# SYNOPSIS 19 20~~~c 21#include <curl/curl.h> 22 23CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_ACTIVESOCKET, 24 curl_socket_t *socket); 25~~~ 26 27# DESCRIPTION 28 29Pass a pointer to a curl_socket_t to receive the most recently active socket 30used for the transfer connection by this curl session. If the socket is no 31longer valid, *CURL_SOCKET_BAD* is returned. When you are finished working 32with the socket, you must call curl_easy_cleanup(3) as usual on the easy 33handle and let libcurl close the socket and cleanup other resources associated 34with the handle. This option returns the active socket only after the transfer 35is complete, and is typically used in combination with 36CURLOPT_CONNECT_ONLY(3), which skips the transfer phase. 37 38CURLINFO_ACTIVESOCKET(3) was added as a replacement for 39CURLINFO_LASTSOCKET(3) since that one is not working on all platforms. 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 curl_socket_t sockfd; 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_ACTIVESOCKET, &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.45.0 74 75# RETURN VALUE 76 77Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 78