当前位置:网站首页>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 formula (test)
- 1146_ SiCp learning notes_ exponentiation
- 远程办公工具分享|社区征文
- VM11289 WAService. js:2 Do not have __ e handler in component:
- 国内如何购买Google Colab会员
- Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
- Kotlin's collaboration: Context
- Hongmeng third training
- Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
- List的stream中Long对象与long判等问题记录
猜你喜欢
List的stream中Long对象与long判等问题记录
Vs2013 has blocked the installer, and ie10 needs to be installed
Select 3 fcpx plug-ins. Come and see if you like them
How to deploy applications on kubernetes cluster
MySQL has been stopped in the configuration interface during installation
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
[RT thread] NXP rt10xx device driver framework -- pin construction and use
Wechat applet for the first time
Leetcode Valentine's Day Special - looking for a single dog
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
随机推荐
鸿蒙第三次培训
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
Interviewer: why is the value nil not equal to nil?
Applet with multiple tabs and Swipers + paging of each tab
Five problems of database operation in commodity supermarket system
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
Online assignment 3 of mobile Internet technology in the 20th autumn of electronic technology [standard answer]
Servlet specification Part II
[vscode] convert tabs to spaces
Stm32h7 Hal library SPI DMA transmission has been in busy solution
聊聊支付流程的设计与实现逻辑
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
Kubernetes resource object introduction and common commands (III)
Ml (machine learning) softmax function to realize the classification of simple movie categories
Hongmeng fourth training
The difference between get and post
First day of rhcsa study
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026