11.7Schristos/* $NetBSD: sysctlnametomib.c,v 1.7 2012/03/13 21:13:37 christos Exp $ */ 21.1Satatat 31.1Satatat/*- 41.1Satatat * Copyright (c) 2003,2004 The NetBSD Foundation, Inc. 51.1Satatat * All rights reserved. 61.1Satatat * 71.1Satatat * This code is derived from software contributed to The NetBSD Foundation 81.1Satatat * by Andrew Brown. 91.1Satatat * 101.1Satatat * Redistribution and use in source and binary forms, with or without 111.1Satatat * modification, are permitted provided that the following conditions 121.1Satatat * are met: 131.1Satatat * 1. Redistributions of source code must retain the above copyright 141.1Satatat * notice, this list of conditions and the following disclaimer. 151.1Satatat * 2. Redistributions in binary form must reproduce the above copyright 161.1Satatat * notice, this list of conditions and the following disclaimer in the 171.1Satatat * documentation and/or other materials provided with the distribution. 181.1Satatat * 191.1Satatat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Satatat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Satatat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Satatat * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Satatat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Satatat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Satatat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Satatat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Satatat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Satatat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Satatat * POSSIBILITY OF SUCH DAMAGE. 301.1Satatat */ 311.1Satatat 321.3Slukem#include <sys/cdefs.h> 331.3Slukem#if defined(LIBC_SCCS) && !defined(lint) 341.7Schristos__RCSID("$NetBSD: sysctlnametomib.c,v 1.7 2012/03/13 21:13:37 christos Exp $"); 351.3Slukem#endif /* LIBC_SCCS and not lint */ 361.3Slukem 371.5Spooka#ifndef RUMP_ACTION 381.2Satatat#include "namespace.h" 391.5Spooka#endif 401.1Satatat#include <sys/param.h> 411.1Satatat#include <sys/sysctl.h> 421.7Schristos#include <assert.h> 431.1Satatat 441.6Spooka#ifdef RUMP_ACTION 451.6Spooka#include <rump/rump_syscalls.h> 461.6Spooka#define sysctl(a,b,c,d,e,f) rump_sys___sysctl(a,b,c,d,e,f) 471.6Spooka#else 481.2Satatat#ifdef __weak_alias 491.2Satatat__weak_alias(sysctlnametomib,_sysctlnametomib) 501.2Satatat#endif 511.5Spooka#endif /* RUMP_ACTION */ 521.5Spooka 531.1Satatat/* 541.1Satatat * freebsd compatible sysctlnametomib() function, implemented as an 551.1Satatat * extremely thin wrapper around sysctlgetmibinfo(). i think the use 561.1Satatat * of size_t as the third argument is erroneous, but what can we do 571.1Satatat * about that? 581.1Satatat */ 591.1Satatatint 601.1Satatatsysctlnametomib(const char *gname, int *iname, size_t *namelenp) 611.1Satatat{ 621.1Satatat u_int unamelen; 631.1Satatat int rc; 641.1Satatat 651.7Schristos _DIAGASSERT(__type_fit(u_int, *namelenp)); 661.7Schristos unamelen = (u_int)*namelenp; 671.1Satatat rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL, 681.1Satatat SYSCTL_VERSION); 691.1Satatat *namelenp = unamelen; 701.1Satatat 711.1Satatat return (rc); 721.1Satatat} 73