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?
相关问题
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
Damn. Searched about half an hour. Now after posting this question I found immiediately the answer.
getsockopt([...]) with option SO_DOMAIN (see socket options)
POSIX-standard getsockname will help:
it will fill in given struct sockaddr (upon success):