当前位置:网站首页>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相关联,那为何不直接返回最下面那个呢?
边栏推荐
- PR second time
- SQL injection database operation foundation
- Tensorboard quick start (pytoch uses tensorboard)
- Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
- Comparison of kotlin collaboration + retro build network request schemes
- PS screen printing brush 131, many illustrators have followed suit
- Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
- 聊聊支付流程的设计与实现逻辑
- 聊聊支付流程的设计与实现逻辑
- How to read the source code [debug and observe the source code]
猜你喜欢
Notes on problems -- watching videos on edge will make the screen green
QT学习日记9——对话框
PS screen printing brush 131, many illustrators have followed suit
TensorBoard快速入门(Pytorch使用TensorBoard)
UE4 official charging resources, with a total price of several thousand
How to purchase Google colab members in China
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
面试官:值为 nil 为什么不等于 nil ?
TCP拥塞控制详解 | 3. 设计空间
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
随机推荐
How to purchase Google colab members in China
POM in idea XML graying solution
远程办公工具分享|社区征文
First day of rhcsa study
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
AcWing 3438. Number system conversion
Select 3 fcpx plug-ins. Come and see if you like them
AcWing 4489. 最长子序列
TCP congestion control details | 3 design space
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
UE4 official charging resources, with a total price of several thousand
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
数学公式(测试)
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
Online assignment 3 of mobile Internet technology in the 20th autumn of electronic technology [standard answer]
Talk about the design and implementation logic of payment process
聊聊支付流程的设计与实现逻辑
[combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
[RT thread] NXP rt10xx device driver framework -- Audio construction and use