当前位置:网站首页>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相关联,那为何不直接返回最下面那个呢?
边栏推荐
- Comparison of kotlin collaboration + retro build network request schemes
- AcWing 3438. 数制转换
- AcWing 4489. 最长子序列
- POM in idea XML graying solution
- VM11289 WAService. js:2 Do not have __ e handler in component:
- University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
- Ml (machine learning) softmax function to realize the classification of simple movie categories
- Inheritance of ES6 class
- Hongmeng third training
- Y is always discrete and can't understand, how to solve it? Answer: read it several times
猜你喜欢

Kubernetes resource object introduction and common commands (4)
![How to read the source code [debug and observe the source code]](/img/40/a2fca67bcde3c468a739c6990325f4.jpg)
How to read the source code [debug and observe the source code]

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

QT adjust win screen brightness and sound size

问题随记 —— 在 edge 上看视频会绿屏

As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation

互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码

STM32实现74HC595控制
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge

1147_ Makefile learning_ Target files and dependent files in makefile
随机推荐
Enterprise custom form engine solution (XI) -- form rule engine 1
问题随记 —— 在 edge 上看视频会绿屏
ES6类的继承
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
MinGW compile boost library
Introduction to SolidWorks gear design software tool geartrax
1146_ SiCp learning notes_ exponentiation
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
Mathematical formula (test)
i++与++i的区别:通俗易懂的讲述他们的区别
Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
Talk about the design and implementation logic of payment process
c# . Net tool ecosystem
MySQL has been stopped in the configuration interface during installation
Comparison of kotlin collaboration + retro build network request schemes
Kubernetes resource object introduction and common commands (III)
AcWing 4489. Longest subsequence
聊聊支付流程的设计与实现逻辑