On Sat, Sep 09, 2000 at 09:44:17AM +0900, [EMAIL PROTECTED] wrote:
> IPPROTO_IPvX(s)
> int s;
> {
> struct sockaddr_storage ss;
> socklen_t sslen;
>
> sslen = sizeof(ss);
> getsockname(s, (struct sockaddr *)&ss, &sslen);
> switch (ss.ss_family) {
> case AF_INET:
> return IPPROTO_IP;
> case AF_INET6:
> return IPPROTO_IPV6;
> default:
> return -1;
> }
> }
This is not guaranteed to work. The XNET spec says that if the socket
is not bound to a local name, the contents of the returned data is
unspecified.
This is a shame, I've had real use for this a few times. This is not
just related to IPv6 either. I've seen code that uses this to check
if a socket is AF_INET or AF_UNIX.
I haven't yet seen a platform where this doesn't work, but I'm reluctant
to use it because of the spec. I suppose should check this with the
XNET-people.
Stig
---------------------------------------------------------------------
The IPv6 Users Mailing List
Unsubscribe by sending "unsubscribe users" to [EMAIL PROTECTED]