From owner-freebsd-net Sun Mar 25 13:14:31 2001 Delivered-To: freebsd-net@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 67BE337B71E for ; Sun, 25 Mar 2001 13:14:28 -0800 (PST) (envelope-from bright@fw.wintelcom.net) Received: (from bright@localhost) by fw.wintelcom.net (8.10.0/8.10.0) id f2PLESD27030 for net@FreeBSD.ORG; Sun, 25 Mar 2001 13:14:28 -0800 (PST) Date: Sun, 25 Mar 2001 13:14:28 -0800 From: Alfred Perlstein To: net@FreeBSD.ORG Subject: Re: proper way to test for INET/INET6? Message-ID: <20010325131428.T9431@fw.wintelcom.net> References: <20010325125710.S9431@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010325125710.S9431@fw.wintelcom.net>; from bright@wintelcom.net on Sun, Mar 25, 2001 at 12:57:10PM -0800 X-all-your-base: are belong to us. Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org * Alfred Perlstein [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