当前位置:网站首页>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相关联,那为何不直接返回最下面那个呢?
边栏推荐
- Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
- 数仓任务里面 跑SQL任务的时候用的数据库账号是在哪里配置的
- Graduation summary
- [set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela
- Type conversion, variable
- [mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
- c# .net 工具生态
- vs2013已阻止安装程序,需安装IE10
- Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
- Basic grammar of interview (Part 2)
猜你喜欢

TCP congestion control details | 3 design space

Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source

Golang unit test, mock test and benchmark test

【JokerのZYNQ7020】DDS_ Compiler。

How to purchase Google colab members in China

Implementation of Tetris in C language

IntelliJ 2021.3 short command line when running applications

Talk about the design and implementation logic of payment process

面试官:值为 nil 为什么不等于 nil ?

List的stream中Long对象与long判等问题记录
随机推荐
AcWing 4489. 最长子序列
Research on Swift
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
Micro service component sentinel console call
Golang unit test, mock test and benchmark test
Ml (machine learning) softmax function to realize the classification of simple movie categories
PHP processing - watermark images (text, etc.)
ArrayList分析3 : 删除元素
STM32 realizes 74HC595 control
QT学习日记9——对话框
Enterprise custom form engine solution (XI) -- form rule engine 1
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
RDS数据库的监测页面在哪看?
Draw some simple graphics with MFC
Leetcode540: a single element in an ordered array
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Vs2013 has blocked the installer, and ie10 needs to be installed
Select 3 fcpx plug-ins. Come and see if you like them
国内如何购买Google Colab会员
MySQL has been stopped in the configuration interface during installation