从套接字获取地址族.Linux [英] Get address family from socket. Linux

查看:18
本文介绍了从套接字获取地址族.Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 Linux Socket API 编写一个 C++ 包装器.在 socket() ctor 中,请求地址族 (AF).我不想再次在 connect() 签名中要求 AF,因为它已经在套接字的构造函数中给出.那么如何从现有套接字中获取 AF?

I want to write a C++ wrapper for the Linux Socket API. In the socket() ctor the adress family (AF) is requested. I dont want to require the AF in the connect() signature again, becuase it has been already given in the constructor of socket. So how do I get the AF from an existing socket?

推荐答案

该死.找了半个小时左右.现在发布这个问题后,我立即找到了答案.

Damn. Searched about half an hour. Now after posting this question I found immiediately the answer.

getsockopt([...]) 带有选项 SO_DOMAIN(参见 socket 选项)

getsockopt([...]) with option SO_DOMAIN (see socket options)

这篇关于从套接字获取地址族.Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆