当前位置:网站首页>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相關聯,那為何不直接返回最下面那個呢?
边栏推荐
- Research on Swift
- Remote office tools sharing | community essay solicitation
- Notes on problems -- watching videos on edge will make the screen green
- 1164 Good in C
- 微服务组件Sentinel控制台调用
- 自动渗透测试工具核心功能简述
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- AcWing 4489. Longest subsequence
- Wechat applet for the first time
- How to purchase Google colab members in China
猜你喜欢

Micro service component sentinel console call
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge

问题随记 —— 在 edge 上看视频会绿屏

Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)

1164 Good in C

Automata and automatic line of non-standard design

Interviewer: why is the value nil not equal to nil?

STM32实现74HC595控制

Getting started with deops

UE4 official charging resources, with a total price of several thousand
随机推荐
[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)
Basic grammar of interview (Part 2)
Comparison of kotlin collaboration + retro build network request schemes
List of financial products in 2022
VM11289 WAService. js:2 Do not have __ e handler in component:
ArrayList分析3 : 删除元素
Talk about the design and implementation logic of payment process
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
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
TCP拥塞控制详解 | 3. 设计空间
Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
Leetcode Valentine's Day Special - looking for a single dog
Swm32 series Tutorial 4 port mapping and serial port application
聊聊支付流程的设计与实现逻辑
【JokerのZYNQ7020】DDS_ Compiler。
毕业总结
When absolutely positioned, the element is horizontally and vertically centered
Deops入门
Life perception 1