From 6ebd73a51261c05eb5da93c703031bc26bd5a839 Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 19 Jul 2022 09:25:44 +0000 Subject: [PATCH] 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@ --- lib/libc/gen/sysconf.c | 17 +++++++++++------ 1 file 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); -- 2.20.1