171409Smckusick/* 271409Smckusick * Copyright 2001 The FreeBSD Project. All Rights Reserved. 371409Smckusick * 471409Smckusick * Redistribution and use in source and binary forms, with or without 571409Smckusick * modification, are permitted provided that the following conditions 671409Smckusick * are met: 771409Smckusick * 871409Smckusick * 1. Redistributions of source code must retain the above copyright 971409Smckusick * notice, this list of conditions and the following disclaimer. 1071409Smckusick * 2. Redistributions in binary form must reproduce the above copyright 1171409Smckusick * notice, this list of conditions and the following disclaimer in the 1271409Smckusick * documentation and/or other materials provided with the distribution. 1371409Smckusick * 1471409Smckusick * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY 1571409Smckusick * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1671409Smckusick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1771409Smckusick * DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT BE LIABLE FOR 1871409Smckusick * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1971409Smckusick * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2071409Smckusick * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2171409Smckusick * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2271409Smckusick * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2371409Smckusick * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2471409Smckusick * SUCH DAMAGE. 2571409Smckusick */ 2671409Smckusick 2790039Sobrien#include <sys/cdefs.h> 2890039Sobrien__FBSDID("$FreeBSD$"); 2990039Sobrien 3071409Smckusick#include <sys/types.h> 3171409Smckusick#include <sys/sysctl.h> 32108628Stjr#include <string.h> 3371409Smckusick 3471409Smckusick/* 3571409Smckusick * This function uses a presently undocumented interface to the kernel 3671409Smckusick * to walk the tree and get the type so it can print the value. 3771409Smckusick * This interface is under work and consideration, and should probably 3871409Smckusick * be killed with a big axe by the first person who can find the time. 3971409Smckusick * (be aware though, that the proper interface isn't as obvious as it 4071409Smckusick * may seem, there are various conflicting requirements. 4171409Smckusick */ 4271409Smckusickint 4371409Smckusicksysctlnametomib(const char *name, int *mibp, size_t *sizep) 4471409Smckusick{ 4571409Smckusick int oid[2]; 4671409Smckusick int error; 4771409Smckusick 4871409Smckusick oid[0] = 0; 4971409Smckusick oid[1] = 3; 5071409Smckusick 51204170Sed *sizep *= sizeof(int); 52204170Sed error = sysctl(oid, 2, mibp, sizep, name, strlen(name)); 53204170Sed *sizep /= sizeof(int); 5476748Sru return (error); 5571409Smckusick} 56