Hi Wilbert,
Generally, I think if you're creating the socket, the best thing to do is to
keep track of which type you created in some associated variable. Your code
sample below, for example, appears to keep this information in the "do6"
variable, so you don't need to query the socket for it.
On the other hand, if you get a socket of unknown type from somewhere, one
option is to do a getsockname call on it and check the sa_family field in
the returned address. This should always work when the socket is already
bound to an address. However, when this subject came up recently on the
implementor's mailing list, it was noted that this solution may not work on
some implementations in the case where the socket isn't bound to anything.
--Brian
> -----Original Message-----
> From: Wilbert de Graaf [mailto:[EMAIL PROTECTED]]
> Sent: Friday, 08 September, 2000 10:21
> To: [EMAIL PROTECTED]
> Subject: Q: how to get out the PF_xxx of a socket
>
>
>
> Hi,
>
> I am looking for a way to make code between ipv4 and ipv6 having less
> ifdef's. What I (think I) need is a way to find out the PF_xxx of a
> socket socket. Much like:
>
>
> if (do6)
> s = socket(PF_INET6, ...);
> else
> s = socket(PF_INET, ...);
>
> setsockopt(s, IPPROTO_IPvX(s), ...);
>
>
> I want to write the macro IPPROTO_IPvX(s), returning IPPROTO_IP if the
> socket's domain is PF_INET and IPPROTO_IPV6 if it's PF_INET6.
>
> I have been going trhough rfc2553 but couldn't find it. Does anybody
> have a clue ?
>
> - Wilbert
>
> ---------------------------------------------------------------------
> The IPv6 Users Mailing List
> Unsubscribe by sending "unsubscribe users" to [EMAIL PROTECTED]
>
---------------------------------------------------------------------
The IPv6 Users Mailing List
Unsubscribe by sending "unsubscribe users" to [EMAIL PROTECTED]