1*df6ad731Slogwang /*
2*df6ad731Slogwang * Copyright 2001 The FreeBSD Project. All Rights Reserved.
3*df6ad731Slogwang *
4*df6ad731Slogwang * Redistribution and use in source and binary forms, with or without
5*df6ad731Slogwang * modification, are permitted provided that the following conditions
6*df6ad731Slogwang * are met:
7*df6ad731Slogwang *
8*df6ad731Slogwang * 1. Redistributions of source code must retain the above copyright
9*df6ad731Slogwang * notice, this list of conditions and the following disclaimer.
10*df6ad731Slogwang * 2. Redistributions in binary form must reproduce the above copyright
11*df6ad731Slogwang * notice, this list of conditions and the following disclaimer in the
12*df6ad731Slogwang * documentation and/or other materials provided with the distribution.
13*df6ad731Slogwang *
14*df6ad731Slogwang * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY
15*df6ad731Slogwang * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16*df6ad731Slogwang * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17*df6ad731Slogwang * DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT BE LIABLE FOR
18*df6ad731Slogwang * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*df6ad731Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*df6ad731Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*df6ad731Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*df6ad731Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*df6ad731Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*df6ad731Slogwang * SUCH DAMAGE.
25*df6ad731Slogwang */
26*df6ad731Slogwang
27*df6ad731Slogwang #include <sys/cdefs.h>
28*df6ad731Slogwang #ifndef FSTACK
29*df6ad731Slogwang __FBSDID("$FreeBSD$");
30*df6ad731Slogwang #endif
31*df6ad731Slogwang
32*df6ad731Slogwang #include <sys/types.h>
33*df6ad731Slogwang #include <sys/sysctl.h>
34*df6ad731Slogwang #include <string.h>
35*df6ad731Slogwang
36*df6ad731Slogwang
37*df6ad731Slogwang /*
38*df6ad731Slogwang * This function uses a presently undocumented interface to the kernel
39*df6ad731Slogwang * to walk the tree and get the type so it can print the value.
40*df6ad731Slogwang * This interface is under work and consideration, and should probably
41*df6ad731Slogwang * be killed with a big axe by the first person who can find the time.
42*df6ad731Slogwang * (be aware though, that the proper interface isn't as obvious as it
43*df6ad731Slogwang * may seem, there are various conflicting requirements.
44*df6ad731Slogwang */
45*df6ad731Slogwang int
sysctlnametomib(const char * name,int * mibp,size_t * sizep)46*df6ad731Slogwang sysctlnametomib(const char *name, int *mibp, size_t *sizep)
47*df6ad731Slogwang {
48*df6ad731Slogwang int oid[2];
49*df6ad731Slogwang int error;
50*df6ad731Slogwang
51*df6ad731Slogwang oid[0] = 0;
52*df6ad731Slogwang oid[1] = 3;
53*df6ad731Slogwang
54*df6ad731Slogwang *sizep *= sizeof(int);
55*df6ad731Slogwang error = sysctl(oid, 2, mibp, sizep, name, strlen(name));
56*df6ad731Slogwang *sizep /= sizeof(int);
57*df6ad731Slogwang return (error);
58*df6ad731Slogwang }
59