当前位置:网站首页>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相關聯,那為何不直接返回最下面那個呢?
边栏推荐
- [mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- 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
- [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)
- Life perception 1
- QT学习日记9——对话框
- 1146_ SiCp learning notes_ exponentiation
- Leetcode 669 pruning binary search tree -- recursive method and iterative method
- [UE4] brush Arctic pack high quality Arctic terrain pack
- Qt调节Win屏幕亮度和声音大小
猜你喜欢

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

Golang单元测试、Mock测试以及基准测试

Leetcode Valentine's Day Special - looking for a single dog

(9) Opencv Canny edge detection

鸿蒙第四次培训

Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028

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

Leetcode 108 converts an ordered array into a binary search tree -- recursive method

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

Type conversion, variable
随机推荐
Micro service component sentinel console call
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Swm32 series Tutorial 4 port mapping and serial port application
Test your trained model
First day of rhcsa study
WEB-UI自动化测试-最全元素定位方法
Y is always discrete and can't understand, how to solve it? Answer: read it several times
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
RDS数据库的监测页面在哪看?
Type conversion, variable
[combinatorics] generating function (shift property)
Tensorboard quick start (pytoch uses tensorboard)
List的stream中Long对象与long判等问题记录
[RT thread] NXP rt10xx device driver framework -- pin construction and use
Applet setting multi account debugging
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
问题随记 —— 在 edge 上看视频会绿屏
1146_ SiCp learning notes_ exponentiation
The third day of writing C language by Yabo people
(8) HS corner detection