源代码

/****************************************************************************                                  _   _ ____  _*  Project                     ___| | | |  _ \| |*                             / __| | | | |_) | |*                            | (__| |_| |  _ <| |___*                             \___|\___/|_| \_\_____|** Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.** This software is licensed as described in the file COPYING, which* you should have received as part of this distribution. The terms* are also available at https://curl.haxx.se/docs/copyright.html.** You may opt to use, copy, modify, merge, publish, distribute and/or sell* copies of the Software, and permit persons to whom the Software is* furnished to do so, under the terms of the COPYING file.** This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY* KIND, either express or implied.****************************************************************************/
/* <DESC>* Uses the CURLINFO_TLS_SESSION data.* </DESC>*//* Note that this example currently requires curl to be linked againstGnuTLS (and this program must also be linked against -lgnutls). */#include <stdio.h>#include <curl/curl.h>
#include <gnutls/gnutls.h>static CURL *curl;static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
{const struct curl_tlssessioninfo *info;unsigned int cert_list_size;const gnutls_datum_t *chainp;CURLcode res;(void)stream;(void)ptr;res = curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &info);if(!res) {switch(info->backend) {case CURLSSLBACKEND_GNUTLS:/* info->internals is now the gnutls_session_t */chainp = gnutls_certificate_get_peers(info->internals, &cert_list_size);if((chainp) && (cert_list_size)) {unsigned int i;for(i = 0; i < cert_list_size; i++) {gnutls_x509_crt_t cert;gnutls_datum_t dn;if(GNUTLS_E_SUCCESS == gnutls_x509_crt_init(&cert)) {if(GNUTLS_E_SUCCESS ==gnutls_x509_crt_import(cert, &chainp[i], GNUTLS_X509_FMT_DER)) {if(GNUTLS_E_SUCCESS ==gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_FULL, &dn)) {fprintf(stderr, "Certificate #%u: %.*s", i, dn.size, dn.data);gnutls_free(dn.data);}}gnutls_x509_crt_deinit(cert);}}}break;case CURLSSLBACKEND_NONE:default:break;}}return size * nmemb;
}int main(void)
{curl_global_init(CURL_GLOBAL_DEFAULT);curl = curl_easy_init();if(curl) {curl_easy_setopt(curl, CURLOPT_URL, "http://10.170.6.66");curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);(void) curl_easy_perform(curl);curl_easy_cleanup(curl);}curl_global_cleanup();return 0;
}

编译

#!/bin/bash
# rongtaogcc $* `curl-config --libs --cflags` `pkg-config --libs --cflags openssl gtk+-2.0 gthread-2.0 libevent` \-I /usr/include/libxml2/ -lxml2 -leventviews -levent_pthreads /usr/local/lib/libuv.a -ldl -lgnutls

C语言libcurl:Uses the CURLINFO_TLS_SESSION data.相关推荐

  1. C语言libcurl例程:multi 多线程,多任务

    目录 A multi-threaded example that uses pthreads to fetch several files at once multi_socket API using ...

  2. 【C语言】[其他] :code, data, idata, xdata, bdata, edata, hdata等,代表的意思

    从数据存储类型来说,8051系列有片内.片外程序存储器,片内.片外数据存储器,片内程序存储器还分直接寻址区和间接寻址类型,分别对应code.data.xdata.idata以及根据51系列特点而设 定 ...

  3. R语言必学包之data.table包

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/wltom1985/article/de ...

  4. (三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析

    注:本博客旨在分享个人学习心得,有不规范之处请多多包涵! 目录 Function 函数 data.frame 数据框 DNA序列读取与分析实例 结束语 Function 函数 像其它的编程语言一样,R ...

  5. C语言libcurl:RTSP(Real Time Streaming Protocol),RFC2326,实时流传输协议

    RTSP是TCP/IP协议体系中的一个应用层协议,由哥伦比亚大学.网景和RealNetworks公司提交的IETF RFC标准. /** Copyright (c) 2011 - 2019, Jim ...

  6. C语言libcurl:提供特定主机和端口对的自定义地址--resolve

    使用CURLOPT_RESOLVE为给定的主机名+端口*数字组合提供自定义IP地址. /******************************************************** ...

  7. model存储 swift_Swift语言IOS8开发战记10.Data Model

    上一话中实现了两个控制器间的传值,最终效果如图: 这是我们的主页面: 在ViewController中我们主页显示的内容是放到不同的数组中的: var restaurantNames = [" ...

  8. R语言MIDAS(Mixed Frequency Data Sampling Regression Models)学习分享(一)从下载安装包开始

    最近想做混频数据的研究,此前没有接触过,完全是从0开始,记录学习过程,请大家指点~~ 首先选择R作为我这次的建模工具,为此查看了很多教程,发现大多数教程从library(midasr)开始教学,然而我 ...

  9. 05--MySQL自学教程:DDL(Data Definition Language:数据库定义语言)操作数据库(一)

    1.DDL(Data Definition Language:数据库定义语言)概览 DDL(Data Definition Language:数据库定义语言) 2.DDL对数据库的操作 1)方法概览 ...

最新文章

  1. python装饰器 property_python @property装饰器
  2. html文件div盒子浮动,css基础03-盒模型、网站布局思想、浮动以及浮动带来的影响...
  3. HTML学习04之内联框架和表单
  4. nslang oracle_RAC11g+DG 高可用容灾方案部署
  5. 编写html要注意,编写XHTML需要注意的问题以及和HTML的区别
  6. LeakCanary,检测安卓,java内存泄漏
  7. 小程序中view的自定义属性获取
  8. 常用的JavaScript工具类库收藏
  9. matlab fair,matlab练习程序(加权最小二乘)
  10. 网易编程题目——相反数:
  11. 性格测试系统v1.0
  12. PC软件-实用工具 True Launch Bar
  13. 使用android新特性:Material Design
  14. 明天14:00,棕榈泉见~友盟+、大麦网、凯叔讲故事都在
  15. Android加载web页时有的手机会弹出手机自带的浏览器解决方法
  16. 用python对excel进行单元格操作
  17. System memory 249364480 must be at least 471859200
  18. Week4 常用类 麻了
  19. 中国探月工程首席科学家欧阳自远:“嫦娥”月面图千真万确
  20. 介绍一种音频信号分类方法

热门文章

  1. github语音识别对对_语音识别尝试方向
  2. Python3基础13——冒泡排序
  3. 1207.1——C语言 函数
  4. Java中static、final用法小结
  5. Siebel Admin: How to find the Component that associated with Application
  6. 案例:演示JDBC的使用
  7. Mysql 数据库语句常用总结
  8. vue服务端转html,普通vue-cli初始项目转为服务端渲染SSR
  9. 2017年12月计算机一级c,2017年12月计算机二级《C语言》强化模拟题(1)
  10. python 重写抽象类编译错误_从零开始的Java之旅5.0继承、super、this、抽象类