1CURLOPT_PREREQFUNCTION(3)  curl_easy_setopt options  CURLOPT_PREREQFUNCTION(3)
2
3
4

NAME

6       CURLOPT_PREREQFUNCTION  -  user  callback  called when a connection has
7       been established, but before a request has been made.
8

SYNOPSIS

10       #include <curl/curl.h>
11
12       /* These are the return codes for the pre-request callback. */
13       #define CURL_PREREQFUNC_OK 0
14       #define CURL_PREREQFUNC_ABORT 1 /* fail the entire transfer */
15
16       int prereq_callback(void *clientp,
17                           char *conn_primary_ip,
18                           char *conn_local_ip,
19                           int conn_primary_port,
20                           int conn_local_port);
21
22       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
23

DESCRIPTION

25       Pass a pointer to your callback function, which should match the proto‐
26       type shown above.
27
28       This function gets called by libcurl after a connection has been estab‐
29       lished or a connection has been reused (including any SSL handshaking),
30       but before any request is actually made on the connection. For example,
31       for HTTP, this callback is called once a  connection  has  been  estab‐
32       lished  to  the server, but before a GET/HEAD/POST/etc request has been
33       sent.
34
35       This function may be called multiple times if redirections are  enabled
36       and are being followed (see CURLOPT_FOLLOWLOCATION(3)).
37
38       The  callback  function  must  return CURL_PREREQFUNC_OK on success, or
39       CURL_PREREQFUNC_ABORT to cause the transfer to fail.
40
41       This function is passed the following arguments:
42
43       conn_primary_ip
44              A null-terminated pointer to a C string containing  the  primary
45              IP  of  the  remote server established with this connection. For
46              FTP, this is the IP for the control connection.  IPv6  addresses
47              are represented without surrounding brackets.
48
49       conn_local_ip
50              A null-terminated pointer to a C string containing the originat‐
51              ing IP for this connection. IPv6 addresses are represented with‐
52              out surrounding brackets.
53
54       conn_primary_port
55              The  primary  port  number on the remote server established with
56              this connection.  For FTP, this is the port for the control con‐
57              nection. This can be a TCP or a UDP port number depending on the
58              protocol.
59
60       conn_local_port
61              The originating port number for this connection. This can  be  a
62              TCP or a UDP port number depending on the protocol.
63
64       clientp
65              The pointer you set with CURLOPT_PREREQDATA(3).
66

DEFAULT

68       By default, this is NULL and unused.
69

PROTOCOLS

71       ALL
72

EXAMPLE

74       static int prereq_callback(void *clientp,
75                                  char *conn_primary_ip,
76                                  char *conn_local_ip,
77                                  int conn_primary_port,
78                                  int conn_local_port)
79       {
80         printf("Connection made to %s:%s\n", conn_primary_ip, conn_primary_port);
81         return CURL_PREREQFUNC_OK;
82       }
83
84       {
85         struct data prereq_data;
86         curl_easy_setopt(CURL *handle, CURLOPT_PREREQFUNCTION, prereq_callback);
87         curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, &prereq_data);
88       }
89

AVAILABILITY

91       Added in 7.80.0
92

RETURN VALUE

94       Returns  CURLE_OK  if the option is supported, and CURLE_UNKNOWN_OPTION
95       if not.
96

SEE ALSO

98       CURLOPT_PREREQDATA(3)
99
100
101
102libcurl 8.0.1                  January 02, 2023      CURLOPT_PREREQFUNCTION(3)
Impressum