CURLOPT_PREREQDATA.md (1528B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_PREREQDATA 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_PRIMARY_IP (3) 9 - CURLINFO_PRIMARY_PORT (3) 10 - CURLOPT_PREREQFUNCTION (3) 11 Protocol: 12 - All 13 Added-in: 7.80.0 14 --- 15 16 # NAME 17 18 CURLOPT_PREREQDATA - pointer passed to the pre-request callback 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, void *pointer); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a *pointer* that is untouched by libcurl and passed as the first 31 argument in the pre-request callback set with CURLOPT_PREREQFUNCTION(3). 32 33 # DEFAULT 34 35 NULL 36 37 # %PROTOCOLS% 38 39 # EXAMPLE 40 41 ~~~c 42 struct priv { 43 void *custom; 44 }; 45 46 static int prereq_callback(void *clientp, 47 char *conn_primary_ip, 48 char *conn_local_ip, 49 int conn_primary_port, 50 int conn_local_port) 51 { 52 printf("Connection made to %s:%d\n", conn_primary_ip, conn_primary_port); 53 return CURL_PREREQFUNC_OK; 54 } 55 56 int main(void) 57 { 58 struct priv prereq_data; 59 CURL *curl = curl_easy_init(); 60 if(curl) { 61 curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback); 62 curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data); 63 curl_easy_perform(curl); 64 } 65 } 66 ~~~ 67 68 # %AVAILABILITY% 69 70 # RETURN VALUE 71 72 curl_easy_setopt(3) returns a CURLcode indicating success or error. 73 74 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 75 libcurl-errors(3).