当前位置:网站首页>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相關聯,那為何不直接返回最下面那個呢?
边栏推荐
- Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
- AcWing 3438. Number system conversion
- Detailed explanation of common network attacks
- As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
- [combinatorics] generating function (linear property | product property)
- UE4 official charging resources, with a total price of several thousand
- Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
- AcWing 3438. 数制转换
- How to read the source code [debug and observe the source code]
- Assembly for unloading Loadfrom() loaded assembly - unloading the assembly loaded with assembly LoadFrom()
猜你喜欢

Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028

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

1164 Good in C

MySQL has been stopped in the configuration interface during installation

Research on Swift

Wechat applet for the first time

Notes on problems -- watching videos on edge will make the screen green

Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos

聊聊支付流程的設計與實現邏輯
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge
随机推荐
Website with JS doesn't work in IE9 until the Developer Tools is activated
[combinatorics] generating function (linear property | product property)
Inheritance of ES6 class
Basic grammar of interview (Part 2)
Tensorboard quick start (pytoch uses tensorboard)
AcWing 3438. Number system conversion
Automata and automatic line of non-standard design
Y is always discrete and can't understand, how to solve it? Answer: read it several times
RDS数据库的监测页面在哪看?
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
List of financial products in 2022
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
国内如何购买Google Colab会员
Embedded-c language-7
Research on Swift
Kubernetes resource object introduction and common commands (III)
鸿蒙第四次培训
Web-ui automated testing - the most complete element positioning method
[combinatorics] recursive equation (special solution form | special solution solving method | special solution example)