当前位置:网站首页>OpenSSL的SSL/BIO_get_fd
OpenSSL的SSL/BIO_get_fd
2022-07-03 17:47:00 【星哥玩云】
只要是用到了OpenSSL,总会碰到让人心塞的事。 这次是SSL_get_fd。我用一种很简单的方式创建了一个SSL对象,直接在这个对象上进行SSL的accept:
bio = BIO_new(BIO_s_accept()); BIO_set_accept_port(bio, "1234"); BIO_do_accept(bio); SSL_set_bio(ssl, bio, bio); SSL_accept(ssl);
这样就不必折腾讨厌的sockaddr了。后来我想在和这个SSL对象关联的底层socket上执行setsockopt,想当然的使用了SSL_get_fd/BIO_get_fd这个非常自明的API。到此为止非常棒。接下来就不爽了,我发现setsockiot最终操作的那个描述符是listnen套接字,而不是accept返回的那个套接字。这似乎在API层面上十分合理,毕竟bio的参数就是一个BIO_s_accept,而和它关联的就是一个listen套接字。想要正确的得到accept返回的读写socket描述符,你得这么写:
[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
BIO_get_fd(BIO_next(bio), &sd);
BIO_get_fd(BIO_next(bio), &sd);问题是,你必须知道这个BIO stack是如何排列的才能写出上面的代码,做到如此最好的办法就是看OpenSSL的源代码。
BIO的API设计就一定要设计成get/set_fd吗?BIO就一定要和一个fd相关吗?memory类型的BIO如果get fd的话,会返回怎么的错误吗呢?既然BIO构成了一个叠加的IO stack,那么也许之有最下面的那个才会和一个UNIX fd相关联,那为何不直接返回最下面那个呢?
边栏推荐
- Automata and automatic line of non-standard design
- Kubernetes resource object introduction and common commands (4)
- Detailed explanation of common network attacks
- 国内如何购买Google Colab会员
- Talk about the design and implementation logic of payment process
- AcWing 4489. 最长子序列
- BFS - topology sort
- Test your trained model
- PUT vs. POST for Uploading Files - RESTful API to be Built Using Zend Framework
- [combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
猜你喜欢

Qt调节Win屏幕亮度和声音大小

Golang unit test, mock test and benchmark test

聊聊支付流程的设计与实现逻辑

vs2013已阻止安装程序,需安装IE10

国内如何购买Google Colab会员

Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028

Introduction to SolidWorks gear design software tool geartrax

Leetcode 669 pruning binary search tree -- recursive method and iterative method

IntelliJ 2021.3 short command line when running applications

Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
随机推荐
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
WEB-UI自动化测试-最全元素定位方法
PHP returns 500 errors but no error log - PHP return 500 error but no error log
Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
The difference between i++ and ++i: tell their differences easily
自动渗透测试工具核心功能简述
c# . Net tool ecosystem
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
Test your trained model
Y is always discrete and can't understand, how to solve it? Answer: read it several times
Vs2013 has blocked the installer, and ie10 needs to be installed
IntelliJ 2021.3 short command line when running applications
[combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
Ml (machine learning) softmax function to realize the classification of simple movie categories
SQL injection database operation foundation
When absolutely positioned, the element is horizontally and vertically centered
What is the difference between cloud server and cloud virtual machine
PHP processing - watermark images (text, etc.)
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
AcWing 4489. Longest subsequence