Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Mar 2001 13:14:28 -0800
From:      Alfred Perlstein <bright@wintelcom.net>
To:        net@FreeBSD.ORG
Subject:   Re: proper way to test for INET/INET6?
Message-ID:  <20010325131428.T9431@fw.wintelcom.net>
In-Reply-To: <20010325125710.S9431@fw.wintelcom.net>; from bright@wintelcom.net on Sun, Mar 25, 2001 at 12:57:10PM -0800
References:  <20010325125710.S9431@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
* Alfred Perlstein <bright@wintelcom.net> [010325 12:57] wrote:
> I'm wondering how one is supposed to test for INET6 support in the
> kernel.  Currently a few places do it in a somewhat bogus fashion
> like this:
> 
>     s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
>     if (s == -1)
>         have_v6 = 0;
>     else
>         close(s); 
> 
> But this is wrong because unless errno is EPROTONOSUPPORT this
> might mean something else is horribly wrong.  There's also at least
> one place that happens to check for EPROTONOSUPPORT, but it also
> erroniously checks for EPFNOSUPPORT and EAFNOSUPPORT which are
> actually the result one would get if they passed invalid arguments
> to socket(2).
> 
> So what's the right thing to do here?

Someone suggested using sysctl, the problem is that unlike testing
for devfs (sysctlbyname("vfs.devfs.generation", NULL, NULL, NULL, 0) == 0)
I can't do that because "net.inet6" isn't a leaf sysctl node.

What I can do is:

int mibs[20];
size_t sz;

sz = sizeof (mibs);
if (sysctlnametomib("net.inet6", mibs, &sz) == 0) 
	printf("ok\n");
else
	printf("no\n");

Which is somewhat gross, anyone object to me changing sysctlnametomib()
such that it can take NULL arguements (it cores if you do that now)
and return success if the node exists?

-- 
-Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
Daemon News Magazine in your snail-mail! http://magazine.daemonnews.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010325131428.T9431>