当前位置: 首页 > news >正文

福州网站建设加推广携程网站模板

福州网站建设加推广,携程网站模板,机关网站建设和运行情况汇报,wordpress在线监测文章目录 openssl3.2 - 官方demo学习 - saccept.cEND openssl3.2 - 官方demo学习 - saccept.c 建立TLSServer(使用了证书, 和证书中的私钥), 接收客户端的连接, 并将客户端发来的信息打印到屏幕 笔记 /*! \file saccept.c */ /*! \brief 建立TLSServer(使用了证书, 和证书中…

文章目录

    • openssl3.2 - 官方demo学习 - saccept.c
    • END

openssl3.2 - 官方demo学习 - saccept.c

建立TLSServer(使用了证书, 和证书中的私钥), 接收客户端的连接, 并将客户端发来的信息打印到屏幕

笔记

/*! \file saccept.c */
/*! \brief 建立TLSServer(使用了证书, 和证书中的私钥)接收客户端的连接, 并将客户端发来的信息打印到屏幕 *//** Copyright 1998-2017 The OpenSSL Project Authors. All Rights Reserved.** Licensed under the Apache License 2.0 (the "License").  You may not use* this file except in compliance with the License.  You can obtain a copy* in the file LICENSE in the source distribution or at* https://www.openssl.org/source/license.html*//*-* A minimal program to serve an SSL connection.* It uses blocking.* saccept host:port* host is the interface IP to use.  If any interface, use *:port* The default it *:4433** cc -I../../include saccept.c -L../.. -lssl -lcrypto -ldl*/#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <openssl/err.h>
#include <openssl/ssl.h>#pragma comment(lib, "libcrypto.lib")
#pragma comment(lib, "libssl.lib")#include <openssl/applink.c> /*! for OPENSSL_Uplink(00007FF8B7EF0FE8,08): no OPENSSL_Applink */#define CERT_FILE       "server.pem"static volatile int done = 0;void interrupt(int sig)
{done = 1;
}// linux才有的信号处理, VS2019中没有
#ifdef __unix__
void sigsetup(void)
{struct sigaction sa;/** Catch at most once, and don't restart the accept system call.*/sa.sa_flags = SA_RESETHAND;sa.sa_handler = interrupt;sigemptyset(&sa.sa_mask);sigaction(SIGINT, &sa, NULL);
}
#else 
void sigsetup(void) {}
#endif // #ifdef __unix__int main(int argc, char *argv[])
{char *port = NULL;BIO *in = NULL;BIO *ssl_bio, *tmp;SSL_CTX *ctx;char buf[512];int ret = EXIT_FAILURE, i;if (argc <= 1)port = "*:4433";elseport = argv[1];ctx = SSL_CTX_new(TLS_server_method());if (!SSL_CTX_use_certificate_chain_file(ctx, CERT_FILE))goto err;if (!SSL_CTX_use_PrivateKey_file(ctx, CERT_FILE, SSL_FILETYPE_PEM))goto err;if (!SSL_CTX_check_private_key(ctx))goto err;/* Setup server side SSL bio */ssl_bio = BIO_new_ssl(ctx, 0);if ((in = BIO_new_accept(port)) == NULL)goto err;/** This means that when a new connection is accepted on 'in', The ssl_bio* will be 'duplicated' and have the new socket BIO push into it.* Basically it means the SSL BIO will be automatically setup*/BIO_set_accept_bios(in, ssl_bio);/* Arrange to leave server loop on interrupt */sigsetup();again:/** The first call will setup the accept socket, and the second will get a* socket.  In this loop, the first actual accept will occur in the* BIO_read() function.*/if (BIO_do_accept(in) <= 0)goto err;while (!done) {// 阻塞的读i = BIO_read(in, buf, 512);if (i == 0) {/** If we have finished, remove the underlying BIO stack so the* next time we call any function for this BIO, it will attempt* to do an accept*/printf("Done\n");tmp = BIO_pop(in);BIO_free_all(tmp);goto again;}if (i < 0)goto err;fwrite(buf, 1, i, stdout);fflush(stdout);}ret = EXIT_SUCCESS;err:if (ret != EXIT_SUCCESS)ERR_print_errors_fp(stderr);BIO_free(in);return ret;
}

END

http://www.yayakq.cn/news/638184/

相关文章:

  • 百度站长工具怎么查排名专业做二手网站有哪些
  • 外链建设应如何进行seo技术蜘蛛屯
  • 什么是做学院网站网站排名查询
  • 北京做网站比较好的谷德设计网app
  • 做网站的具体需求中国中小企业河南网
  • 漳州哪里做网站wordpress json api auth
  • 企业营销型网站建设价格中国服务外包
  • 中国企业报集团简介百度seo优化
  • 无锡 网站建设专业的建站公司服务
  • 东莞seo网站建设公司怎样在凡科免费做网站
  • 湖州佳成建设网站中讯科技-运城网站建设
  • 辽宁城建设计院有限公司网站微信网站 详解
  • 网站改版会影响收录吗济南建网站价格消费品展
  • 马边彝族移动网站建设海口建设网站
  • 辽阳专业网站开发公司财务公司协会
  • 网站建设中通知ppt模板免费网站在线制作
  • 衡水做外贸网站建设做我女朋友程序网站
  • 智能网站建设系统wordpress 微信主题下载
  • 有做酒席酒水网站吗完全备份wordpress
  • 深圳品牌网站制作推荐驾校网站模板
  • copyright技术支持 东莞网站建设wordpress front
  • 网站制作的部分WordPress获取用户密码
  • 国外外贸网站大全.net网站开发实验报告
  • 网站外链建设培训高港区企业网站建设
  • 网站文章标题室内设计师联系方式
  • 微信网站特点wordpress多重筛选
  • asp.net 网站访问量推广普通话手抄报简单又好看内容
  • 深圳网站设计兴田德润官方网站wordpress如何制作主题
  • wordpress赞赏插件win7优化大师
  • 中国核工业华兴建设公司网站哈尔滨新闻头条最新消息