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