Home | History | Annotate | Line # | Download | only in sysctl
sysctl.c revision 1.65
      1  1.65     lukem /*	$NetBSD: sysctl.c,v 1.65 2003/04/06 05:19:03 lukem Exp $	*/
      2   1.9   thorpej 
      3   1.1       cgd /*
      4   1.1       cgd  * Copyright (c) 1993
      5   1.1       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.14  christos #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38  1.14  christos __COPYRIGHT(
     39   1.1       cgd "@(#) Copyright (c) 1993\n\
     40  1.14  christos 	The Regents of the University of California.  All rights reserved.\n");
     41   1.1       cgd #endif /* not lint */
     42   1.1       cgd 
     43   1.1       cgd #ifndef lint
     44   1.9   thorpej #if 0
     45   1.9   thorpej static char sccsid[] = "@(#)sysctl.c	8.1 (Berkeley) 6/6/93";
     46   1.9   thorpej #else
     47  1.65     lukem __RCSID("$NetBSD: sysctl.c,v 1.65 2003/04/06 05:19:03 lukem Exp $");
     48   1.9   thorpej #endif
     49   1.1       cgd #endif /* not lint */
     50   1.1       cgd 
     51   1.1       cgd #include <sys/param.h>
     52   1.1       cgd #include <sys/gmon.h>
     53   1.1       cgd #include <sys/stat.h>
     54   1.1       cgd #include <sys/sysctl.h>
     55   1.1       cgd #include <sys/socket.h>
     56  1.17   thorpej #include <sys/mount.h>
     57  1.19   thorpej #include <sys/mbuf.h>
     58  1.22    bouyer #include <sys/resource.h>
     59  1.38       mrg #include <uvm/uvm_param.h>
     60   1.1       cgd #include <machine/cpu.h>
     61   1.1       cgd 
     62  1.17   thorpej #include <ufs/ufs/dinode.h>
     63  1.17   thorpej #include <ufs/ufs/dir.h>
     64  1.17   thorpej #include <ufs/ffs/fs.h>
     65  1.17   thorpej #include <ufs/ffs/ffs_extern.h>
     66  1.17   thorpej 
     67  1.17   thorpej #include <nfs/rpcv2.h>
     68  1.17   thorpej #include <nfs/nfsproto.h>
     69  1.17   thorpej #include <nfs/nfs.h>
     70  1.17   thorpej 
     71   1.1       cgd #include <netinet/in.h>
     72   1.1       cgd #include <netinet/in_systm.h>
     73   1.1       cgd #include <netinet/ip.h>
     74   1.1       cgd #include <netinet/ip_icmp.h>
     75   1.1       cgd #include <netinet/icmp_var.h>
     76   1.1       cgd #include <netinet/ip_var.h>
     77   1.1       cgd #include <netinet/udp.h>
     78   1.1       cgd #include <netinet/udp_var.h>
     79   1.8   thorpej #include <netinet/tcp.h>
     80   1.8   thorpej #include <netinet/tcp_timer.h>
     81   1.8   thorpej #include <netinet/tcp_var.h>
     82   1.1       cgd 
     83  1.20    itojun #ifdef INET6
     84  1.24    itojun #include <netinet/ip6.h>
     85  1.24    itojun #include <netinet/icmp6.h>
     86  1.20    itojun #include <netinet6/ip6_var.h>
     87  1.20    itojun #include <netinet6/udp6.h>
     88  1.20    itojun #include <netinet6/udp6_var.h>
     89  1.20    itojun #ifdef TCP6
     90  1.20    itojun #include <netinet6/tcp6.h>
     91  1.20    itojun #include <netinet6/tcp6_timer.h>
     92  1.20    itojun #include <netinet6/tcp6_var.h>
     93  1.20    itojun #endif
     94  1.20    itojun #include <netinet6/pim6_var.h>
     95  1.20    itojun #endif /* INET6 */
     96  1.20    itojun 
     97  1.56  christos #include "../../sys/compat/linux/common/linux_exec.h"
     98  1.60      manu #include "../../sys/compat/irix/irix_sysctl.h"
     99  1.62      manu #include "../../sys/compat/darwin/darwin_sysctl.h"
    100  1.56  christos 
    101  1.20    itojun #ifdef IPSEC
    102  1.20    itojun #include <net/route.h>
    103  1.20    itojun #include <netinet6/ipsec.h>
    104  1.20    itojun #include <netkey/key_var.h>
    105  1.20    itojun #endif /* IPSEC */
    106  1.48  jdolecek 
    107  1.48  jdolecek #include <sys/pipe.h>
    108  1.20    itojun 
    109  1.14  christos #include <err.h>
    110  1.14  christos #include <ctype.h>
    111   1.1       cgd #include <errno.h>
    112   1.1       cgd #include <stdio.h>
    113   1.1       cgd #include <stdlib.h>
    114   1.1       cgd #include <string.h>
    115  1.15      tron #include <unistd.h>
    116   1.1       cgd 
    117   1.1       cgd struct ctlname topname[] = CTL_NAMES;
    118   1.1       cgd struct ctlname kernname[] = CTL_KERN_NAMES;
    119   1.1       cgd struct ctlname vmname[] = CTL_VM_NAMES;
    120  1.17   thorpej struct ctlname vfsname[] = CTL_VFS_NAMES;
    121   1.1       cgd struct ctlname netname[] = CTL_NET_NAMES;
    122   1.1       cgd struct ctlname hwname[] = CTL_HW_NAMES;
    123   1.1       cgd struct ctlname username[] = CTL_USER_NAMES;
    124  1.10   thorpej struct ctlname ddbname[] = CTL_DDB_NAMES;
    125   1.1       cgd struct ctlname debugname[CTL_DEBUG_MAXID];
    126   1.1       cgd #ifdef CTL_MACHDEP_NAMES
    127   1.1       cgd struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
    128   1.1       cgd #endif
    129  1.56  christos struct ctlname emulname[] = CTL_EMUL_NAMES;
    130  1.56  christos struct ctlname vendorname[] = { { 0, 0 } };
    131  1.56  christos 
    132  1.22    bouyer /* this one is dummy, it's used only for '-a' or '-A' */
    133  1.22    bouyer struct ctlname procname[] = { {0, 0}, {"curproc", CTLTYPE_NODE} };
    134  1.22    bouyer 
    135   1.1       cgd char names[BUFSIZ];
    136   1.1       cgd 
    137   1.1       cgd struct list {
    138   1.1       cgd 	struct	ctlname *list;
    139   1.1       cgd 	int	size;
    140   1.1       cgd };
    141   1.1       cgd struct list toplist = { topname, CTL_MAXID };
    142   1.1       cgd struct list secondlevel[] = {
    143   1.1       cgd 	{ 0, 0 },			/* CTL_UNSPEC */
    144   1.1       cgd 	{ kernname, KERN_MAXID },	/* CTL_KERN */
    145   1.1       cgd 	{ vmname, VM_MAXID },		/* CTL_VM */
    146  1.17   thorpej 	{ vfsname, VFS_MAXID },		/* CTL_VFS */
    147   1.1       cgd 	{ netname, NET_MAXID },		/* CTL_NET */
    148   1.1       cgd 	{ 0, CTL_DEBUG_MAXID },		/* CTL_DEBUG */
    149   1.1       cgd 	{ hwname, HW_MAXID },		/* CTL_HW */
    150   1.1       cgd #ifdef CTL_MACHDEP_NAMES
    151   1.1       cgd 	{ machdepname, CPU_MAXID },	/* CTL_MACHDEP */
    152   1.1       cgd #else
    153   1.1       cgd 	{ 0, 0 },			/* CTL_MACHDEP */
    154   1.1       cgd #endif
    155   1.1       cgd 	{ username, USER_MAXID },	/* CTL_USER_NAMES */
    156  1.10   thorpej 	{ ddbname, DDBCTL_MAXID },	/* CTL_DDB_NAMES */
    157  1.22    bouyer 	{ procname, 2 },		/* dummy name */
    158  1.56  christos 	{ vendorname, 0 },		/* CTL_VENDOR_NAMES */
    159  1.56  christos 	{ emulname, EMUL_MAXID },	/* CTL_EMUL_NAMES */
    160  1.56  christos 
    161  1.43      fvdl 	{ 0, 0},
    162   1.1       cgd };
    163   1.1       cgd 
    164  1.58  sommerfe int	Aflag, aflag, nflag, qflag, wflag;
    165  1.65     lukem FILE	*warnfp = stderr;
    166   1.1       cgd 
    167   1.1       cgd /*
    168   1.1       cgd  * Variables requiring special processing.
    169   1.1       cgd  */
    170   1.1       cgd #define	CLOCK		0x00000001
    171   1.1       cgd #define	BOOTTIME	0x00000002
    172   1.1       cgd #define	CONSDEV		0x00000004
    173  1.32    simonb #define	DISKINFO	0x00000008
    174  1.32    simonb #define	CPTIME		0x00000010
    175   1.1       cgd 
    176  1.22    bouyer /*
    177  1.22    bouyer  * A dummy type for limits, which requires special parsing
    178  1.22    bouyer  */
    179  1.22    bouyer #define CTLTYPE_LIMIT	((~0x1) << 31)
    180  1.22    bouyer 
    181  1.53    simonb int main(int, char *[]);
    182  1.14  christos 
    183  1.53    simonb static void listall(const char *, struct list *);
    184  1.53    simonb static void parse(char *, int);
    185  1.53    simonb static void debuginit(void);
    186  1.53    simonb static int sysctl_inet(char *, char **, int[], int, int *);
    187  1.20    itojun #ifdef INET6
    188  1.53    simonb static int sysctl_inet6(char *, char **, int[], int, int *);
    189  1.20    itojun #endif
    190  1.53    simonb static int sysctl_vfs(char *, char **, int[], int, int *);
    191  1.53    simonb static int sysctl_proc(char *, char **, int[], int, int *);
    192  1.56  christos static int sysctl_3rd(struct list *, char *, char **, int[], int, int *);
    193  1.56  christos 
    194  1.56  christos #ifdef IPSEC
    195  1.56  christos struct ctlname keynames[] = KEYCTL_NAMES;
    196  1.56  christos struct list keyvars = { keynames, KEYCTL_MAXID };
    197  1.56  christos #endif /*IPSEC*/
    198  1.56  christos struct ctlname vfsgenname[] = CTL_VFSGENCTL_NAMES;
    199  1.56  christos struct list vfsgenvars = { vfsgenname, VFSGEN_MAXID };
    200  1.56  christos struct ctlname mbufnames[] = CTL_MBUF_NAMES;
    201  1.56  christos struct list mbufvars = { mbufnames, MBUF_MAXID };
    202  1.56  christos struct ctlname pipenames[] = CTL_PIPE_NAMES;
    203  1.56  christos struct list pipevars = { pipenames, KERN_PIPE_MAXID };
    204  1.56  christos struct ctlname tkstatnames[] = KERN_TKSTAT_NAMES;
    205  1.56  christos struct list tkstatvars = { tkstatnames, KERN_TKSTAT_MAXID };
    206  1.56  christos 
    207  1.56  christos static int sysctl_linux(char *, char **, int[], int, int *);
    208  1.60      manu static int sysctl_irix(char *, char **, int[], int, int *);
    209  1.62      manu static int sysctl_darwin(char *, char **, int[], int, int *);
    210  1.53    simonb static int findname(char *, char *, char **, struct list *);
    211  1.53    simonb static void usage(void);
    212  1.14  christos 
    213  1.55  christos #define USEAPP(s, a) \
    214  1.65     lukem     if (flags) fprintf(warnfp, "%s: use '%s' to view this information\n", s, a)
    215  1.50     lukem 
    216  1.50     lukem 
    217   1.1       cgd int
    218  1.53    simonb main(int argc, char *argv[])
    219   1.1       cgd {
    220  1.27    tsarna 	char *fn = NULL;
    221   1.1       cgd 	int ch, lvl1;
    222   1.1       cgd 
    223  1.58  sommerfe 	while ((ch = getopt(argc, argv, "Aaf:nqw")) != -1) {
    224   1.1       cgd 		switch (ch) {
    225   1.1       cgd 
    226   1.1       cgd 		case 'A':
    227   1.1       cgd 			Aflag = 1;
    228   1.1       cgd 			break;
    229   1.1       cgd 
    230   1.1       cgd 		case 'a':
    231   1.1       cgd 			aflag = 1;
    232   1.1       cgd 			break;
    233   1.1       cgd 
    234  1.27    tsarna 		case 'f':
    235  1.27    tsarna 			fn = optarg;
    236  1.27    tsarna 			wflag = 1;
    237  1.27    tsarna 			break;
    238  1.27    tsarna 
    239   1.1       cgd 		case 'n':
    240   1.1       cgd 			nflag = 1;
    241   1.1       cgd 			break;
    242   1.1       cgd 
    243  1.58  sommerfe 		case 'q':
    244  1.58  sommerfe 			qflag = 1;
    245  1.58  sommerfe 			break;
    246  1.58  sommerfe 
    247   1.1       cgd 		case 'w':
    248   1.1       cgd 			wflag = 1;
    249   1.1       cgd 			break;
    250   1.1       cgd 
    251   1.1       cgd 		default:
    252   1.1       cgd 			usage();
    253   1.1       cgd 		}
    254   1.1       cgd 	}
    255  1.58  sommerfe 
    256  1.58  sommerfe 	if (qflag && !wflag)
    257  1.58  sommerfe 		usage();
    258  1.58  sommerfe 
    259   1.1       cgd 	argc -= optind;
    260   1.1       cgd 	argv += optind;
    261   1.1       cgd 
    262   1.1       cgd 	if (Aflag || aflag) {
    263  1.65     lukem 		warnfp = stdout;
    264   1.1       cgd 		debuginit();
    265   1.1       cgd 		for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
    266   1.1       cgd 			listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
    267  1.14  christos 		return 0;
    268   1.1       cgd 	}
    269  1.27    tsarna 
    270  1.27    tsarna 	if (fn) {
    271  1.27    tsarna 		FILE *fp;
    272  1.27    tsarna 		char *l;
    273  1.58  sommerfe 
    274  1.27    tsarna 		fp = fopen(fn, "r");
    275  1.27    tsarna 		if (fp == NULL) {
    276  1.27    tsarna 			err(1, "%s", fn);
    277  1.27    tsarna 		} else {
    278  1.41     enami 			for (; (l = fparseln(fp, NULL, NULL, NULL, 0)) != NULL;
    279  1.41     enami 			    free(l)) {
    280  1.41     enami 				if (*l)
    281  1.27    tsarna 					parse(l, 1);
    282  1.27    tsarna 			}
    283  1.27    tsarna 			fclose(fp);
    284  1.27    tsarna 		}
    285  1.27    tsarna 	} else {
    286  1.27    tsarna 		if (argc == 0)
    287  1.27    tsarna 			usage();
    288  1.27    tsarna 		while (argc-- > 0)
    289  1.27    tsarna 			parse(*argv++, 1);
    290  1.27    tsarna 	}
    291  1.14  christos 	return 0;
    292   1.1       cgd }
    293   1.1       cgd 
    294   1.1       cgd /*
    295   1.1       cgd  * List all variables known to the system.
    296   1.1       cgd  */
    297  1.14  christos static void
    298  1.53    simonb listall(const char *prefix, struct list *lp)
    299   1.1       cgd {
    300   1.1       cgd 	int lvl2;
    301   1.1       cgd 	char *cp, name[BUFSIZ];
    302   1.1       cgd 
    303   1.1       cgd 	if (lp->list == 0)
    304   1.1       cgd 		return;
    305   1.1       cgd 	strcpy(name, prefix);
    306   1.1       cgd 	cp = &name[strlen(name)];
    307   1.1       cgd 	*cp++ = '.';
    308   1.1       cgd 	for (lvl2 = 0; lvl2 < lp->size; lvl2++) {
    309   1.1       cgd 		if (lp->list[lvl2].ctl_name == 0)
    310   1.1       cgd 			continue;
    311   1.1       cgd 		strcpy(cp, lp->list[lvl2].ctl_name);
    312   1.1       cgd 		parse(name, Aflag);
    313   1.1       cgd 	}
    314   1.1       cgd }
    315   1.1       cgd 
    316   1.1       cgd /*
    317   1.1       cgd  * Parse a name into a MIB entry.
    318   1.1       cgd  * Lookup and print out the MIB entry if it exists.
    319   1.1       cgd  * Set a new value if requested.
    320   1.1       cgd  */
    321  1.14  christos static void
    322  1.53    simonb parse(char *string, int flags)
    323   1.1       cgd {
    324   1.5       cgd 	int indx, type, state, len;
    325   1.1       cgd 	int special = 0;
    326   1.1       cgd 	void *newval = 0;
    327   1.1       cgd 	int intval, newsize = 0;
    328   1.1       cgd 	quad_t quadval;
    329   1.5       cgd 	size_t size;
    330   1.1       cgd 	struct list *lp;
    331   1.1       cgd 	int mib[CTL_MAXNAME];
    332  1.14  christos 	char *cp, *bufp, buf[BUFSIZ];
    333  1.46       chs 	double loads[3];
    334   1.1       cgd 
    335   1.1       cgd 	bufp = buf;
    336   1.1       cgd 	snprintf(buf, BUFSIZ, "%s", string);
    337   1.1       cgd 	if ((cp = strchr(string, '=')) != NULL) {
    338  1.14  christos 		if (!wflag)
    339  1.14  christos 			errx(2, "Must specify -w to set variables");
    340   1.1       cgd 		*strchr(buf, '=') = '\0';
    341   1.1       cgd 		*cp++ = '\0';
    342  1.14  christos 		while (isspace((unsigned char) *cp))
    343   1.1       cgd 			cp++;
    344   1.1       cgd 		newval = cp;
    345   1.1       cgd 		newsize = strlen(cp);
    346   1.1       cgd 	}
    347   1.1       cgd 	if ((indx = findname(string, "top", &bufp, &toplist)) == -1)
    348   1.1       cgd 		return;
    349   1.1       cgd 	mib[0] = indx;
    350   1.1       cgd 	if (indx == CTL_DEBUG)
    351   1.1       cgd 		debuginit();
    352  1.22    bouyer 	if (mib[0] == CTL_PROC) {
    353  1.22    bouyer 		type = CTLTYPE_NODE;
    354  1.22    bouyer 		len = 1;
    355  1.22    bouyer 	} else {
    356  1.22    bouyer 		lp = &secondlevel[indx];
    357  1.22    bouyer 		if (lp->list == 0) {
    358  1.22    bouyer 			warnx("Class `%s' is not implemented",
    359  1.50     lukem 			    topname[indx].ctl_name);
    360  1.22    bouyer 			return;
    361  1.22    bouyer 		}
    362  1.22    bouyer 		if (bufp == NULL) {
    363  1.22    bouyer 			listall(topname[indx].ctl_name, lp);
    364  1.22    bouyer 			return;
    365  1.22    bouyer 		}
    366  1.22    bouyer 		if ((indx = findname(string, "second", &bufp, lp)) == -1)
    367  1.22    bouyer 			return;
    368  1.22    bouyer 		mib[1] = indx;
    369  1.22    bouyer 		type = lp->list[indx].ctl_type;
    370  1.22    bouyer 		len = 2;
    371   1.1       cgd 	}
    372   1.1       cgd 	switch (mib[0]) {
    373   1.1       cgd 
    374   1.1       cgd 	case CTL_KERN:
    375   1.1       cgd 		switch (mib[1]) {
    376   1.1       cgd 		case KERN_PROF:
    377   1.1       cgd 			mib[2] = GPROF_STATE;
    378   1.1       cgd 			size = sizeof state;
    379   1.1       cgd 			if (sysctl(mib, 3, &state, &size, NULL, 0) < 0) {
    380   1.1       cgd 				if (flags == 0)
    381   1.1       cgd 					return;
    382   1.1       cgd 				if (!nflag)
    383  1.65     lukem 					fprintf(warnfp, "%s: ", string);
    384  1.65     lukem 				fprintf(warnfp,
    385  1.50     lukem 				    "kernel is not compiled for profiling\n");
    386   1.1       cgd 				return;
    387   1.1       cgd 			}
    388   1.1       cgd 			if (!nflag)
    389  1.33    simonb 				printf("%s: %s\n", string,
    390   1.1       cgd 				    state == GMON_PROF_OFF ? "off" : "running");
    391   1.1       cgd 			return;
    392   1.1       cgd 		case KERN_VNODE:
    393   1.1       cgd 		case KERN_FILE:
    394  1.50     lukem 			USEAPP(string, "pstat");
    395   1.1       cgd 			return;
    396   1.1       cgd 		case KERN_PROC:
    397  1.32    simonb 		case KERN_PROC2:
    398  1.34    simonb 		case KERN_PROC_ARGS:
    399  1.50     lukem 			USEAPP(string, "ps");
    400   1.1       cgd 			return;
    401   1.1       cgd 		case KERN_CLOCKRATE:
    402   1.1       cgd 			special |= CLOCK;
    403   1.1       cgd 			break;
    404   1.1       cgd 		case KERN_BOOTTIME:
    405   1.1       cgd 			special |= BOOTTIME;
    406   1.1       cgd 			break;
    407  1.12  jonathan 		case KERN_NTPTIME:
    408  1.50     lukem 			USEAPP(string, "ntpdc -c kerninfo");
    409  1.12  jonathan 			return;
    410  1.19   thorpej 		case KERN_MBUF:
    411  1.56  christos 			len = sysctl_3rd(&mbufvars, string, &bufp, mib, flags,
    412  1.56  christos 			    &type);
    413  1.19   thorpej 			if (len < 0)
    414  1.19   thorpej 				return;
    415  1.19   thorpej 			break;
    416  1.32    simonb 		case KERN_CP_TIME:
    417  1.32    simonb 			special |= CPTIME;
    418  1.40    simonb 			break;
    419  1.40    simonb 		case KERN_MSGBUF:
    420  1.50     lukem 			USEAPP(string, "dmesg");
    421  1.40    simonb 			return;
    422  1.40    simonb 		case KERN_CONSDEV:
    423  1.40    simonb 			special |= CONSDEV;
    424  1.32    simonb 			break;
    425  1.47  jdolecek 		case KERN_PIPE:
    426  1.56  christos 			len = sysctl_3rd(&pipevars, string, &bufp, mib, flags,
    427  1.56  christos 			    &type);
    428  1.47  jdolecek 			if (len < 0)
    429  1.47  jdolecek 				return;
    430  1.47  jdolecek 			break;
    431  1.54    simonb 		case KERN_TKSTAT:
    432  1.56  christos 			len = sysctl_3rd(&tkstatvars, string, &bufp, mib, flags,
    433  1.56  christos 			    &type);
    434  1.54    simonb 			if (len < 0)
    435  1.54    simonb 				return;
    436  1.54    simonb 			break;
    437   1.1       cgd 		}
    438   1.1       cgd 		break;
    439   1.1       cgd 
    440   1.1       cgd 	case CTL_HW:
    441  1.51    simonb 		switch (mib[1]) {
    442  1.51    simonb 		case HW_DISKSTATS:
    443  1.51    simonb 			USEAPP(string, "iostat");
    444  1.51    simonb 			return;
    445  1.51    simonb 		}
    446   1.1       cgd 		break;
    447   1.1       cgd 
    448   1.1       cgd 	case CTL_VM:
    449  1.46       chs 		switch (mib[1]) {
    450  1.46       chs 		case VM_LOADAVG:
    451   1.1       cgd 			getloadavg(loads, 3);
    452   1.1       cgd 			if (!nflag)
    453  1.33    simonb 				printf("%s: ", string);
    454  1.33    simonb 			printf("%.2f %.2f %.2f\n", loads[0], loads[1],
    455  1.33    simonb 			    loads[2]);
    456   1.1       cgd 			return;
    457  1.46       chs 
    458  1.46       chs 		case VM_METER:
    459  1.46       chs 		case VM_UVMEXP:
    460  1.46       chs 		case VM_UVMEXP2:
    461  1.55  christos 			USEAPP(string, "vmstat' or 'systat");
    462  1.46       chs 			return;
    463   1.1       cgd 		}
    464  1.46       chs 		break;
    465   1.1       cgd 
    466   1.1       cgd 	case CTL_NET:
    467   1.1       cgd 		if (mib[1] == PF_INET) {
    468   1.1       cgd 			len = sysctl_inet(string, &bufp, mib, flags, &type);
    469   1.1       cgd 			if (len >= 0)
    470   1.1       cgd 				break;
    471   1.1       cgd 			return;
    472   1.1       cgd 		}
    473  1.20    itojun #ifdef INET6
    474  1.20    itojun 		else if (mib[1] == PF_INET6) {
    475  1.20    itojun 			len = sysctl_inet6(string, &bufp, mib, flags, &type);
    476  1.20    itojun 			if (len >= 0)
    477  1.20    itojun 				break;
    478  1.20    itojun 			return;
    479  1.20    itojun 		}
    480  1.20    itojun #endif /* INET6 */
    481  1.20    itojun #ifdef IPSEC
    482  1.20    itojun 		else if (mib[1] == PF_KEY) {
    483  1.56  christos 			len = sysctl_3rd(&keyvars, string, &bufp, mib, flags,
    484  1.56  christos 			    &type);
    485  1.20    itojun 			if (len >= 0)
    486  1.20    itojun 				break;
    487  1.20    itojun 			return;
    488  1.20    itojun 		}
    489  1.20    itojun #endif /* IPSEC */
    490   1.1       cgd 		if (flags == 0)
    491   1.1       cgd 			return;
    492  1.50     lukem 		USEAPP(string, "netstat");
    493   1.1       cgd 		return;
    494   1.1       cgd 
    495   1.1       cgd 	case CTL_DEBUG:
    496   1.1       cgd 		mib[2] = CTL_DEBUG_VALUE;
    497   1.1       cgd 		len = 3;
    498   1.1       cgd 		break;
    499   1.1       cgd 
    500   1.1       cgd 	case CTL_MACHDEP:
    501   1.1       cgd #ifdef CPU_CONSDEV
    502   1.1       cgd 		if (mib[1] == CPU_CONSDEV)
    503   1.1       cgd 			special |= CONSDEV;
    504   1.1       cgd #endif
    505  1.26      fvdl #ifdef CPU_DISKINFO
    506  1.26      fvdl 		if (mib[1] == CPU_DISKINFO)
    507  1.26      fvdl 			special |= DISKINFO;
    508  1.26      fvdl #endif
    509   1.1       cgd 		break;
    510   1.1       cgd 
    511  1.13      fvdl 	case CTL_VFS:
    512  1.56  christos 		if (mib[1] == VFS_GENERIC) {
    513  1.56  christos 			len = sysctl_3rd(&vfsgenvars, string, &bufp, mib, flags,
    514  1.56  christos 			    &type);
    515  1.56  christos 			/* Don't bother with VFS_CONF. */
    516  1.56  christos 			if (mib[2] == VFS_CONF)
    517  1.56  christos 				len = -1;
    518  1.56  christos 		} else
    519  1.17   thorpej 			len = sysctl_vfs(string, &bufp, mib, flags, &type);
    520  1.18   thorpej 		if (len < 0)
    521  1.18   thorpej 			return;
    522  1.18   thorpej 
    523  1.18   thorpej 		/* XXX Special-case for NFS stats. */
    524  1.18   thorpej 		if (mib[1] == 2 && mib[2] == NFS_NFSSTATS) {
    525  1.50     lukem 			USEAPP(string, "nfsstat");
    526  1.18   thorpej 			return;
    527  1.18   thorpej 		}
    528  1.18   thorpej 		break;
    529  1.17   thorpej 
    530  1.43      fvdl 	case CTL_VENDOR:
    531   1.1       cgd 	case CTL_USER:
    532  1.10   thorpej 	case CTL_DDB:
    533   1.1       cgd 		break;
    534  1.22    bouyer 	case CTL_PROC:
    535  1.22    bouyer 		len = sysctl_proc(string, &bufp, mib, flags, &type);
    536  1.22    bouyer 		if (len < 0)
    537  1.22    bouyer 			return;
    538  1.22    bouyer 		break;
    539  1.56  christos 	case CTL_EMUL:
    540  1.56  christos 		switch (mib[1]) {
    541  1.60      manu 		case EMUL_IRIX:
    542  1.60      manu 		    len = sysctl_irix(string, &bufp, mib, flags, &type);
    543  1.60      manu 		    break;
    544  1.62      manu 
    545  1.56  christos 		case EMUL_LINUX:
    546  1.56  christos 		    len = sysctl_linux(string, &bufp, mib, flags, &type);
    547  1.56  christos 		    break;
    548  1.62      manu 
    549  1.62      manu 		case EMUL_DARWIN:
    550  1.62      manu 		    len = sysctl_darwin(string, &bufp, mib, flags, &type);
    551  1.62      manu 		    break;
    552  1.62      manu 
    553  1.56  christos 		default:
    554  1.56  christos 		    warnx("Illegal emul level value: %d", mib[0]);
    555  1.56  christos 		    break;
    556  1.56  christos 		}
    557  1.56  christos 		if (len < 0)
    558  1.56  christos 			return;
    559  1.56  christos 		break;
    560   1.1       cgd 	default:
    561  1.14  christos 		warnx("Illegal top level value: %d", mib[0]);
    562   1.1       cgd 		return;
    563  1.58  sommerfe 
    564   1.1       cgd 	}
    565   1.1       cgd 	if (bufp) {
    566  1.14  christos 		warnx("Name %s in %s is unknown", bufp, string);
    567   1.1       cgd 		return;
    568   1.1       cgd 	}
    569   1.1       cgd 	if (newsize > 0) {
    570   1.1       cgd 		switch (type) {
    571   1.1       cgd 		case CTLTYPE_INT:
    572   1.1       cgd 			intval = atoi(newval);
    573   1.1       cgd 			newval = &intval;
    574   1.1       cgd 			newsize = sizeof intval;
    575   1.1       cgd 			break;
    576   1.1       cgd 
    577  1.22    bouyer 		case CTLTYPE_LIMIT:
    578  1.22    bouyer 			if (strcmp(newval, "unlimited") == 0) {
    579  1.22    bouyer 				quadval = RLIM_INFINITY;
    580  1.22    bouyer 				newval = &quadval;
    581  1.22    bouyer 				newsize = sizeof quadval;
    582  1.22    bouyer 				break;
    583  1.22    bouyer 			}
    584  1.22    bouyer 			/* FALLTHROUGH */
    585   1.1       cgd 		case CTLTYPE_QUAD:
    586  1.42     lukem 			sscanf(newval, "%lld", (long long *)&quadval);
    587   1.1       cgd 			newval = &quadval;
    588   1.1       cgd 			newsize = sizeof quadval;
    589   1.1       cgd 			break;
    590   1.1       cgd 		}
    591   1.1       cgd 	}
    592   1.1       cgd 	size = BUFSIZ;
    593   1.1       cgd 	if (sysctl(mib, len, buf, &size, newsize ? newval : 0, newsize) == -1) {
    594   1.1       cgd 		if (flags == 0)
    595   1.1       cgd 			return;
    596   1.1       cgd 		switch (errno) {
    597   1.1       cgd 		case EOPNOTSUPP:
    598  1.65     lukem 			fprintf(warnfp,
    599  1.65     lukem 			    "%s: the value is not available\n", string);
    600   1.1       cgd 			return;
    601   1.1       cgd 		case ENOTDIR:
    602  1.65     lukem 			fprintf(warnfp,
    603  1.65     lukem 			    "%s: the specification is incomplete\n", string);
    604   1.1       cgd 			return;
    605   1.1       cgd 		case ENOMEM:
    606  1.65     lukem 			fprintf(warnfp,
    607  1.65     lukem 			    "%s: this type is unknown to this program\n",
    608   1.1       cgd 			    string);
    609   1.1       cgd 			return;
    610   1.1       cgd 		default:
    611  1.65     lukem 			fprintf(warnfp, "%s: sysctl() failed with %s\n",
    612  1.50     lukem 			    string, strerror(errno));
    613   1.1       cgd 			return;
    614   1.1       cgd 		}
    615   1.1       cgd 	}
    616  1.58  sommerfe 	if (qflag && (newsize > 0))
    617  1.58  sommerfe 		return;
    618   1.1       cgd 	if (special & CLOCK) {
    619   1.1       cgd 		struct clockinfo *clkp = (struct clockinfo *)buf;
    620   1.1       cgd 
    621   1.1       cgd 		if (!nflag)
    622  1.33    simonb 			printf("%s: ", string);
    623  1.33    simonb 		printf(
    624   1.4   mycroft 		    "tick = %d, tickadj = %d, hz = %d, profhz = %d, stathz = %d\n",
    625   1.4   mycroft 		    clkp->tick, clkp->tickadj, clkp->hz, clkp->profhz, clkp->stathz);
    626   1.1       cgd 		return;
    627   1.1       cgd 	}
    628   1.1       cgd 	if (special & BOOTTIME) {
    629   1.1       cgd 		struct timeval *btp = (struct timeval *)buf;
    630   1.7       cgd 		time_t boottime;
    631   1.1       cgd 
    632   1.7       cgd 		if (!nflag) {
    633   1.7       cgd 			boottime = btp->tv_sec;
    634  1.31    simonb 			/* ctime() provides the trailing newline */
    635  1.33    simonb 			printf("%s = %s", string, ctime(&boottime));
    636   1.7       cgd 		} else
    637  1.33    simonb 			printf("%ld\n", (long) btp->tv_sec);
    638   1.1       cgd 		return;
    639   1.1       cgd 	}
    640   1.1       cgd 	if (special & CONSDEV) {
    641   1.1       cgd 		dev_t dev = *(dev_t *)buf;
    642   1.1       cgd 
    643   1.1       cgd 		if (!nflag)
    644  1.33    simonb 			printf("%s = %s\n", string, devname(dev, S_IFCHR));
    645   1.1       cgd 		else
    646  1.33    simonb 			printf("0x%x\n", dev);
    647   1.1       cgd 		return;
    648   1.1       cgd 	}
    649  1.26      fvdl 	if (special & DISKINFO) {
    650  1.63       dsl #ifdef CPU_DISKINFO
    651  1.26      fvdl 		/* Don't know a good way to deal with this i386 specific one */
    652  1.63       dsl 		/* OTOH this does pass the info out... */
    653  1.63       dsl 		struct disklist *dl = (void *)buf;
    654  1.63       dsl 		struct biosdisk_info *bi;
    655  1.63       dsl 		struct nativedisk_info *ni;
    656  1.63       dsl 		uint i, b, lim;
    657  1.63       dsl 		if (!nflag)
    658  1.63       dsl 			printf("%s: ", string);
    659  1.63       dsl 		lim = dl->dl_nbiosdisks;
    660  1.63       dsl 		if (lim > MAX_BIOSDISKS)
    661  1.63       dsl 			lim = MAX_BIOSDISKS;
    662  1.63       dsl 		for (bi = dl->dl_biosdisks, i = 0; i < lim; bi++, i++)
    663  1.63       dsl 			printf("%x:%lld(%d/%d/%d),%x ",
    664  1.64      fvdl 				bi->bi_dev, (long long)bi->bi_lbasecs,
    665  1.64      fvdl 				bi->bi_cyl, bi->bi_head, bi->bi_sec,
    666  1.64      fvdl 				bi->bi_flags);
    667  1.63       dsl 		lim = dl->dl_nnativedisks;
    668  1.63       dsl 		ni = dl->dl_nativedisks;
    669  1.63       dsl 		bi = dl->dl_biosdisks;
    670  1.63       dsl 		if ((char *)&ni[lim] != (char *)buf + size) {
    671  1.65     lukem 			fprintf(warnfp, "size mismatch\n");
    672  1.63       dsl 			return;
    673  1.63       dsl 		}
    674  1.63       dsl 		for (i = 0; i < lim; ni++, i++) {
    675  1.63       dsl 			char sep = ':';
    676  1.63       dsl 			printf(" %.*s", (int)sizeof ni->ni_devname,
    677  1.63       dsl 				ni->ni_devname);
    678  1.63       dsl 			for (b = 0; b < ni->ni_nmatches; sep = ',', b++)
    679  1.63       dsl 				printf("%c%x", sep,
    680  1.63       dsl 					bi[ni->ni_biosmatches[b]].bi_dev);
    681  1.63       dsl 		}
    682  1.63       dsl 		printf("\n");
    683  1.63       dsl #endif
    684  1.32    simonb 		return;
    685  1.32    simonb 	}
    686  1.32    simonb 	if (special & CPTIME) {
    687  1.35    simonb 		u_int64_t *cp_time = (u_int64_t *)buf;
    688  1.32    simonb 
    689  1.32    simonb 		if (!nflag)
    690  1.33    simonb 			printf("%s: ", string);
    691  1.36      matt 		printf("user = %llu, nice = %llu, sys = %llu, intr = %llu, "
    692  1.36      matt 		    "idle = %llu\n", (unsigned long long) cp_time[0],
    693  1.36      matt 		    (unsigned long long) cp_time[1],
    694  1.36      matt 		    (unsigned long long) cp_time[2],
    695  1.36      matt 		    (unsigned long long) cp_time[3],
    696  1.36      matt 		    (unsigned long long) cp_time[4]);
    697  1.26      fvdl 		return;
    698  1.26      fvdl 	}
    699  1.58  sommerfe 
    700   1.1       cgd 	switch (type) {
    701   1.1       cgd 	case CTLTYPE_INT:
    702   1.1       cgd 		if (newsize == 0) {
    703   1.1       cgd 			if (!nflag)
    704  1.33    simonb 				printf("%s = ", string);
    705  1.33    simonb 			printf("%d\n", *(int *)buf);
    706   1.1       cgd 		} else {
    707   1.1       cgd 			if (!nflag)
    708  1.33    simonb 				printf("%s: %d -> ", string, *(int *)buf);
    709  1.33    simonb 			printf("%d\n", *(int *)newval);
    710   1.1       cgd 		}
    711   1.1       cgd 		return;
    712   1.1       cgd 
    713   1.1       cgd 	case CTLTYPE_STRING:
    714  1.59    simonb 		/* If sysctl() didn't return any data, don't print a string. */
    715  1.59    simonb 		if (size == 0)
    716  1.59    simonb 			buf[0] = '\0';
    717   1.1       cgd 		if (newsize == 0) {
    718   1.1       cgd 			if (!nflag)
    719  1.33    simonb 				printf("%s = ", string);
    720  1.33    simonb 			printf("%s\n", buf);
    721   1.1       cgd 		} else {
    722   1.1       cgd 			if (!nflag)
    723  1.33    simonb 				printf("%s: %s -> ", string, buf);
    724  1.33    simonb 			printf("%s\n", (char *) newval);
    725   1.1       cgd 		}
    726   1.1       cgd 		return;
    727   1.1       cgd 
    728  1.22    bouyer 	case CTLTYPE_LIMIT:
    729  1.22    bouyer #define PRINTF_LIMIT(lim) { \
    730  1.22    bouyer if ((lim) == RLIM_INFINITY) \
    731  1.33    simonb 	printf("unlimited");\
    732  1.22    bouyer else \
    733  1.42     lukem 	printf("%lld", (long long)(lim)); \
    734  1.22    bouyer }
    735  1.22    bouyer 
    736  1.22    bouyer 		if (newsize == 0) {
    737  1.22    bouyer 			if (!nflag)
    738  1.33    simonb 				printf("%s = ", string);
    739  1.22    bouyer 			PRINTF_LIMIT((long long)(*(quad_t *)buf));
    740  1.22    bouyer 		} else {
    741  1.22    bouyer 			if (!nflag) {
    742  1.33    simonb 				printf("%s: ", string);
    743  1.22    bouyer 				PRINTF_LIMIT((long long)(*(quad_t *)buf));
    744  1.33    simonb 				printf(" -> ");
    745  1.22    bouyer 			}
    746  1.22    bouyer 			PRINTF_LIMIT((long long)(*(quad_t *)newval));
    747  1.22    bouyer 		}
    748  1.33    simonb 		printf("\n");
    749  1.22    bouyer 		return;
    750  1.22    bouyer #undef PRINTF_LIMIT
    751  1.22    bouyer 
    752   1.1       cgd 	case CTLTYPE_QUAD:
    753   1.1       cgd 		if (newsize == 0) {
    754   1.1       cgd 			if (!nflag)
    755  1.33    simonb 				printf("%s = ", string);
    756  1.42     lukem 			printf("%lld\n", (long long)(*(quad_t *)buf));
    757   1.1       cgd 		} else {
    758   1.1       cgd 			if (!nflag)
    759  1.42     lukem 				printf("%s: %lld -> ", string,
    760  1.16   thorpej 				    (long long)(*(quad_t *)buf));
    761  1.42     lukem 			printf("%lld\n", (long long)(*(quad_t *)newval));
    762   1.1       cgd 		}
    763   1.1       cgd 		return;
    764   1.1       cgd 
    765   1.1       cgd 	case CTLTYPE_STRUCT:
    766  1.14  christos 		warnx("%s: unknown structure returned", string);
    767   1.1       cgd 		return;
    768   1.1       cgd 
    769   1.1       cgd 	default:
    770   1.1       cgd 	case CTLTYPE_NODE:
    771  1.14  christos 		warnx("%s: unknown type returned", string);
    772   1.1       cgd 		return;
    773   1.1       cgd 	}
    774   1.1       cgd }
    775   1.1       cgd 
    776   1.1       cgd /*
    777   1.1       cgd  * Initialize the set of debugging names
    778   1.1       cgd  */
    779  1.14  christos static void
    780  1.53    simonb debuginit(void)
    781   1.1       cgd {
    782   1.5       cgd 	int mib[3], loc, i;
    783   1.5       cgd 	size_t size;
    784   1.1       cgd 
    785   1.1       cgd 	if (secondlevel[CTL_DEBUG].list != 0)
    786   1.1       cgd 		return;
    787   1.1       cgd 	secondlevel[CTL_DEBUG].list = debugname;
    788   1.1       cgd 	mib[0] = CTL_DEBUG;
    789   1.1       cgd 	mib[2] = CTL_DEBUG_NAME;
    790   1.1       cgd 	for (loc = 0, i = 0; i < CTL_DEBUG_MAXID; i++) {
    791   1.1       cgd 		mib[1] = i;
    792   1.1       cgd 		size = BUFSIZ - loc;
    793   1.1       cgd 		if (sysctl(mib, 3, &names[loc], &size, NULL, 0) == -1)
    794   1.1       cgd 			continue;
    795   1.1       cgd 		debugname[i].ctl_name = &names[loc];
    796   1.1       cgd 		debugname[i].ctl_type = CTLTYPE_INT;
    797   1.1       cgd 		loc += size;
    798   1.1       cgd 	}
    799   1.1       cgd }
    800   1.1       cgd 
    801   1.1       cgd struct ctlname inetname[] = CTL_IPPROTO_NAMES;
    802   1.1       cgd struct ctlname ipname[] = IPCTL_NAMES;
    803   1.1       cgd struct ctlname icmpname[] = ICMPCTL_NAMES;
    804   1.8   thorpej struct ctlname tcpname[] = TCPCTL_NAMES;
    805   1.1       cgd struct ctlname udpname[] = UDPCTL_NAMES;
    806  1.20    itojun #ifdef IPSEC
    807  1.20    itojun struct ctlname ipsecname[] = IPSECCTL_NAMES;
    808  1.20    itojun #endif
    809   1.1       cgd struct list inetlist = { inetname, IPPROTO_MAXID };
    810   1.1       cgd struct list inetvars[] = {
    811  1.20    itojun /*0*/	{ ipname, IPCTL_MAXID },	/* ip */
    812   1.1       cgd 	{ icmpname, ICMPCTL_MAXID },	/* icmp */
    813   1.1       cgd 	{ 0, 0 },			/* igmp */
    814   1.1       cgd 	{ 0, 0 },			/* ggmp */
    815   1.1       cgd 	{ 0, 0 },
    816   1.1       cgd 	{ 0, 0 },
    817   1.8   thorpej 	{ tcpname, TCPCTL_MAXID },	/* tcp */
    818   1.1       cgd 	{ 0, 0 },
    819   1.1       cgd 	{ 0, 0 },			/* egp */
    820   1.1       cgd 	{ 0, 0 },
    821  1.20    itojun /*10*/	{ 0, 0 },
    822   1.1       cgd 	{ 0, 0 },
    823   1.1       cgd 	{ 0, 0 },			/* pup */
    824   1.1       cgd 	{ 0, 0 },
    825   1.1       cgd 	{ 0, 0 },
    826   1.1       cgd 	{ 0, 0 },
    827   1.1       cgd 	{ 0, 0 },
    828   1.1       cgd 	{ udpname, UDPCTL_MAXID },	/* udp */
    829  1.20    itojun 	{ 0, 0 },
    830  1.20    itojun 	{ 0, 0 },
    831  1.20    itojun /*20*/	{ 0, 0 },
    832  1.20    itojun 	{ 0, 0 },
    833  1.20    itojun 	{ 0, 0 },			/* idp */
    834  1.20    itojun 	{ 0, 0 },
    835  1.20    itojun 	{ 0, 0 },
    836  1.20    itojun 	{ 0, 0 },
    837  1.20    itojun 	{ 0, 0 },
    838  1.20    itojun 	{ 0, 0 },
    839  1.20    itojun 	{ 0, 0 },
    840  1.20    itojun 	{ 0, 0 },
    841  1.20    itojun /*30*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    842  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    843  1.20    itojun /*40*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    844  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    845  1.20    itojun #ifdef IPSEC
    846  1.20    itojun 	{ ipsecname, IPSECCTL_MAXID },	/* esp - for backward compatibility */
    847  1.20    itojun 	{ ipsecname, IPSECCTL_MAXID },	/* ah */
    848  1.20    itojun #else
    849  1.20    itojun 	{ 0, 0 },
    850  1.20    itojun 	{ 0, 0 },
    851  1.20    itojun #endif
    852   1.1       cgd };
    853   1.1       cgd 
    854   1.1       cgd /*
    855   1.1       cgd  * handle internet requests
    856   1.1       cgd  */
    857  1.14  christos static int
    858  1.53    simonb sysctl_inet(char *string, char **bufpp, int mib[], int flags, int *typep)
    859   1.1       cgd {
    860   1.1       cgd 	struct list *lp;
    861   1.1       cgd 	int indx;
    862   1.1       cgd 
    863   1.1       cgd 	if (*bufpp == NULL) {
    864   1.1       cgd 		listall(string, &inetlist);
    865   1.1       cgd 		return (-1);
    866   1.1       cgd 	}
    867   1.1       cgd 	if ((indx = findname(string, "third", bufpp, &inetlist)) == -1)
    868   1.1       cgd 		return (-1);
    869   1.1       cgd 	mib[2] = indx;
    870  1.20    itojun 	if (indx <= IPPROTO_MAXID && inetvars[indx].list != NULL)
    871   1.1       cgd 		lp = &inetvars[indx];
    872   1.1       cgd 	else if (!flags)
    873   1.1       cgd 		return (-1);
    874   1.1       cgd 	else {
    875  1.65     lukem 		fprintf(warnfp,
    876  1.65     lukem 		    "%s: no variables defined for protocol\n", string);
    877   1.1       cgd 		return (-1);
    878   1.1       cgd 	}
    879   1.1       cgd 	if (*bufpp == NULL) {
    880   1.1       cgd 		listall(string, lp);
    881   1.1       cgd 		return (-1);
    882   1.1       cgd 	}
    883   1.1       cgd 	if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
    884   1.1       cgd 		return (-1);
    885   1.1       cgd 	mib[3] = indx;
    886   1.1       cgd 	*typep = lp->list[indx].ctl_type;
    887   1.1       cgd 	return (4);
    888  1.17   thorpej }
    889  1.20    itojun 
    890  1.20    itojun #ifdef INET6
    891  1.20    itojun struct ctlname inet6name[] = CTL_IPV6PROTO_NAMES;
    892  1.20    itojun struct ctlname ip6name[] = IPV6CTL_NAMES;
    893  1.20    itojun struct ctlname icmp6name[] = ICMPV6CTL_NAMES;
    894  1.20    itojun struct ctlname udp6name[] = UDP6CTL_NAMES;
    895  1.37    itojun struct ctlname pim6name[] = PIM6CTL_NAMES;
    896  1.20    itojun struct ctlname ipsec6name[] = IPSEC6CTL_NAMES;
    897  1.20    itojun struct list inet6list = { inet6name, IPV6PROTO_MAXID };
    898  1.20    itojun struct list inet6vars[] = {
    899  1.20    itojun /*0*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    900  1.20    itojun 	{ 0, 0 },
    901  1.49    itojun 	{ tcpname, TCPCTL_MAXID },	/* tcp6 */
    902  1.20    itojun 	{ 0, 0 },
    903  1.20    itojun 	{ 0, 0 },
    904  1.20    itojun 	{ 0, 0 },
    905  1.20    itojun /*10*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    906  1.20    itojun 	{ 0, 0 },
    907  1.20    itojun 	{ 0, 0 },
    908  1.20    itojun 	{ udp6name, UDP6CTL_MAXID },	/* udp6 */
    909  1.20    itojun 	{ 0, 0 },
    910  1.20    itojun 	{ 0, 0 },
    911  1.20    itojun /*20*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    912  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    913  1.20    itojun /*30*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    914  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    915  1.20    itojun /*40*/	{ 0, 0 },
    916  1.20    itojun 	{ ip6name, IPV6CTL_MAXID },	/* ipv6 */
    917  1.20    itojun 	{ 0, 0 },
    918  1.20    itojun 	{ 0, 0 },
    919  1.20    itojun 	{ 0, 0 },
    920  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    921  1.20    itojun #ifdef IPSEC
    922  1.20    itojun /*50*/	{ ipsec6name, IPSECCTL_MAXID },	/* esp6 - for backward compatibility */
    923  1.20    itojun 	{ ipsec6name, IPSECCTL_MAXID },	/* ah6 */
    924  1.20    itojun #else
    925  1.20    itojun 	{ 0, 0 },
    926  1.20    itojun 	{ 0, 0 },
    927  1.20    itojun #endif
    928  1.20    itojun 	{ 0, 0 },
    929  1.20    itojun 	{ 0, 0 },
    930  1.20    itojun 	{ 0, 0 },
    931  1.20    itojun 	{ 0, 0 },
    932  1.20    itojun 	{ 0, 0 },
    933  1.20    itojun 	{ 0, 0 },
    934  1.20    itojun 	{ icmp6name, ICMPV6CTL_MAXID },	/* icmp6 */
    935  1.20    itojun 	{ 0, 0 },
    936  1.20    itojun /*60*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    937  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    938  1.20    itojun /*70*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    939  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    940  1.20    itojun /*80*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    941  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    942  1.20    itojun /*90*/	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    943  1.20    itojun 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
    944  1.20    itojun /*100*/	{ 0, 0 },
    945  1.20    itojun 	{ 0, 0 },
    946  1.20    itojun 	{ 0, 0 },
    947  1.37    itojun 	{ pim6name, PIM6CTL_MAXID },	/* pim6 */
    948  1.20    itojun };
    949  1.20    itojun 
    950  1.20    itojun /*
    951  1.20    itojun  * handle internet6 requests
    952  1.20    itojun  */
    953  1.20    itojun static int
    954  1.53    simonb sysctl_inet6(char *string, char **bufpp, int mib[], int flags, int *typep)
    955  1.20    itojun {
    956  1.20    itojun 	struct list *lp;
    957  1.20    itojun 	int indx;
    958  1.20    itojun 
    959  1.20    itojun 	if (*bufpp == NULL) {
    960  1.20    itojun 		listall(string, &inet6list);
    961  1.20    itojun 		return (-1);
    962  1.20    itojun 	}
    963  1.20    itojun 	if ((indx = findname(string, "third", bufpp, &inet6list)) == -1)
    964  1.20    itojun 		return (-1);
    965  1.20    itojun 	mib[2] = indx;
    966  1.20    itojun 	if (indx <= sizeof(inet6vars)/sizeof(inet6vars[0])
    967  1.20    itojun 	 && inet6vars[indx].list != NULL) {
    968  1.20    itojun 		lp = &inet6vars[indx];
    969  1.20    itojun 	} else if (!flags) {
    970  1.20    itojun 		return (-1);
    971  1.20    itojun 	} else {
    972  1.20    itojun 		fprintf(stderr, "%s: no variables defined for this protocol\n",
    973  1.20    itojun 		    string);
    974  1.20    itojun 		return (-1);
    975  1.20    itojun 	}
    976  1.20    itojun 	if (*bufpp == NULL) {
    977  1.20    itojun 		listall(string, lp);
    978  1.20    itojun 		return (-1);
    979  1.20    itojun 	}
    980  1.20    itojun 	if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
    981  1.20    itojun 		return (-1);
    982  1.20    itojun 	mib[3] = indx;
    983  1.20    itojun 	*typep = lp->list[indx].ctl_type;
    984  1.20    itojun 	return (4);
    985  1.20    itojun }
    986  1.20    itojun #endif /* INET6 */
    987  1.20    itojun 
    988  1.17   thorpej struct ctlname ffsname[] = FFS_NAMES;
    989  1.17   thorpej struct ctlname nfsname[] = NFS_NAMES;
    990  1.17   thorpej struct list vfsvars[] = {
    991  1.17   thorpej 	{ 0, 0 },			/* generic */
    992  1.17   thorpej 	{ ffsname, FFS_MAXID },		/* FFS */
    993  1.17   thorpej 	{ nfsname, NFS_MAXID },		/* NFS */
    994  1.17   thorpej 	{ 0, 0 },			/* MFS */
    995  1.17   thorpej 	{ 0, 0 },			/* MSDOS */
    996  1.17   thorpej 	{ 0, 0 },			/* LFS */
    997  1.17   thorpej 	{ 0, 0 },			/* old LOFS */
    998  1.17   thorpej 	{ 0, 0 },			/* FDESC */
    999  1.17   thorpej 	{ 0, 0 },			/* PORTAL */
   1000  1.17   thorpej 	{ 0, 0 },			/* NULL */
   1001  1.17   thorpej 	{ 0, 0 },			/* UMAP */
   1002  1.17   thorpej 	{ 0, 0 },			/* KERNFS */
   1003  1.17   thorpej 	{ 0, 0 },			/* PROCFS */
   1004  1.17   thorpej 	{ 0, 0 },			/* AFS */
   1005  1.17   thorpej 	{ 0, 0 },			/* CD9660 */
   1006  1.17   thorpej 	{ 0, 0 },			/* UNION */
   1007  1.17   thorpej 	{ 0, 0 },			/* ADOSFS */
   1008  1.17   thorpej 	{ 0, 0 },			/* EXT2FS */
   1009  1.17   thorpej 	{ 0, 0 },			/* CODA */
   1010  1.17   thorpej 	{ 0, 0 },			/* FILECORE */
   1011  1.17   thorpej };
   1012  1.17   thorpej 
   1013  1.17   thorpej /*
   1014  1.17   thorpej  * handle vfs requests
   1015  1.17   thorpej  */
   1016  1.17   thorpej static int
   1017  1.53    simonb sysctl_vfs(char *string, char **bufpp, int mib[], int flags, int *typep)
   1018  1.17   thorpej {
   1019  1.17   thorpej 	struct list *lp = &vfsvars[mib[1]];
   1020  1.17   thorpej 	int indx;
   1021  1.17   thorpej 
   1022  1.17   thorpej 	if (lp->list == NULL) {
   1023  1.17   thorpej 		if (flags)
   1024  1.65     lukem 			fprintf(warnfp,
   1025  1.65     lukem 			    "%s: no variables defined for file system\n",
   1026  1.17   thorpej 			    string);
   1027  1.17   thorpej 		return (-1);
   1028  1.17   thorpej 	}
   1029  1.17   thorpej 	if (*bufpp == NULL) {
   1030  1.17   thorpej 		listall(string, lp);
   1031  1.17   thorpej 		return (-1);
   1032  1.17   thorpej 	}
   1033  1.17   thorpej 	if ((indx = findname(string, "third", bufpp, lp)) == -1)
   1034  1.17   thorpej 		return (-1);
   1035  1.17   thorpej 	mib[2] = indx;
   1036  1.17   thorpej 	*typep = lp->list[indx].ctl_type;
   1037  1.17   thorpej 	return (3);
   1038  1.17   thorpej }
   1039  1.17   thorpej 
   1040  1.17   thorpej /*
   1041  1.56  christos  * handle 3rd level requests.
   1042  1.17   thorpej  */
   1043  1.17   thorpej static int
   1044  1.56  christos sysctl_3rd(struct list *lp, char *string, char **bufpp, int mib[], int flags,
   1045  1.56  christos     int *typep)
   1046  1.17   thorpej {
   1047  1.17   thorpej 	int indx;
   1048  1.17   thorpej 
   1049  1.17   thorpej 	if (*bufpp == NULL) {
   1050  1.17   thorpej 		listall(string, lp);
   1051  1.17   thorpej 		return (-1);
   1052  1.17   thorpej 	}
   1053  1.17   thorpej 	if ((indx = findname(string, "third", bufpp, lp)) == -1)
   1054  1.17   thorpej 		return (-1);
   1055  1.19   thorpej 	mib[2] = indx;
   1056  1.19   thorpej 	*typep = lp->list[indx].ctl_type;
   1057  1.19   thorpej 	return (3);
   1058  1.19   thorpej }
   1059  1.19   thorpej 
   1060  1.22    bouyer struct ctlname procnames[] = PROC_PID_NAMES;
   1061  1.22    bouyer struct list procvars = {procnames, PROC_PID_MAXID};
   1062  1.22    bouyer struct ctlname proclimitnames[] = PROC_PID_LIMIT_NAMES;
   1063  1.22    bouyer struct list proclimitvars = {proclimitnames, PROC_PID_LIMIT_MAXID};
   1064  1.22    bouyer struct ctlname proclimittypenames[] = PROC_PID_LIMIT_TYPE_NAMES;
   1065  1.22    bouyer struct list proclimittypevars = {proclimittypenames,
   1066  1.22    bouyer     PROC_PID_LIMIT_TYPE_MAXID};
   1067  1.22    bouyer /*
   1068  1.22    bouyer  * handle kern.proc requests
   1069  1.22    bouyer  */
   1070  1.22    bouyer static int
   1071  1.53    simonb sysctl_proc(char *string, char **bufpp, int mib[], int flags, int *typep)
   1072  1.22    bouyer {
   1073  1.22    bouyer 	char *cp, name[BUFSIZ];
   1074  1.22    bouyer 	struct list *lp;
   1075  1.22    bouyer 	int indx;
   1076  1.22    bouyer 
   1077  1.22    bouyer 	if (*bufpp == NULL) {
   1078  1.22    bouyer 		strcpy(name, string);
   1079  1.22    bouyer 		cp = &name[strlen(name)];
   1080  1.22    bouyer 		*cp++ = '.';
   1081  1.22    bouyer 		strcpy(cp, "curproc");
   1082  1.46       chs 		parse(name, Aflag);
   1083  1.22    bouyer 		return (-1);
   1084  1.22    bouyer 	}
   1085  1.22    bouyer 	cp = strsep(bufpp, ".");
   1086  1.22    bouyer 	if (cp == NULL) {
   1087  1.22    bouyer 		warnx("%s: incomplete specification", string);
   1088  1.22    bouyer 		return (-1);
   1089  1.22    bouyer 	}
   1090  1.22    bouyer 	if (strcmp(cp, "curproc") == 0) {
   1091  1.22    bouyer 		mib[1] = PROC_CURPROC;
   1092  1.22    bouyer 	} else {
   1093  1.22    bouyer 		mib[1] = atoi(cp);
   1094  1.22    bouyer 		if (mib[1] == 0) {
   1095  1.22    bouyer 			warnx("second level name %s in %s is invalid", cp,
   1096  1.22    bouyer 			    string);
   1097  1.22    bouyer 			return (-1);
   1098  1.22    bouyer 		}
   1099  1.22    bouyer 	}
   1100  1.22    bouyer 	*typep = CTLTYPE_NODE;
   1101  1.22    bouyer 	lp = &procvars;
   1102  1.22    bouyer 	if (*bufpp == NULL) {
   1103  1.22    bouyer 		listall(string, lp);
   1104  1.22    bouyer 		return (-1);
   1105  1.22    bouyer 	}
   1106  1.22    bouyer 	if ((indx = findname(string, "third", bufpp, lp)) == -1)
   1107  1.22    bouyer 		return (-1);
   1108  1.22    bouyer 	mib[2] = indx;
   1109  1.22    bouyer 	*typep = lp->list[indx].ctl_type;
   1110  1.22    bouyer 	if (*typep != CTLTYPE_NODE)
   1111  1.22    bouyer 		return(3);
   1112  1.22    bouyer 	lp = &proclimitvars;
   1113  1.22    bouyer 	if (*bufpp == NULL) {
   1114  1.22    bouyer 		listall(string, lp);
   1115  1.22    bouyer 		return (-1);
   1116  1.22    bouyer 	}
   1117  1.22    bouyer 	if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
   1118  1.22    bouyer 		return (-1);
   1119  1.22    bouyer 	mib[3] = indx;
   1120  1.22    bouyer 	lp = &proclimittypevars;
   1121  1.22    bouyer 	if (*bufpp == NULL) {
   1122  1.22    bouyer 		listall(string, lp);
   1123  1.22    bouyer 		return (-1);
   1124  1.22    bouyer 	}
   1125  1.22    bouyer 	if ((indx = findname(string, "fifth", bufpp, lp)) == -1)
   1126  1.22    bouyer 		return (-1);
   1127  1.22    bouyer 	mib[4] = indx;
   1128  1.22    bouyer 	*typep = CTLTYPE_LIMIT;
   1129  1.22    bouyer 	return(5);
   1130  1.22    bouyer }
   1131  1.22    bouyer 
   1132  1.56  christos struct ctlname linuxnames[] = EMUL_LINUX_NAMES;
   1133  1.56  christos struct list linuxvars = { linuxnames, EMUL_LINUX_MAXID };
   1134  1.56  christos struct ctlname linuxkernnames[] = EMUL_LINUX_KERN_NAMES;
   1135  1.56  christos struct list linuxkernvars = { linuxkernnames, EMUL_LINUX_KERN_MAXID };
   1136  1.47  jdolecek 
   1137  1.47  jdolecek static int
   1138  1.56  christos sysctl_linux(char *string, char **bufpp, int mib[], int flags, int *typep)
   1139  1.47  jdolecek {
   1140  1.56  christos 	struct list *lp = &linuxvars;
   1141  1.54    simonb 	int indx;
   1142  1.56  christos 	char name[BUFSIZ], *cp;
   1143  1.54    simonb 
   1144  1.54    simonb 	if (*bufpp == NULL) {
   1145  1.56  christos 		(void)strcpy(name, string);
   1146  1.56  christos 		cp = &name[strlen(name)];
   1147  1.56  christos 		*cp++ = '.';
   1148  1.56  christos 		(void)strcpy(cp, "kern");
   1149  1.56  christos 		listall(name, &linuxkernvars);
   1150  1.54    simonb 		return (-1);
   1151  1.54    simonb 	}
   1152  1.54    simonb 	if ((indx = findname(string, "third", bufpp, lp)) == -1)
   1153  1.54    simonb 		return (-1);
   1154  1.54    simonb 	mib[2] = indx;
   1155  1.56  christos 	lp = &linuxkernvars;
   1156  1.60      manu 	*typep = lp->list[indx].ctl_type;
   1157  1.60      manu 	if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
   1158  1.60      manu 		return (-1);
   1159  1.60      manu 	mib[3] = indx;
   1160  1.60      manu 	*typep = lp->list[indx].ctl_type;
   1161  1.60      manu 	return (4);
   1162  1.60      manu }
   1163  1.60      manu 
   1164  1.60      manu struct ctlname irixnames[] = EMUL_IRIX_NAMES;
   1165  1.60      manu struct list irixvars = { irixnames, EMUL_IRIX_MAXID };
   1166  1.60      manu struct ctlname irixkernnames[] = EMUL_IRIX_KERN_NAMES;
   1167  1.60      manu struct list irixkernvars = { irixkernnames, EMUL_IRIX_KERN_MAXID };
   1168  1.60      manu 
   1169  1.60      manu static int
   1170  1.60      manu sysctl_irix(char *string, char **bufpp, int mib[], int flags, int *typep)
   1171  1.60      manu {
   1172  1.60      manu 	struct list *lp = &irixvars;
   1173  1.60      manu 	int indx;
   1174  1.60      manu 	char name[BUFSIZ], *cp;
   1175  1.60      manu 
   1176  1.60      manu 	if (*bufpp == NULL) {
   1177  1.60      manu 		(void)strcpy(name, string);
   1178  1.60      manu 		cp = &name[strlen(name)];
   1179  1.60      manu 		*cp++ = '.';
   1180  1.60      manu 		(void)strcpy(cp, "kern");
   1181  1.60      manu 		listall(name, &irixkernvars);
   1182  1.60      manu 		return (-1);
   1183  1.60      manu 	}
   1184  1.60      manu 	if ((indx = findname(string, "third", bufpp, lp)) == -1)
   1185  1.60      manu 		return (-1);
   1186  1.60      manu 	mib[2] = indx;
   1187  1.60      manu 	lp = &irixkernvars;
   1188  1.54    simonb 	*typep = lp->list[indx].ctl_type;
   1189  1.56  christos 	if ((indx = findname(string, "fourth", bufpp, lp)) == -1)
   1190  1.19   thorpej 		return (-1);
   1191  1.56  christos 	mib[3] = indx;
   1192  1.17   thorpej 	*typep = lp->list[indx].ctl_type;
   1193  1.56  christos 	return (4);
   1194  1.62      manu }
   1195  1.62      manu 
   1196  1.62      manu struct ctlname darwinnames[] = EMUL_DARWIN_NAMES;
   1197  1.62      manu struct list darwinvars = { darwinnames, EMUL_DARWIN_MAXID };
   1198  1.62      manu 
   1199  1.62      manu static int
   1200  1.62      manu sysctl_darwin(char *string, char **bufpp, int mib[], int flags, int *typep)
   1201  1.62      manu {
   1202  1.62      manu 	struct list *lp = &darwinvars;
   1203  1.62      manu 	int indx;
   1204  1.62      manu 
   1205  1.62      manu 	if (*bufpp == NULL) {
   1206  1.62      manu 		listall(string, &darwinvars);
   1207  1.62      manu 		return (-1);
   1208  1.62      manu 	}
   1209  1.62      manu 	if ((indx = findname(string, "third", bufpp, lp)) == -1)
   1210  1.62      manu 		return (-1);
   1211  1.62      manu 	mib[2] = indx;
   1212  1.62      manu 	lp = &darwinvars;
   1213  1.62      manu 	*typep = lp->list[indx].ctl_type;
   1214  1.62      manu 	return (3);
   1215   1.1       cgd }
   1216   1.1       cgd 
   1217   1.1       cgd /*
   1218   1.1       cgd  * Scan a list of names searching for a particular name.
   1219   1.1       cgd  */
   1220  1.14  christos static int
   1221  1.53    simonb findname(char *string, char *level, char **bufp, struct list *namelist)
   1222   1.1       cgd {
   1223   1.1       cgd 	char *name;
   1224   1.1       cgd 	int i;
   1225   1.1       cgd 
   1226   1.1       cgd 	if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) {
   1227  1.14  christos 		warnx("%s: incomplete specification", string);
   1228   1.1       cgd 		return (-1);
   1229   1.1       cgd 	}
   1230   1.1       cgd 	for (i = 0; i < namelist->size; i++)
   1231   1.1       cgd 		if (namelist->list[i].ctl_name != NULL &&
   1232   1.1       cgd 		    strcmp(name, namelist->list[i].ctl_name) == 0)
   1233   1.1       cgd 			break;
   1234   1.1       cgd 	if (i == namelist->size) {
   1235  1.14  christos 		warnx("%s level name %s in %s is invalid",
   1236   1.1       cgd 		    level, name, string);
   1237   1.1       cgd 		return (-1);
   1238   1.1       cgd 	}
   1239   1.1       cgd 	return (i);
   1240   1.1       cgd }
   1241   1.1       cgd 
   1242  1.14  christos static void
   1243  1.53    simonb usage(void)
   1244   1.1       cgd {
   1245  1.45       cgd 	const char *progname = getprogname();
   1246  1.45       cgd 
   1247  1.50     lukem 	(void)fprintf(stderr,
   1248  1.50     lukem 	    "Usage:\t%s %s\n\t%s %s\n\t%s %s\n\t%s %s\n\t%s %s\n",
   1249  1.58  sommerfe 	    progname, "[-n] variable ...",
   1250  1.58  sommerfe 	    progname, "[-n] [-q] -w variable=value ...",
   1251  1.45       cgd 	    progname, "[-n] -a",
   1252  1.45       cgd 	    progname, "[-n] -A",
   1253  1.58  sommerfe 	    progname, "[-n] [-q] -f file");
   1254   1.1       cgd 	exit(1);
   1255   1.1       cgd }
   1256