sysctlnametomib.c revision 1.1
11.1Satatat/*	$NetBSD: sysctlnametomib.c,v 1.1 2004/03/25 19:36:26 atatat 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 * 3. Neither the name of The NetBSD Foundation nor the names of its
191.1Satatat *    contributors may be used to endorse or promote products derived
201.1Satatat *    from this software without specific prior written permission.
211.1Satatat *
221.1Satatat * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
231.1Satatat * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
241.1Satatat * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
251.1Satatat * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
261.1Satatat * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
271.1Satatat * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
281.1Satatat * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
291.1Satatat * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
301.1Satatat * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
311.1Satatat * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
321.1Satatat * POSSIBILITY OF SUCH DAMAGE.
331.1Satatat */
341.1Satatat
351.1Satatat#include <sys/param.h>
361.1Satatat#include <sys/sysctl.h>
371.1Satatat
381.1Satatat/*
391.1Satatat * freebsd compatible sysctlnametomib() function, implemented as an
401.1Satatat * extremely thin wrapper around sysctlgetmibinfo().  i think the use
411.1Satatat * of size_t as the third argument is erroneous, but what can we do
421.1Satatat * about that?
431.1Satatat */
441.1Satatatint
451.1Satatatsysctlnametomib(const char *gname, int *iname, size_t *namelenp)
461.1Satatat{
471.1Satatat	u_int unamelen;
481.1Satatat	int rc;
491.1Satatat
501.1Satatat	unamelen = *namelenp;
511.1Satatat	rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL,
521.1Satatat			      SYSCTL_VERSION);
531.1Satatat	*namelenp = unamelen;
541.1Satatat
551.1Satatat	return (rc);
561.1Satatat}
57