]>
git.saurik.com Git - apple/system_cmds.git/blob - sysctl.tproj/sysctl.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * The Regents of the University of California. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
41 * 4. Neither the name of the University nor the names of its contributors
42 * may be used to endorse or promote products derived from this software
43 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 Modified November 1, 2000, by Ryan Rempel, ryan.rempel@utoronto.ca
61 The Darwin sysctl mechanism is in a state of flux. Parts of the kernel use the old
62 style of BSD sysctl definition, and other parts use the new style. The sysctl (8)
63 command that shipped with Darwin 1.2 (OS X PB) did not allow you to access
64 all possible sysctl values. In particular, it did not permit access to sysctl values
65 created by kernel extensions--hence my particular interest. The freeBSD sysctl (8)
66 command compiled and ran under Darwin 1.2, and it did permit access to
67 sysctl values created by kernel extensions, as well as several others. However, it
68 did not permit access to many other values which the Darwin 1.2 sysctl could access.
70 What I have done is merge the Darwin 1.2 sysctl and the freeBSD sysctl. Essentially,
71 there are two points of merger. When showing all values (i.e. -a, -A, or -X), sysctl now
72 runs the Darwin 1.2 routine to show all values, and then the freeBSD routine. This does
73 result in some duplication. When getting or setting a particular value, sysctl now tries
74 the freeBSD way first. If it cannot find the value, then it tries the Darwin 1.2 way.
76 There are a few oddities which this creates (aside from some duplication with -a, -A,
77 and -X). The freeBSD version of sysctl now supports two extra options, -b and -X.
78 In this syctl, those options are supported where the value is retrieved by the freeBSD
79 routine, and have no effect where the value is retrieved by the Darwin 1.2 routine.
80 The freeBSD sysctl uses a ':' to separate the name and the value, whereas Darwin 1.2's
81 sysctl uses a '='. I have left this way, as it lets you know which routine was used,
84 I have also fixed several lines which gave warnings previously, one of which appears
85 to have been an actual bug (bufp was dereferenced when it shouldn't have been).
86 I have also incoporated my previous patch to permit setting kern.hostid as an unsigned
87 integer. In the freeBSD side of the code, I have incorporated a general fix for
88 setting values where the format is specified as unsigned integer.
92 static char copyright
[] =
93 "@(#) Copyright (c) 1993\n\
94 The Regents of the University of California. All rights reserved.\n";
98 static char sccsid
[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95";
101 #include <sys/param.h>
102 #include <sys/gmon.h>
103 #include <sys/mount.h>
104 #include <sys/stat.h>
105 #include <sys/sysctl.h>
106 #include <sys/socket.h>
108 #include <mach/machine/vm_param.h>
109 #include <mach/machine/vm_types.h>
110 #include <mach/mach_types.h>
112 #include <vm/vm_param.h>
113 #endif /* __APPLE__ */
114 #include <machine/cpu.h>
123 #include <sys/types.h>
124 #include <sys/resource.h>
127 struct ctlname topname
[] = CTL_NAMES
;
128 struct ctlname kernname
[] = CTL_KERN_NAMES
;
129 struct ctlname vmname
[] = CTL_VM_NAMES
;
130 struct ctlname hwname
[] = CTL_HW_NAMES
;
131 struct ctlname username
[] = CTL_USER_NAMES
;
132 struct ctlname debugname
[CTL_DEBUG_MAXID
];
133 struct ctlname
*vfsname
;
134 #ifdef CTL_MACHDEP_NAMES
135 struct ctlname machdepname
[] = CTL_MACHDEP_NAMES
;
141 struct ctlname
*list
;
144 struct list toplist
= { topname
, CTL_MAXID
};
145 struct list secondlevel
[] = {
146 { 0, 0 }, /* CTL_UNSPEC */
147 { kernname
, KERN_MAXID
}, /* CTL_KERN */
148 { vmname
, VM_MAXID
}, /* CTL_VM */
149 { 0, 0 }, /* CTL_VFS */
150 { 0, 0 }, /* CTL_NET */
151 { 0, CTL_DEBUG_MAXID
}, /* CTL_DEBUG */
152 { 0, 0 }, /* CTL_HW */
153 #ifdef CTL_MACHDEP_NAMES
154 { machdepname
, CPU_MAXID
}, /* CTL_MACHDEP */
156 { 0, 0 }, /* CTL_MACHDEP */
158 { username
, USER_MAXID
}, /* CTL_USER_NAMES */
161 static int Aflag
, aflag
, bflag
, nflag
, wflag
, Xflag
;
162 static int foundSome
= 0;
164 void listall(char *prefix
, struct list
*lp
);
165 void old_parse(char *string
, int flags
);
168 int findname(char *string
, char *level
, char **bufp
, struct list
*namelist
);
171 static void parse(char *string
, int flags
);
172 static int oidfmt(int *, int, char *, u_int
*);
173 static int show_var(int *, int, int);
174 static int sysctl_all (int *oid
, int len
);
175 static int name2oid(char *, int *);
178 * Variables requiring special processing.
180 #define CLOCK 0x00000001
181 #define BOOTTIME 0x00000002
182 #define CONSDEV 0x00000004
189 // extern char *optarg; // unused
193 while ((ch
= getopt(argc
, argv
, "AabnwX")) != EOF
) {
195 case 'A': Aflag
= 1; break;
196 case 'a': aflag
= 1; break;
197 case 'b': bflag
= 1; break;
198 case 'n': nflag
= 1; break;
199 case 'w': wflag
= 1; break;
200 case 'X': Xflag
= Aflag
= 1; break;
207 if (argc
== 0 && (Aflag
|| aflag
)) {
210 for (lvl1
= 1; lvl1
< CTL_MAXID
; lvl1
++)
211 listall(topname
[lvl1
].ctl_name
, &secondlevel
[lvl1
]);
212 exit (sysctl_all(0, 0));
216 for (; *argv
!= NULL
; ++argv
)
222 * List all variables known to the system.
230 char *cp
, name
[BUFSIZ
];
234 strcpy(name
, prefix
);
235 cp
= &name
[strlen(name
)];
237 for (lvl2
= 0; lvl2
< lp
->size
; lvl2
++) {
238 if (lp
->list
[lvl2
].ctl_name
== 0)
240 strcpy(cp
, lp
->list
[lvl2
].ctl_name
);
241 old_parse(name
, Aflag
);
246 * Parse a name into a MIB entry.
247 * Lookup and print out the MIB entry if it exists.
248 * Set a new value if requested.
251 old_parse(string
, flags
)
255 int indx
, type
, state
, len
;
259 int intval
, newsize
= 0;
260 unsigned int uintval
;
261 int useUnsignedInt
= 0;
265 int mib
[CTL_MAXNAME
];
266 char *cp
, *bufp
, buf
[BUFSIZ
] /*, strval[BUFSIZ] */ ;
269 snprintf(buf
, BUFSIZ
, "%s", string
);
270 if ((cp
= strchr(string
, '=')) != NULL
) {
272 fprintf(stderr
, "Must specify -w to set variables\n");
275 *strchr(buf
, '=') = '\0';
280 newsize
= strlen(cp
);
282 if ((indx
= findname(string
, "top", &bufp
, &toplist
)) == -1)
287 if (indx
== CTL_DEBUG
)
289 lp
= &secondlevel
[indx
];
291 if (!foundSome
) fprintf(stderr
, "%s: class is not implemented\n",
292 topname
[indx
].ctl_name
);
296 listall(topname
[indx
].ctl_name
, lp
);
299 if ((indx
= findname(string
, "second", &bufp
, lp
)) == -1)
302 type
= lp
->list
[indx
].ctl_type
;
309 mib
[2] = GPROF_STATE
;
311 if (sysctl(mib
, 3, &state
, &size
, NULL
, 0) < 0) {
315 fprintf(stdout
, "%s: ", string
);
317 "kernel is not compiled for profiling\n");
321 fprintf(stdout
, "%s: %s\n", string
,
322 state
== GMON_PROF_OFF
? "off" : "running");
329 "Use pstat to view %s information\n", string
);
335 "Use ps to view %s information\n", string
);
354 if (mib
[1] == VM_LOADAVG
) { /* XXX this is bogus */
357 getloadavg(loads
, 3);
359 fprintf(stdout
, "%s: ", string
);
360 fprintf(stdout
, "%.2f %.2f %.2f\n",
361 loads
[0], loads
[1], loads
[2]);
367 "Use vmstat or systat to view %s information\n", string
);
371 mib
[2] = CTL_DEBUG_VALUE
;
377 if (mib
[1] == CPU_CONSDEV
)
384 mib
[1] = VFS_GENERIC
;
388 if (sysctl(mib
, 4, &vfc
, &size
, (void *)0, (size_t)0) < 0) {
392 if (flags
== 0 && vfc
.vfc_refcount
== 0)
395 fprintf(stdout
, "%s has %d mounted instance%s\n",
396 string
, vfc
.vfc_refcount
,
397 vfc
.vfc_refcount
!= 1 ? "s" : "");
399 fprintf(stdout
, "%d\n", vfc
.vfc_refcount
);
406 fprintf(stderr
, "Illegal top level value: %d\n", mib
[0]);
411 fprintf(stderr
, "name %s in %s is unknown\n", bufp
, string
);
417 if (useUnsignedInt
) {
418 uintval
= strtoul(newval
, 0, 0);
420 newsize
= sizeof uintval
;
422 intval
= atoi(newval
);
424 newsize
= sizeof intval
;
429 sscanf(newval
, "%qd", &quadval
);
431 newsize
= sizeof quadval
;
436 if (sysctl(mib
, len
, buf
, &size
, newsize
? newval
: 0, newsize
) == -1) {
441 fprintf(stderr
, "%s: value is not available\n", string
);
444 fprintf(stderr
, "%s: specification is incomplete\n",
448 fprintf(stderr
, "%s: type is unknown to this program\n",
456 if (special
& CLOCK
) {
457 struct clockinfo
*clkp
= (struct clockinfo
*)buf
;
460 fprintf(stdout
, "%s: ", string
);
462 "hz = %d, tick = %d, profhz = %d, stathz = %d\n",
463 clkp
->hz
, clkp
->tick
, clkp
->profhz
, clkp
->stathz
);
466 if (special
& BOOTTIME
) {
467 struct timeval
*btp
= (struct timeval
*)buf
;
470 fprintf(stdout
, "%s = %s\n", string
,
471 ctime((time_t *) &btp
->tv_sec
));
473 fprintf(stdout
, "%d\n", btp
->tv_sec
);
476 if (special
& CONSDEV
) {
477 dev_t dev
= *(dev_t
*)buf
;
480 fprintf(stdout
, "%s = %s\n", string
,
481 devname(dev
, S_IFCHR
));
483 fprintf(stdout
, "0x%x\n", dev
);
490 fprintf(stdout
, "%s = ", string
);
491 fprintf(stdout
, useUnsignedInt
? "%u\n" : "%d\n", *(int *)buf
);
494 fprintf(stdout
, useUnsignedInt
? "%s: %u -> " : "%s: %d -> ",
495 string
, *(int *)buf
);
496 fprintf(stdout
, useUnsignedInt
? "%u\n" : "%d\n", *(int *)newval
);
503 fprintf(stdout
, "%s = ", string
);
504 fprintf(stdout
, "%s\n", buf
);
507 fprintf(stdout
, "%s: %s -> ", string
, buf
);
508 fprintf(stdout
, "%s\n", (char *) newval
);
515 fprintf(stdout
, "%s = ", string
);
516 fprintf(stdout
, "%qd\n", *(quad_t
*)buf
);
519 fprintf(stdout
, "%s: %qd -> ", string
,
521 fprintf(stdout
, "%qd\n", *(quad_t
*)newval
);
530 fprintf(stderr
, "%s: unknown type returned\n",
537 * Initialize the set of debugging names
544 if (secondlevel
[CTL_DEBUG
].list
!= 0)
546 secondlevel
[CTL_DEBUG
].list
= debugname
;
548 mib
[2] = CTL_DEBUG_NAME
;
549 for (loc
= lastused
, i
= 0; i
< CTL_DEBUG_MAXID
; i
++) {
552 if (sysctl(mib
, 3, &names
[loc
], &size
, NULL
, 0) == -1)
554 debugname
[i
].ctl_name
= &names
[loc
];
555 debugname
[i
].ctl_type
= CTLTYPE_INT
;
562 * Initialize the set of filesystem names
566 int mib
[4], maxtypenum
, cnt
, loc
, size
;
570 if (secondlevel
[CTL_VFS
].list
!= 0)
573 mib
[1] = VFS_GENERIC
;
574 mib
[2] = VFS_MAXTYPENUM
;
576 if (sysctl(mib
, 3, &maxtypenum
, &buflen
, (void *)0, (size_t)0) < 0)
578 if ((vfsname
= malloc(maxtypenum
* sizeof(*vfsname
))) == 0)
580 memset(vfsname
, 0, maxtypenum
* sizeof(*vfsname
));
583 for (loc
= lastused
, cnt
= 0; cnt
< maxtypenum
; cnt
++) {
585 if (sysctl(mib
, 4, &vfc
, &buflen
, (void *)0, (size_t)0) < 0) {
586 if (errno
== EOPNOTSUPP
)
592 strcat(&names
[loc
], vfc
.vfc_name
);
593 vfsname
[cnt
].ctl_name
= &names
[loc
];
594 vfsname
[cnt
].ctl_type
= CTLTYPE_INT
;
595 size
= strlen(vfc
.vfc_name
) + 1;
599 secondlevel
[CTL_VFS
].list
= vfsname
;
600 secondlevel
[CTL_VFS
].size
= maxtypenum
;
605 * Scan a list of names searching for a particular name.
608 findname(string
, level
, bufp
, namelist
)
612 struct list
*namelist
;
617 if (namelist
->list
== 0 || (name
= strsep(bufp
, ".")) == NULL
) {
618 fprintf(stderr
, "%s: incomplete specification\n", string
);
621 for (i
= 0; i
< namelist
->size
; i
++)
622 if (namelist
->list
[i
].ctl_name
!= NULL
&&
623 strcmp(name
, namelist
->list
[i
].ctl_name
) == 0)
625 if (i
== namelist
->size
) {
626 fprintf(stderr
, "%s level name %s in %s is invalid\n",
627 level
, name
, string
);
636 (void)fprintf(stderr
, "%s\n%s\n%s\n%s\n%s\n",
637 "usage: sysctl [-bn] variable ...",
638 " sysctl [-bn] -w variable=value ...",
646 * Parse a name into a MIB entry.
647 * Lookup and print out the MIB entry if it exists.
648 * Set a new value if requested.
651 parse(char *string
, int flags
)
655 int intval
, newsize
= 0;
656 unsigned int uintval
;
658 int mib
[CTL_MAXNAME
];
659 char *cp
, *bufp
, buf
[BUFSIZ
], fmt
[BUFSIZ
];
663 snprintf(buf
, BUFSIZ
, "%s", string
);
664 if ((cp
= strchr(string
, '=')) != NULL
) {
666 errx(2, "must specify -w to set variables");
667 *strchr(buf
, '=') = '\0';
672 newsize
= strlen(cp
);
677 len
= name2oid(bufp
, mib
);
681 while (*cp
!= '\0') cp
--;
684 old_parse (string
, flags
);
688 if (oidfmt(mib
, len
, fmt
, &kind
))
689 err(1, "couldn't find format of oid '%s'", bufp
);
692 if ((kind
& CTLTYPE
) == CTLTYPE_NODE
) {
693 sysctl_all(mib
, len
);
695 old_parse (string
, flags
);
697 i
= show_var(mib
, len
, 1);
702 if ((kind
& CTLTYPE
) == CTLTYPE_NODE
)
703 errx(1, "oid '%s' isn't a leaf node", bufp
);
705 if (!(kind
&CTLFLAG_WR
))
706 errx(1, "oid '%s' is read only", bufp
);
708 switch (kind
& CTLTYPE
) {
710 if ((*fmt
== 'I') && (*(fmt
+ 1) == 'U')) {
711 uintval
= (unsigned int) strtoul (newval
, NULL
, 0);
713 newsize
= sizeof uintval
;
715 intval
= (int) strtol(newval
, NULL
, 0);
717 newsize
= sizeof intval
;
724 sscanf(newval
, "%qd", &quadval
);
726 newsize
= sizeof quadval
;
729 errx(1, "oid '%s' is type %d,"
730 " cannot set that", bufp
,
734 i
= show_var(mib
, len
, 1);
735 if (sysctl(mib
, len
, 0, 0, newval
, newsize
) == -1) {
740 errx(1, "%s: value is not available",
743 errx(1, "%s: specification is incomplete",
746 errx(1, "%s: type is unknown to this program",
757 j
= show_var(mib
, len
, 1);
764 /* These functions will dump out various interesting structures. */
767 S_clockinfo(int l2
, void *p
)
769 struct clockinfo
*ci
= (struct clockinfo
*)p
;
770 if (l2
!= sizeof *ci
)
771 err(1, "S_clockinfo %d != %d", l2
, sizeof *ci
);
772 printf("{ hz = %d, tick = %d, tickadj = %d, profhz = %d, stathz = %d }",
773 ci
->hz
, ci
->tick
, ci
->tickadj
, ci
->profhz
, ci
->stathz
);
778 S_loadavg(int l2
, void *p
)
780 struct loadavg
*tv
= (struct loadavg
*)p
;
782 if (l2
!= sizeof *tv
)
783 err(1, "S_loadavg %d != %d", l2
, sizeof *tv
);
785 printf("{ %.2f %.2f %.2f }",
786 (double)tv
->ldavg
[0]/(double)tv
->fscale
,
787 (double)tv
->ldavg
[1]/(double)tv
->fscale
,
788 (double)tv
->ldavg
[2]/(double)tv
->fscale
);
793 S_timeval(int l2
, void *p
)
795 struct timeval
*tv
= (struct timeval
*)p
;
799 if (l2
!= sizeof *tv
)
800 err(1, "S_timeval %d != %d", l2
, sizeof *tv
);
801 printf("{ sec = %ld, usec = %ld } ",
802 (long) tv
->tv_sec
, (long) tv
->tv_usec
);
804 p1
= strdup(ctime(&tv_sec
));
805 for (p2
=p1
; *p2
; p2
++)
813 T_dev_t(int l2
, void *p
)
815 dev_t
*d
= (dev_t
*)p
;
817 err(1, "T_dev_T %d != %d", l2
, sizeof *d
);
818 if ((int)(*d
) != -1) {
819 if (minor(*d
) > 255 || minor(*d
) < 0)
820 printf("{ major = %d, minor = 0x%x }",
821 major(*d
), minor(*d
));
823 printf("{ major = %d, minor = %d }",
824 major(*d
), minor(*d
));
830 * These functions uses a presently undocumented interface to the kernel
831 * to walk the tree and get the type so it can print the value.
832 * This interface is under work and consideration, and should probably
833 * be killed with a big axe by the first person who can find the time.
834 * (be aware though, that the proper interface isn't as obvious as it
835 * may seem, there are various conflicting requirements.
839 name2oid(char *name
, int *oidp
)
848 j
= CTL_MAXNAME
* sizeof (int);
849 i
= sysctl(oid
, 2, oidp
, &j
, name
, strlen(name
));
857 oidfmt(int *oid
, int len
, char *fmt
, u_int
*kind
)
859 int qoid
[CTL_MAXNAME
+2];
866 memcpy(qoid
+ 2, oid
, len
* sizeof(int));
869 i
= sysctl(qoid
, len
+ 2, buf
, &j
, 0, 0);
871 err(1, "sysctl fmt %d %d %d", i
, j
, errno
);
874 *kind
= *(u_int
*)buf
;
877 strcpy(fmt
, (char *)(buf
+ sizeof(u_int
)));
882 * This formats and outputs the value of one variable
884 * Returns zero if anything was actually output.
885 * Returns one if didn't know what to do with this.
886 * Return minus one if we had errors.
890 show_var(int *oid
, int nlen
, int show_masked
)
892 u_char buf
[BUFSIZ
], *val
, *mval
, *p
;
893 char name
[BUFSIZ
], /* descr[BUFSIZ], */ *fmt
;
894 int qoid
[CTL_MAXNAME
+2];
899 int (*func
)(int, void *) = 0;
902 memcpy(qoid
+ 2, oid
, nlen
* sizeof(int));
906 i
= sysctl(qoid
, nlen
+ 2, name
, &j
, 0, 0);
908 err(1, "sysctl name %d %d %d", i
, j
, errno
);
910 /* find an estimate of how much we need for this var */
912 i
= sysctl(oid
, nlen
, 0, &j
, 0, 0);
913 j
+= j
; /* we want to be sure :-) */
915 val
= mval
= malloc(j
);
917 i
= sysctl(oid
, nlen
, val
, &len
, 0, 0);
924 fwrite(val
, 1, len
, stdout
);
931 i
= sysctl(qoid
, nlen
+ 2, buf
, &j
, 0, 0);
933 err(1, "sysctl fmt %d %d %d", i
, j
, errno
);
935 kind
= *(u_int
*)buf
;
936 if (!show_masked
&& (kind
& CTLFLAG_MASKED
)) {
941 fmt
= (char *)(buf
+ sizeof(u_int
));
946 /* deprecated, do not print */
953 printf("%s: ", name
);
960 printf("%s: ", name
);
963 while (len
>= sizeof(int)) {
965 printf("%s%u", val
, *(unsigned int *)p
);
967 printf("%s%d", val
, *(int *)p
);
977 printf("%s: ", name
);
980 while (len
>= sizeof(long)) {
982 printf("%s%lu", val
, *(unsigned long *)p
);
984 printf("%s%ld", val
, *(long *)p
);
986 len
-= sizeof (long);
994 printf("%s: ", name
);
995 printf("%p", *(void **)p
);
1001 printf("%s: ", name
);
1004 while (len
>= sizeof(long long)) {
1006 printf("%s%llu", val
, *(unsigned long long *)p
);
1008 printf("%s%lld", val
, *(long long *)p
);
1010 len
-= sizeof (long long);
1011 p
+= sizeof (long long);
1020 if (!strcmp(fmt
, "S,clockinfo")) func
= S_clockinfo
;
1021 else if (!strcmp(fmt
, "S,timeval")) func
= S_timeval
;
1022 else if (!strcmp(fmt
, "S,loadavg")) func
= S_loadavg
;
1023 else if (!strcmp(fmt
, "T,dev_t")) func
= T_dev_t
;
1026 printf("%s: ", name
);
1027 retval
= (*func
)(len
, p
);
1037 printf("%s: ", name
);
1038 printf("Format:%s Length:%ld Dump:0x", fmt
, len
);
1040 printf("%02x", *p
++);
1041 if (Xflag
|| p
< val
+16)
1057 sysctl_all (int *oid
, int len
)
1059 int name1
[22], name2
[22];
1067 memcpy(name1
+2, oid
, len
*sizeof (int));
1075 j
= sysctl(name1
, l1
, name2
, &l2
, 0, 0);
1077 if (errno
== ENOENT
)
1080 err(1, "sysctl(getnext) %d %d", j
, l2
);
1088 for (i
= 0; i
< len
; i
++)
1089 if (name2
[i
] != oid
[i
])
1092 i
= show_var(name2
, l2
, 0);
1096 memcpy(name1
+2, name2
, l2
*sizeof (int));