2 * Copyright (c) 1980, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)mbufs.c 8.1 (Berkeley) 6/6/93
34 * $FreeBSD: src/usr.bin/systat/icmp6.c,v 1.3 2006/04/30 04:47:23 bde Exp $
35 * $DragonFly: src/usr.bin/systat/icmp6.c,v 1.1 2007/05/31 11:38:36 hasso Exp $
38 #include <sys/cdefs.h>
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <sys/sysctl.h>
46 #include <netinet/in.h>
47 #include <netinet/icmp6.h>
56 static struct icmp6stat icmp6stat
, initstat
, oldstat
;
60 --0123456789012345678901234567890123456789012345678901234567890123456789012345
61 00 ICMPv6 Input ICMPv6 Output
62 01999999999 total messages 999999999 total messages
63 02999999999 with bad code 999999999 errors generated
64 03999999999 with bad length 999999999 suppressed - original too short
65 04999999999 with bad checksum 999999999 suppressed - original was ICMP
66 05999999999 with insufficient data 999999999 responses sent
68 07 Input Histogram Output Histogram
69 08999999999 echo response 999999999 echo response
70 09999999999 echo request 999999999 echo request
71 10999999999 destination unreachable 999999999 destination unreachable
72 11999999999 redirect 999999999 redirect
73 12999999999 time-to-live exceeded 999999999 time-to-line exceeded
74 13999999999 parameter problem 999999999 parameter problem
75 14999999999 neighbor solicitation 999999999 neighbor solicitation
76 15999999999 neighbor advertisment 999999999 neighbor advertisment
77 16999999999 router advertisement 999999999 router solicitation
80 --0123456789012345678901234567890123456789012345678901234567890123456789012345
87 return (subwin(stdscr
, LINES
-4-1, 0, 4, 0));
104 wmove(wnd
, 0, 0); wclrtoeol(wnd
);
105 #define L(row, str) mvwprintw(wnd, row, 10, str)
106 #define R(row, str) mvwprintw(wnd, row, 45, str);
107 L(1, "ICMPv6 Input"); R(1, "ICMPv6 Output");
108 L(2, "total messages"); R(2, "total messages");
109 L(3, "with bad code"); R(3, "errors generated");
110 L(4, "with bad length"); R(4, "suppressed - original too short");
111 L(5, "with bad checksum"); R(5, "suppressed - original was ICMP");
112 L(6, "with insufficient data"); R(6, "responses sent");
114 L(8, "Input Histogram"); R(8, "Output Histogram");
115 #define B(row, str) L(row, str); R(row, str)
116 B(9, "echo response");
117 B(10, "echo request");
118 B(11, "destination unreachable");
120 B(13, "time-to-live exceeded");
121 B(14, "parameter problem");
122 B(15, "neighbor solicitation");
123 B(16, "neighbor advertisment");
124 L(17, "router advertisement"); R(17, "router solicitation");
131 domode(struct icmp6stat
*ret
)
133 const struct icmp6stat
*sub
;
136 switch(currentmode
) {
151 #define DO(stat) ret->stat = (icmp6stat.stat - sub->stat) / divisor
155 for (i
= 0; i
<= ICMP6_MAXTYPE
; i
++) {
156 DO(icp6s_outhist
[i
]);
163 for (i
= 0; i
<= ICMP6_MAXTYPE
; i
++) {
172 struct icmp6stat stats
;
173 u_long totalin
, totalout
;
176 memset(&stats
, 0, sizeof stats
);
178 for (i
= totalin
= totalout
= 0; i
<= ICMP6_MAXTYPE
; i
++) {
179 totalin
+= stats
.icp6s_inhist
[i
];
180 totalout
+= stats
.icp6s_outhist
[i
];
182 totalin
+= stats
.icp6s_badcode
+ stats
.icp6s_badlen
+
183 stats
.icp6s_checksum
+ stats
.icp6s_tooshort
;
184 mvwprintw(wnd
, 2, 0, "%9lu", totalin
);
185 mvwprintw(wnd
, 2, 35, "%9lu", totalout
);
187 #define DO(stat, row, col) \
188 mvwprintw(wnd, row, col, "%9lu", stats.stat)
190 DO(icp6s_badcode
, 3, 0);
191 DO(icp6s_badlen
, 4, 0);
192 DO(icp6s_checksum
, 5, 0);
193 DO(icp6s_tooshort
, 6, 0);
194 DO(icp6s_error
, 3, 35);
195 DO(icp6s_tooshort
, 4, 35);
196 DO(icp6s_canterror
, 5, 35);
197 DO(icp6s_reflect
, 6, 35);
198 #define DO2(type, row) DO(icp6s_inhist[type], row, 0); DO(icp6s_outhist[type], \
200 DO2(ICMP6_ECHO_REPLY
, 9);
201 DO2(ICMP6_ECHO_REQUEST
, 10);
202 DO2(ICMP6_DST_UNREACH
, 11);
203 DO2(ND_REDIRECT
, 12);
204 DO2(ICMP6_TIME_EXCEEDED
, 13);
205 DO2(ICMP6_PARAM_PROB
, 14);
206 DO2(ND_NEIGHBOR_SOLICIT
, 15);
207 DO2(ND_NEIGHBOR_ADVERT
, 16);
208 DO(icp6s_inhist
[ND_ROUTER_SOLICIT
], 17, 0);
209 DO(icp6s_outhist
[ND_ROUTER_ADVERT
], 17, 35);
222 name
[2] = IPPROTO_ICMPV6
;
223 name
[3] = ICMPV6CTL_STATS
;
226 if (sysctl(name
, 4, 0, &len
, 0, 0) < 0) {
227 error("sysctl getting icmp6stat size failed");
230 if (len
> sizeof icmp6stat
) {
231 error("icmp6stat structure has grown--recompile systat!");
234 if (sysctl(name
, 4, &initstat
, &len
, 0, 0) < 0) {
235 error("sysctl getting icmp6stat size failed");
250 name
[2] = IPPROTO_ICMPV6
;
251 name
[3] = ICMPV6CTL_STATS
;
253 len
= sizeof initstat
;
254 if (sysctl(name
, 4, &initstat
, &len
, 0, 0) < 0) {
255 error("sysctl getting icmp6stat size failed");
269 name
[2] = IPPROTO_ICMPV6
;
270 name
[3] = ICMPV6CTL_STATS
;
271 len
= sizeof icmp6stat
;
273 if (sysctl(name
, 4, &icmp6stat
, &len
, 0, 0) < 0)