当前位置:网站首页>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相關聯,那為何不直接返回最下面那個呢?
边栏推荐
- 一入“远程”终不悔,几人欢喜几人愁。| 社区征文
- 聊聊支付流程的設計與實現邏輯
- Tensorboard quick start (pytoch uses tensorboard)
- Notes on problems -- watching videos on edge will make the screen green
- Managing multiple selections with MVVM - managing multiple selections with MVVM
- Leetcode540: a single element in an ordered array
- [combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
- PR second time
- Introduction to SolidWorks gear design software tool geartrax
- QT学习日记9——对话框
猜你喜欢

Research on Swift

Implementation of Tetris in C language

Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition

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

【JokerのZYNQ7020】DDS_ Compiler。

Type conversion, variable

Micro service component sentinel console call

Golang unit test, mock test and benchmark test
![[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](/img/f1/c96c4a6d34e1ae971f492f4aed5a93.jpg)
[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

Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
随机推荐
互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
Graduation summary
1147_ Makefile learning_ Target files and dependent files in makefile
Gear2021 monthly update - December
[combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
Type conversion, variable
STM32 realizes 74HC595 control
AcWing 4489. Longest subsequence
QT adjust win screen brightness and sound size
企业级自定义表单引擎解决方案(十一)--表单规则引擎1
Leetcode 669 pruning binary search tree -- recursive method and iterative method
PR second time
远程办公工具分享|社区征文
[combinatorics] recursive equation (special solution form | special solution solving method | special solution example)
Qt调节Win屏幕亮度和声音大小
PHP processing - watermark images (text, etc.)
Kubernetes resource object introduction and common commands (4)
[mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source