当前位置:网站首页>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相關聯,那為何不直接返回最下面那個呢?
边栏推荐
- Deops入门
- Micro service component sentinel console call
- Introduction to SolidWorks gear design software tool geartrax
- 小程序 多tab 多swiper + 每个tab分页
- 1164 Good in C
- Talk about the design and implementation logic of payment process
- Web-ui automated testing - the most complete element positioning method
- Leetcode540: a single element in an ordered array
- PS screen printing brush 131, many illustrators have followed suit
- How to install PHP on Ubuntu 20.04
猜你喜欢

MySQL grouping query
![[RT thread] NXP rt10xx device driver framework -- pin construction and use](/img/75/b4f034bfe49409f76e7fd92758804e.png)
[RT thread] NXP rt10xx device driver framework -- pin construction and use

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

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

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

Baiwen.com 7 days Internet of things smart home learning experience punch in the next day

Test your trained model

Leetcode 669 pruning binary search tree -- recursive method and iterative method

Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
随机推荐
数学公式(测试)
小程序 多tab 多swiper + 每个tab分页
Wechat applet for the first time
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
毕业总结
ES6类的继承
[combinatorics] generating function (shift property)
[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
Loop through JSON object list
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
问题随记 —— 在 edge 上看视频会绿屏
What is the difference between cloud server and cloud virtual machine
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
Deops入门
Ml (machine learning) softmax function to realize the classification of simple movie categories
[UE4] brush Arctic pack high quality Arctic terrain pack
AcWing 4489. Longest subsequence
Assembly for unloading Loadfrom() loaded assembly - unloading the assembly loaded with assembly LoadFrom()