]>
Commit | Line | Data |
---|---|---|
d9520f62 A |
1 | /* |
2 | * Copyright (c) 2017 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #include <sys/sysctl.h> | |
30 | ||
31 | #include <net/net_api_stats.h> | |
32 | #include <err.h> | |
33 | #include <stdio.h> | |
34 | ||
35 | #include "netstat.h" | |
36 | ||
37 | void | |
38 | print_net_api_stats(uint32_t off __unused, char *name, int af __unused) | |
39 | { | |
40 | static struct net_api_stats pnet_api_stats; | |
41 | struct net_api_stats net_api_stats; | |
42 | size_t len = sizeof(struct net_api_stats); | |
43 | const char *mibvar = "net.api_stats"; | |
44 | ||
45 | if (sysctlbyname(mibvar, &net_api_stats, &len, 0, 0) < 0) { | |
46 | warn("sysctl: %s", mibvar); | |
47 | return; | |
48 | } | |
49 | ||
50 | #define STATDIFF(f) (net_api_stats.f - pnet_api_stats.f) | |
51 | #define p(f, m) if (STATDIFF(f) || sflag <= 1) \ | |
52 | printf(m, STATDIFF(f), plural(STATDIFF(f))) | |
53 | #define p1a(f, m) if (STATDIFF(f) || sflag <= 1) \ | |
54 | printf(m, STATDIFF(f)) | |
55 | ||
56 | if (interval && vflag > 0) | |
57 | print_time(); | |
58 | printf ("%s:\n", name); | |
59 | ||
60 | p(nas_iflt_attach_count, "\t%lld interface filter%s currently attached\n"); | |
61 | p(nas_iflt_attach_total, "\t%lld interface filter%s attached since boot\n"); | |
62 | p(nas_iflt_attach_os_total, "\t%lld interface filter%s attached since boot by OS\n"); | |
63 | ||
64 | p(nas_ipf_add_count, "\t%lld IP filter%s currently attached\n"); | |
65 | p(nas_ipf_add_total, "\t%lld IP filter%s attached since boot\n"); | |
66 | p(nas_ipf_add_os_total, "\t%lld IP filter%s attached since boot by OS\n"); | |
67 | ||
68 | p(nas_sfltr_register_count, "\t%lld socket filter%s currently attached\n"); | |
69 | p(nas_sfltr_register_total, "\t%lld socket filter%s attached since boot\n"); | |
70 | p(nas_sfltr_register_os_total, "\t%lld socket filter%s attached since boot by OS\n"); | |
71 | ||
72 | p(nas_socket_alloc_total, "\t%lld socket%s allocated since boot\n"); | |
73 | p(nas_socket_in_kernel_total, "\t%lld socket%s allocated in-kernel since boot\n"); | |
74 | p(nas_socket_in_kernel_os_total, "\t%lld socket%s allocated in-kernel by OS\n"); | |
75 | p(nas_socket_necp_clientuuid_total, "\t%lld socket%s with NECP client UUID since boot\n"); | |
76 | ||
77 | p(nas_socket_domain_local_total, "\t%lld local domain socket%s allocated since boot\n"); | |
78 | p(nas_socket_domain_route_total, "\t%lld route domain socket%s allocated since boot\n"); | |
79 | p(nas_socket_domain_inet_total, "\t%lld inet domain socket%s allocated since boot\n"); | |
80 | p(nas_socket_domain_inet6_total, "\t%lld inet6 domain socket%s allocated since boot\n"); | |
81 | p(nas_socket_domain_system_total, "\t%lld system domain socket%s allocated since boot\n"); | |
82 | p(nas_socket_domain_multipath_total, "\t%lld multipath domain socket%s allocated since boot\n"); | |
83 | p(nas_socket_domain_key_total, "\t%lld key domain socket%s allocated since boot\n"); | |
84 | p(nas_socket_domain_ndrv_total, "\t%lld ndrv domain socket%s allocated since boot\n"); | |
85 | p(nas_socket_domain_other_total, "\t%lld other domains socket%s allocated since boot\n"); | |
86 | ||
87 | p(nas_socket_inet_stream_total, "\t%lld IPv4 stream socket%s created since boot\n"); | |
88 | p(nas_socket_inet_dgram_total, "\t%lld IPv4 datagram socket%s created since boot\n"); | |
89 | p(nas_socket_inet_dgram_connected, "\t%lld IPv4 datagram socket%s connected\n"); | |
90 | p(nas_socket_inet_dgram_dns, "\t%lld IPv4 DNS socket%s\n"); | |
91 | p(nas_socket_inet_dgram_no_data, "\t%lld IPv4 datagram socket%s without data\n"); | |
92 | ||
93 | p(nas_socket_inet6_stream_total, "\t%lld IPv6 stream socket%s created since boot\n"); | |
94 | p(nas_socket_inet6_dgram_total, "\t%lld IPv6 datagram socket%s created since boot\n"); | |
95 | p(nas_socket_inet6_dgram_connected, "\t%lld IPv6 datagram socket%s connected\n"); | |
96 | p(nas_socket_inet6_dgram_dns, "\t%lld IPv6 DNS socket%s\n"); | |
97 | p(nas_socket_inet6_dgram_no_data, "\t%lld IPv6 datagram socket%s without data\n"); | |
98 | ||
99 | p(nas_socket_mcast_join_total, "\t%lld socket multicast join%s since boot\n"); | |
100 | p(nas_socket_mcast_join_os_total, "\t%lld socket multicast join%s since boot by OS\n"); | |
101 | ||
102 | p(nas_nx_flow_inet_stream_total, "\t%lld IPv4 stream nexus flow%s added since boot\n"); | |
103 | p(nas_nx_flow_inet_dgram_total, "\t%lld IPv4 datagram nexus flow%s added since boot\n"); | |
104 | ||
105 | p(nas_nx_flow_inet6_stream_total, "\t%lld IPv6 stream nexus flow%s added since boot\n"); | |
106 | p(nas_nx_flow_inet6_dgram_total, "\t%lld IPv6 datagram nexus flow%s added since boot\n"); | |
107 | ||
108 | p(nas_ifnet_alloc_count, "\t%lld interface%s currently allocated\n"); | |
109 | p(nas_ifnet_alloc_total, "\t%lld interface%s allocated since boot\n"); | |
110 | p(nas_ifnet_alloc_os_count, "\t%lld interface%s currently allocated by OS\n"); | |
111 | p(nas_ifnet_alloc_os_total, "\t%lld extended interface%s allocated since boot by OS\n"); | |
112 | ||
113 | p(nas_pf_addrule_total, "\t%lld PF addrule operation%s since boot\n"); | |
114 | p(nas_pf_addrule_os, "\t%lld PF addrule operation%s since boot by OS\n"); | |
115 | ||
116 | p(nas_vmnet_total, "\t%lld vmnet start%s since boot\n"); | |
117 | ||
118 | #undef STATDIFF | |
119 | #undef p | |
120 | #undef p1a | |
121 | } | |
122 |