Xavier Roche
2014-05-17 10:21:02 UTC
Hi folks!
POSIX has a SO_TYPE option for getsockopt() to retrieve the socket type of a given (socket) file descriptor.
The socket type is typically set when creating it through a call to:
int socket(int domain, int type, int protocol);
Unfortunately, it seems that there are no (standardized) options to fetch the first domain attribute, or the last protocol attribute.
Is there any rationale behing the fact that there are neither a SO_DOMAIN option, nor a SO_PROTOCOL option in POSIX ?
As far as I can see, Linux has such options: (http://man7.org/linux/man-pages/man7/socket.7.html)
SO_DOMAIN (since Linux 2.6.32)
Retrieves the socket domain as an integer, returning a value
such as AF_INET6. See socket(2) for details. This socket
option is read-only.
SO_PROTOCOL (since Linux 2.6.32)
Retrieves the socket protocol as an integer, returning a value
such as IPPROTO_SCTP. See socket(2) for details. This socket
option is read-only.
And Solaris has also a SO_DOMAIN option, BUT a bit different SO_PROTOTYPE one: (http://docs.oracle.com/cd/E26505_01/html/816-5170/getsockopt-3socket.html#REFMAN3Bgetsockopt-3socket)
SO_DOMAIN
get the domain used in the socket (get only)
SO_PROTOTYPE
for socket in domains PF_INET and PF_INET6, get the underlying protocol number used in the socket. For socket in domain PF_ROUTE, get the address family used in the socket.
At last, FreeBSD has a SO_PROTOCOL (but no SO_DOMAIN, strangely) (http://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2)
POSIX has a SO_TYPE option for getsockopt() to retrieve the socket type of a given (socket) file descriptor.
The socket type is typically set when creating it through a call to:
int socket(int domain, int type, int protocol);
Unfortunately, it seems that there are no (standardized) options to fetch the first domain attribute, or the last protocol attribute.
Is there any rationale behing the fact that there are neither a SO_DOMAIN option, nor a SO_PROTOCOL option in POSIX ?
As far as I can see, Linux has such options: (http://man7.org/linux/man-pages/man7/socket.7.html)
SO_DOMAIN (since Linux 2.6.32)
Retrieves the socket domain as an integer, returning a value
such as AF_INET6. See socket(2) for details. This socket
option is read-only.
SO_PROTOCOL (since Linux 2.6.32)
Retrieves the socket protocol as an integer, returning a value
such as IPPROTO_SCTP. See socket(2) for details. This socket
option is read-only.
And Solaris has also a SO_DOMAIN option, BUT a bit different SO_PROTOTYPE one: (http://docs.oracle.com/cd/E26505_01/html/816-5170/getsockopt-3socket.html#REFMAN3Bgetsockopt-3socket)
SO_DOMAIN
get the domain used in the socket (get only)
SO_PROTOTYPE
for socket in domains PF_INET and PF_INET6, get the underlying protocol number used in the socket. For socket in domain PF_ROUTE, get the address family used in the socket.
At last, FreeBSD has a SO_PROTOCOL (but no SO_DOMAIN, strangely) (http://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2)