mirror of
https://github.com/moparisthebest/curl
synced 2025-01-11 22:18:00 -05:00
CURLINFO_TLS_SSL_PTR.3: improve the example
The previous example was a little bit confusing, because SSL* structure (or other "in use" SSL connection pointer) is not accessible after the transfer is completed, therefore working with the raw TLS library specific pointer needs to be done during transfer. Closes #2690
This commit is contained in:
parent
eebd3bb68a
commit
24cb114c53
@ -5,7 +5,7 @@
|
|||||||
.\" * | (__| |_| | _ <| |___
|
.\" * | (__| |_| | _ <| |___
|
||||||
.\" * \___|\___/|_| \_\_____|
|
.\" * \___|\___/|_| \_\_____|
|
||||||
.\" *
|
.\" *
|
||||||
.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
.\" *
|
.\" *
|
||||||
.\" * This software is licensed as described in the file COPYING, which
|
.\" * This software is licensed as described in the file COPYING, which
|
||||||
.\" * you should have received as part of this distribution. The terms
|
.\" * you should have received as part of this distribution. The terms
|
||||||
@ -129,15 +129,34 @@ https://github.com/curl/curl/issues/685
|
|||||||
All TLS-based
|
All TLS-based
|
||||||
.SH EXAMPLE
|
.SH EXAMPLE
|
||||||
.nf
|
.nf
|
||||||
CURL *curl = curl_easy_init();
|
#include <curl/curl.h>
|
||||||
if(curl) {
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
CURL *curl;
|
||||||
|
static size_t wf(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||||
|
{
|
||||||
|
const struct curl_tlssessioninfo *info = NULL;
|
||||||
|
CURLcode res = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &info);
|
||||||
|
if(info && !res) {
|
||||||
|
if(CURLSSLBACKEND_OPENSSL == info->backend) {
|
||||||
|
printf("OpenSSL ver. %s\\n", SSL_get_version((SSL*)info->internals));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size * nmemb;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
struct curl_tlssessioninfo *tls;
|
curl = curl_easy_init();
|
||||||
|
if(curl) {
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wf);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tls);
|
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
.fi
|
.fi
|
||||||
.SH AVAILABILITY
|
.SH AVAILABILITY
|
||||||
Added in 7.48.0.
|
Added in 7.48.0.
|
||||||
|
Loading…
Reference in New Issue
Block a user