diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2022-07-19 09:25:45 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2022-07-19 09:25:45 +0000 |
commit | 6b5d086ec45dff51ed22e7a50fa0bb9e9fd186ec (patch) | |
tree | 3ccd969d30d0a03e8c2c019b5c4e33f0f8bbf52f /lib/libc/gen | |
parent | 6f2d6286a0ddaa783704f0ecb116592926cd891f (diff) |
Use sysctl CTL_NET.PF_INET6 to check if IPv6 is available or not.
With this sysconf(3) no longer needs the inet pledge.
The kernel has been updated for this for a while now.
OK sthen@ deraadt@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/sysconf.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 7b7647e9d1e..de36493315a 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysconf.c,v 1.27 2020/10/12 19:51:28 deraadt Exp $ */ +/* $OpenBSD: sysconf.c,v 1.28 2022/07/19 09:25:44 claudio Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -62,7 +62,7 @@ sysconf(int name) { struct rlimit rl; size_t len; - int mib[2], value, namelen, sverrno; + int mib[3], value, namelen, sverrno; len = sizeof(value); namelen = 2; @@ -238,12 +238,17 @@ sysconf(int name) case _SC_IPV6: #if _POSIX_IPV6 == 0 sverrno = errno; - value = socket(PF_INET6, SOCK_DGRAM, 0); + mib[0] = CTL_NET; + mib[1] = PF_INET6; + mib[2] = 0; + namelen = 3; + value = 0; + if (sysctl(mib, 3, NULL, 0, NULL, 0) == -1) + value = errno; errno = sverrno; - if (value >= 0) { - HIDDEN(close)(value); + if (value != ENOPROTOOPT) return (200112L); - } else + else return (0); #else return (_POSIX_IPV6); |