sysctlnametomib.c revision 1.5
11.5Spooka/*	$NetBSD: sysctlnametomib.c,v 1.5 2010/12/13 21:07:55 pooka 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.5Spooka__RCSID("$NetBSD: sysctlnametomib.c,v 1.5 2010/12/13 21:07:55 pooka 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.1Satatat
431.2Satatat#ifdef __weak_alias
441.2Satatat__weak_alias(sysctlnametomib,_sysctlnametomib)
451.2Satatat#endif
461.2Satatat
471.5Spooka#ifdef RUMP_ACTION
481.5Spooka#include <rump/rump_syscalls.h>
491.5Spooka#define sysctl(a,b,c,d,e,f) rump_sys___sysctl(a,b,c,d,e,f)
501.5Spooka#endif /* RUMP_ACTION */
511.5Spooka
521.1Satatat/*
531.1Satatat * freebsd compatible sysctlnametomib() function, implemented as an
541.1Satatat * extremely thin wrapper around sysctlgetmibinfo().  i think the use
551.1Satatat * of size_t as the third argument is erroneous, but what can we do
561.1Satatat * about that?
571.1Satatat */
581.1Satatatint
591.1Satatatsysctlnametomib(const char *gname, int *iname, size_t *namelenp)
601.1Satatat{
611.1Satatat	u_int unamelen;
621.1Satatat	int rc;
631.1Satatat
641.1Satatat	unamelen = *namelenp;
651.1Satatat	rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL,
661.1Satatat			      SYSCTL_VERSION);
671.1Satatat	*namelenp = unamelen;
681.1Satatat
691.1Satatat	return (rc);
701.1Satatat}
71