blob: 93b2e02f1eb51dee9c4c48521eb27571c8c6e680 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen485b9551999-12-07 23:14:59 +00002/*
Eric Andersen485b9551999-12-07 23:14:59 +00003 * Mini ping implementation for busybox
4 *
5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
6 *
Rob Landley42eddba2005-12-15 08:04:17 +00007 * Adapted from the ping in netkit-base 0.10:
Eric Andersen485b9551999-12-07 23:14:59 +00008 * Copyright (c) 1989 The Regents of the University of California.
Denis Vlasenko35d4da02007-01-22 14:04:27 +00009 * All rights reserved.
10 *
11 * This code is derived from software contributed to Berkeley by
12 * Mike Muuss.
Eric Andersen485b9551999-12-07 23:14:59 +000013 *
Rob Landley42eddba2005-12-15 08:04:17 +000014 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen485b9551999-12-07 23:14:59 +000015 */
Denis Vlasenkob9a279b2007-01-24 23:53:22 +000016/* from ping6.c:
17 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
18 *
19 * This version of ping is adapted from the ping in netkit-base 0.10,
20 * which is:
21 *
22 * Original copyright notice is retained at the end of this file.
23 *
24 * This version is an adaptation of ping.c from busybox.
25 * The code was modified by Bart Visscher <magick@linux-fan.com>
26 */
Eric Andersen485b9551999-12-07 23:14:59 +000027
Denis Vlasenkob9a279b2007-01-24 23:53:22 +000028#include <net/if.h>
Eric Andersen485b9551999-12-07 23:14:59 +000029#include <netinet/ip_icmp.h>
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000030#include "libbb.h"
Denis Vlasenkoe9356022007-01-29 18:03:54 +000031
Denis Vlasenkob9a279b2007-01-24 23:53:22 +000032#if ENABLE_PING6
33#include <netinet/icmp6.h>
34/* I see RENUMBERED constants in bits/in.h - !!?
35 * What a fuck is going on with libc? Is it a glibc joke? */
36#ifdef IPV6_2292HOPLIMIT
37#undef IPV6_HOPLIMIT
38#define IPV6_HOPLIMIT IPV6_2292HOPLIMIT
39#endif
40#endif
Eric Andersen485b9551999-12-07 23:14:59 +000041
Rob Landleybc68cd12006-03-10 19:22:06 +000042enum {
43 DEFDATALEN = 56,
44 MAXIPLEN = 60,
45 MAXICMPLEN = 76,
46 MAXPACKET = 65468,
47 MAX_DUP_CHK = (8 * 128),
48 MAXWAIT = 10,
Denis Vlasenkob9a279b2007-01-24 23:53:22 +000049 PINGINTERVAL = 1, /* 1 second */
Rob Landleybc68cd12006-03-10 19:22:06 +000050};
Eric Andersen485b9551999-12-07 23:14:59 +000051
Eric Andersen19db07b1999-12-11 08:41:28 +000052/* common routines */
Denis Vlasenko4a5cf162006-11-20 00:48:22 +000053
Eric Andersen485b9551999-12-07 23:14:59 +000054static int in_cksum(unsigned short *buf, int sz)
55{
Erik Andersene49d5ec2000-02-08 19:58:47 +000056 int nleft = sz;
57 int sum = 0;
58 unsigned short *w = buf;
59 unsigned short ans = 0;
Eric Andersen485b9551999-12-07 23:14:59 +000060
Erik Andersene49d5ec2000-02-08 19:58:47 +000061 while (nleft > 1) {
62 sum += *w++;
63 nleft -= 2;
64 }
Eric Andersen485b9551999-12-07 23:14:59 +000065
Erik Andersene49d5ec2000-02-08 19:58:47 +000066 if (nleft == 1) {
67 *(unsigned char *) (&ans) = *(unsigned char *) w;
68 sum += ans;
69 }
Eric Andersen485b9551999-12-07 23:14:59 +000070
Erik Andersene49d5ec2000-02-08 19:58:47 +000071 sum = (sum >> 16) + (sum & 0xFFFF);
72 sum += (sum >> 16);
73 ans = ~sum;
Denis Vlasenkod9e15f22006-11-27 16:49:55 +000074 return ans;
Erik Andersene49d5ec2000-02-08 19:58:47 +000075}
Eric Andersen485b9551999-12-07 23:14:59 +000076
Denis Vlasenkob9a279b2007-01-24 23:53:22 +000077#if !ENABLE_FEATURE_FANCY_PING
Denis Vlasenko4a5cf162006-11-20 00:48:22 +000078
79/* simple version */
80
Denis Vlasenkocb6874c2006-09-02 16:13:36 +000081static char *hostname;
82
Denis Vlasenkob9a279b2007-01-24 23:53:22 +000083static void noresp(int ign ATTRIBUTE_UNUSED)
Eric Andersenb5474c42002-03-20 11:59:28 +000084{
Eric Andersenb8886822002-03-21 14:04:43 +000085 printf("No response from %s\n", hostname);
Eric Andersen4e486a52003-01-12 06:08:33 +000086 exit(EXIT_FAILURE);
Eric Andersenb5474c42002-03-20 11:59:28 +000087}
Eric Andersen19db07b1999-12-11 08:41:28 +000088
Denis Vlasenkoe9356022007-01-29 18:03:54 +000089static void ping4(len_and_sockaddr *lsa)
Eric Andersen19db07b1999-12-11 08:41:28 +000090{
Erik Andersene49d5ec2000-02-08 19:58:47 +000091 struct sockaddr_in pingaddr;
92 struct icmp *pkt;
93 int pingsock, c;
94 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
Eric Andersen19db07b1999-12-11 08:41:28 +000095
Matt Kraai06ef1652001-07-13 20:56:27 +000096 pingsock = create_icmp_socket();
Paul Fox0b2b5842008-02-01 23:25:32 +000097 pingaddr = lsa->u.sin;
Erik Andersene49d5ec2000-02-08 19:58:47 +000098
99 pkt = (struct icmp *) packet;
100 memset(pkt, 0, sizeof(packet));
101 pkt->icmp_type = ICMP_ECHO;
102 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));
103
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000104 c = xsendto(pingsock, packet, DEFDATALEN + ICMP_MINLEN,
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000105 (struct sockaddr *) &pingaddr, sizeof(pingaddr));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000106
Erik Andersene49d5ec2000-02-08 19:58:47 +0000107 /* listen for replies */
108 while (1) {
109 struct sockaddr_in from;
Mike Frysinger03e827a2005-07-26 23:00:59 +0000110 socklen_t fromlen = sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000111
Denis Vlasenko806116b2006-12-31 12:14:16 +0000112 c = recvfrom(pingsock, packet, sizeof(packet), 0,
113 (struct sockaddr *) &from, &fromlen);
114 if (c < 0) {
Denis Vlasenko44c2eb22007-01-08 23:55:33 +0000115 if (errno != EINTR)
116 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000117 continue;
118 }
119 if (c >= 76) { /* ip + icmp */
120 struct iphdr *iphdr = (struct iphdr *) packet;
121
122 pkt = (struct icmp *) (packet + (iphdr->ihl << 2)); /* skip ip hdr */
123 if (pkt->icmp_type == ICMP_ECHOREPLY)
124 break;
125 }
126 }
Denis Vlasenko9adc6ce2007-01-22 22:45:27 +0000127 if (ENABLE_FEATURE_CLEAN_UP)
128 close(pingsock);
Eric Andersen19db07b1999-12-11 08:41:28 +0000129}
130
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000131#if ENABLE_PING6
132static void ping6(len_and_sockaddr *lsa)
133{
134 struct sockaddr_in6 pingaddr;
135 struct icmp6_hdr *pkt;
136 int pingsock, c;
137 int sockopt;
138 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
139
140 pingsock = create_icmp6_socket();
Paul Fox0b2b5842008-02-01 23:25:32 +0000141 pingaddr = lsa->u.sin6;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000142
143 pkt = (struct icmp6_hdr *) packet;
144 memset(pkt, 0, sizeof(packet));
145 pkt->icmp6_type = ICMP6_ECHO_REQUEST;
146
147 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
148 setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt));
149
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000150 c = xsendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr),
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000151 (struct sockaddr *) &pingaddr, sizeof(pingaddr));
152
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000153 /* listen for replies */
154 while (1) {
155 struct sockaddr_in6 from;
156 socklen_t fromlen = sizeof(from);
157
158 c = recvfrom(pingsock, packet, sizeof(packet), 0,
159 (struct sockaddr *) &from, &fromlen);
160 if (c < 0) {
161 if (errno != EINTR)
162 bb_perror_msg("recvfrom");
163 continue;
164 }
165 if (c >= 8) { /* icmp6_hdr */
166 pkt = (struct icmp6_hdr *) packet;
167 if (pkt->icmp6_type == ICMP6_ECHO_REPLY)
168 break;
169 }
170 }
171 if (ENABLE_FEATURE_CLEAN_UP)
172 close(pingsock);
173}
174#endif
175
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000176int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenko68404f12008-03-17 09:00:54 +0000177int ping_main(int argc ATTRIBUTE_UNUSED, char **argv)
Eric Andersen19db07b1999-12-11 08:41:28 +0000178{
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000179 len_and_sockaddr *lsa;
180#if ENABLE_PING6
181 sa_family_t af = AF_UNSPEC;
Denis Vlasenko3483e852007-07-02 15:47:52 +0000182
183 while ((++argv)[0] && argv[0][0] == '-') {
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000184 if (argv[0][1] == '4') {
185 af = AF_INET;
186 continue;
187 }
188 if (argv[0][1] == '6') {
189 af = AF_INET6;
190 continue;
191 }
Manuel Novoa III cad53642003-03-19 09:13:01 +0000192 bb_show_usage();
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000193 }
194#else
195 argv++;
196#endif
197
198 hostname = *argv;
199 if (!hostname)
200 bb_show_usage();
201
202#if ENABLE_PING6
Denis Vlasenko42823d52007-02-04 02:39:08 +0000203 lsa = xhost_and_af2sockaddr(hostname, 0, af);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000204#else
Denis Vlasenko42823d52007-02-04 02:39:08 +0000205 lsa = xhost_and_af2sockaddr(hostname, 0, AF_INET);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000206#endif
207 /* Set timer _after_ DNS resolution */
208 signal(SIGALRM, noresp);
209 alarm(5); /* give the host 5000ms to respond */
210
211#if ENABLE_PING6
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000212 if (lsa->u.sa.sa_family == AF_INET6)
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000213 ping6(lsa);
214 else
215#endif
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000216 ping4(lsa);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000217 printf("%s is alive!\n", hostname);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000218 return EXIT_SUCCESS;
Eric Andersen19db07b1999-12-11 08:41:28 +0000219}
220
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000221
222#else /* FEATURE_FANCY_PING */
223
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000224
Eric Andersen19db07b1999-12-11 08:41:28 +0000225/* full(er) version */
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000226
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000227#define OPT_STRING ("qvc:s:I:4" USE_PING6("6"))
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000228enum {
229 OPT_QUIET = 1 << 0,
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000230 OPT_VERBOSE = 1 << 1,
231 OPT_c = 1 << 2,
232 OPT_s = 1 << 3,
233 OPT_I = 1 << 4,
234 OPT_IPV4 = 1 << 5,
235 OPT_IPV6 = (1 << 6) * ENABLE_PING6,
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000236};
237
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000238
Denis Vlasenko821cc252007-06-04 10:33:48 +0000239struct globals {
240 int pingsock;
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000241 int if_index;
242 char *opt_I;
Denis Vlasenko821cc252007-06-04 10:33:48 +0000243 len_and_sockaddr *source_lsa;
244 unsigned datalen;
Denis Vlasenko821cc252007-06-04 10:33:48 +0000245 unsigned long ntransmitted, nreceived, nrepeats, pingcount;
246 uint16_t myid;
Denis Vlasenko76791452007-06-18 08:55:57 +0000247 unsigned tmin, tmax; /* in us */
248 unsigned long long tsum; /* in us, sum of all times */
Denis Vlasenko821cc252007-06-04 10:33:48 +0000249 const char *hostname;
250 const char *dotted;
251 union {
252 struct sockaddr sa;
253 struct sockaddr_in sin;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000254#if ENABLE_PING6
Denis Vlasenko821cc252007-06-04 10:33:48 +0000255 struct sockaddr_in6 sin6;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000256#endif
Denis Vlasenko821cc252007-06-04 10:33:48 +0000257 } pingaddr;
258 char rcvd_tbl[MAX_DUP_CHK / 8];
259};
260#define G (*(struct globals*)&bb_common_bufsiz1)
261#define pingsock (G.pingsock )
Denis Vlasenko821cc252007-06-04 10:33:48 +0000262#define if_index (G.if_index )
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000263#define source_lsa (G.source_lsa )
264#define opt_I (G.opt_I )
265#define datalen (G.datalen )
Denis Vlasenko821cc252007-06-04 10:33:48 +0000266#define ntransmitted (G.ntransmitted)
267#define nreceived (G.nreceived )
268#define nrepeats (G.nrepeats )
269#define pingcount (G.pingcount )
270#define myid (G.myid )
271#define tmin (G.tmin )
272#define tmax (G.tmax )
273#define tsum (G.tsum )
274#define hostname (G.hostname )
275#define dotted (G.dotted )
276#define pingaddr (G.pingaddr )
277#define rcvd_tbl (G.rcvd_tbl )
278void BUG_ping_globals_too_big(void);
279#define INIT_G() do { \
Denis Vlasenko6b404432008-01-07 16:13:14 +0000280 if (sizeof(G) > COMMON_BUFSIZE) \
281 BUG_ping_globals_too_big(); \
Denis Vlasenko821cc252007-06-04 10:33:48 +0000282 pingsock = -1; \
283 tmin = UINT_MAX; \
284} while (0)
Eric Andersen19db07b1999-12-11 08:41:28 +0000285
Eric Andersen19db07b1999-12-11 08:41:28 +0000286
Denis Vlasenko4a5cf162006-11-20 00:48:22 +0000287#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
288#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
289#define SET(bit) (A(bit) |= B(bit))
290#define CLR(bit) (A(bit) &= (~B(bit)))
291#define TST(bit) (A(bit) & B(bit))
292
Eric Andersen19db07b1999-12-11 08:41:28 +0000293/**************************************************************************/
294
Denis Vlasenkoaeb4bdd2007-01-25 00:00:02 +0000295static void pingstats(int junk ATTRIBUTE_UNUSED)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000296{
297 signal(SIGINT, SIG_IGN);
298
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000299 printf("\n--- %s ping statistics ---\n", hostname);
Denis Vlasenko13858992006-10-08 12:49:22 +0000300 printf("%lu packets transmitted, ", ntransmitted);
301 printf("%lu packets received, ", nreceived);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000302 if (nrepeats)
Denis Vlasenko13858992006-10-08 12:49:22 +0000303 printf("%lu duplicates, ", nrepeats);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000304 if (ntransmitted)
Denis Vlasenkoaeb4bdd2007-01-25 00:00:02 +0000305 ntransmitted = (ntransmitted - nreceived) * 100 / ntransmitted;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000306 printf("%lu%% packet loss\n", ntransmitted);
Denis Vlasenko76791452007-06-18 08:55:57 +0000307 if (tmin != UINT_MAX) {
308 unsigned tavg = tsum / (nreceived + nrepeats);
309 printf("round-trip min/avg/max = %u.%03u/%u.%03u/%u.%03u ms\n",
310 tmin / 1000, tmin % 1000,
311 tavg / 1000, tavg % 1000,
312 tmax / 1000, tmax % 1000);
313 }
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000314 exit(nreceived == 0); /* (nreceived == 0) is true (1) -- 'failure' */
Eric Andersen485b9551999-12-07 23:14:59 +0000315}
316
Denis Vlasenkoc8e99932007-02-09 18:14:42 +0000317static void sendping_tail(void (*sp)(int), const void *pkt, int size_pkt)
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000318{
Denis Vlasenkoc8e99932007-02-09 18:14:42 +0000319 int sz;
320
321 CLR((uint16_t)ntransmitted % MAX_DUP_CHK);
322 ntransmitted++;
323
324 /* sizeof(pingaddr) can be larger than real sa size, but I think
325 * it doesn't matter */
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000326 sz = xsendto(pingsock, pkt, size_pkt, &pingaddr.sa, sizeof(pingaddr));
Denis Vlasenkoc8e99932007-02-09 18:14:42 +0000327 if (sz != size_pkt)
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000328 bb_error_msg_and_die(bb_msg_write_error);
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000329
330 signal(SIGALRM, sp);
Bernhard Reutner-Fischerb2908892007-04-12 11:34:39 +0000331 if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000332 alarm(PINGINTERVAL);
333 } else { /* done, wait for the last ping to come back */
334 /* todo, don't necessarily need to wait so long... */
335 signal(SIGALRM, pingstats);
336 alarm(MAXWAIT);
337 }
338}
339
340static void sendping4(int junk ATTRIBUTE_UNUSED)
Eric Andersen485b9551999-12-07 23:14:59 +0000341{
Denis Vlasenko76791452007-06-18 08:55:57 +0000342 /* +4 reserves a place for timestamp, which may end up sitting
343 * *after* packet. Saves one if() */
344 struct icmp *pkt = alloca(datalen + ICMP_MINLEN + 4);
Eric Andersen485b9551999-12-07 23:14:59 +0000345
Erik Andersene49d5ec2000-02-08 19:58:47 +0000346 pkt->icmp_type = ICMP_ECHO;
347 pkt->icmp_code = 0;
348 pkt->icmp_cksum = 0;
Denis Vlasenko919c10d2007-01-03 22:14:18 +0000349 pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000350 pkt->icmp_id = myid;
Denis Vlasenko7b72fc12007-06-16 13:37:59 +0000351
Denis Vlasenko76791452007-06-18 08:55:57 +0000352 /* We don't do hton, because we will read it back on the same machine */
353 /*if (datalen >= 4)*/
354 *(uint32_t*)&pkt->icmp_dun = monotonic_us();
Denis Vlasenko7b72fc12007-06-16 13:37:59 +0000355
Denis Vlasenkoc8e99932007-02-09 18:14:42 +0000356 pkt->icmp_cksum = in_cksum((unsigned short *) pkt, datalen + ICMP_MINLEN);
Eric Andersen485b9551999-12-07 23:14:59 +0000357
Denis Vlasenkoc8e99932007-02-09 18:14:42 +0000358 sendping_tail(sendping4, pkt, datalen + ICMP_MINLEN);
Eric Andersen485b9551999-12-07 23:14:59 +0000359}
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000360#if ENABLE_PING6
361static void sendping6(int junk ATTRIBUTE_UNUSED)
362{
Denis Vlasenko76791452007-06-18 08:55:57 +0000363 struct icmp6_hdr *pkt = alloca(datalen + sizeof(struct icmp6_hdr) + 4);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000364
365 pkt->icmp6_type = ICMP6_ECHO_REQUEST;
366 pkt->icmp6_code = 0;
367 pkt->icmp6_cksum = 0;
368 pkt->icmp6_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
369 pkt->icmp6_id = myid;
Denis Vlasenko7b72fc12007-06-16 13:37:59 +0000370
Denis Vlasenko76791452007-06-18 08:55:57 +0000371 /*if (datalen >= 4)*/
372 *(uint32_t*)(&pkt->icmp6_data8[4]) = monotonic_us();
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000373
Denis Vlasenkoc8e99932007-02-09 18:14:42 +0000374 sendping_tail(sendping6, pkt, datalen + sizeof(struct icmp6_hdr));
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000375}
376#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000377
Denis Vlasenko89ef65f2007-01-29 23:43:18 +0000378static const char *icmp_type_name(int id)
Erik Andersen227a59b2000-04-25 23:24:55 +0000379{
380 switch (id) {
Denis Vlasenko35d4da02007-01-22 14:04:27 +0000381 case ICMP_ECHOREPLY: return "Echo Reply";
382 case ICMP_DEST_UNREACH: return "Destination Unreachable";
383 case ICMP_SOURCE_QUENCH: return "Source Quench";
384 case ICMP_REDIRECT: return "Redirect (change route)";
385 case ICMP_ECHO: return "Echo Request";
386 case ICMP_TIME_EXCEEDED: return "Time Exceeded";
387 case ICMP_PARAMETERPROB: return "Parameter Problem";
388 case ICMP_TIMESTAMP: return "Timestamp Request";
389 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
390 case ICMP_INFO_REQUEST: return "Information Request";
391 case ICMP_INFO_REPLY: return "Information Reply";
392 case ICMP_ADDRESS: return "Address Mask Request";
393 case ICMP_ADDRESSREPLY: return "Address Mask Reply";
394 default: return "unknown ICMP type";
Erik Andersen227a59b2000-04-25 23:24:55 +0000395 }
396}
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000397#if ENABLE_PING6
398/* RFC3542 changed some definitions from RFC2292 for no good reason, whee!
399 * the newer 3542 uses a MLD_ prefix where as 2292 uses ICMP6_ prefix */
400#ifndef MLD_LISTENER_QUERY
401# define MLD_LISTENER_QUERY ICMP6_MEMBERSHIP_QUERY
402#endif
403#ifndef MLD_LISTENER_REPORT
404# define MLD_LISTENER_REPORT ICMP6_MEMBERSHIP_REPORT
405#endif
406#ifndef MLD_LISTENER_REDUCTION
407# define MLD_LISTENER_REDUCTION ICMP6_MEMBERSHIP_REDUCTION
408#endif
Denis Vlasenko89ef65f2007-01-29 23:43:18 +0000409static const char *icmp6_type_name(int id)
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000410{
411 switch (id) {
412 case ICMP6_DST_UNREACH: return "Destination Unreachable";
413 case ICMP6_PACKET_TOO_BIG: return "Packet too big";
414 case ICMP6_TIME_EXCEEDED: return "Time Exceeded";
415 case ICMP6_PARAM_PROB: return "Parameter Problem";
416 case ICMP6_ECHO_REPLY: return "Echo Reply";
417 case ICMP6_ECHO_REQUEST: return "Echo Request";
418 case MLD_LISTENER_QUERY: return "Listener Query";
419 case MLD_LISTENER_REPORT: return "Listener Report";
420 case MLD_LISTENER_REDUCTION: return "Listener Reduction";
421 default: return "unknown ICMP type";
422 }
423}
424#endif
Erik Andersen227a59b2000-04-25 23:24:55 +0000425
Denis Vlasenko76791452007-06-18 08:55:57 +0000426static void unpack_tail(int sz, uint32_t *tp,
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000427 const char *from_str,
428 uint16_t recv_seq, int ttl)
429{
430 const char *dupmsg = " (DUP!)";
431 unsigned triptime = triptime; /* for gcc */
432
433 ++nreceived;
434
435 if (tp) {
Denis Vlasenko76791452007-06-18 08:55:57 +0000436 /* (int32_t) cast is for hypothetical 64-bit unsigned */
437 /* (doesn't hurt 32-bit real-world anyway) */
438 triptime = (int32_t) ((uint32_t)monotonic_us() - *tp);
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000439 tsum += triptime;
440 if (triptime < tmin)
441 tmin = triptime;
442 if (triptime > tmax)
443 tmax = triptime;
444 }
445
446 if (TST(recv_seq % MAX_DUP_CHK)) {
447 ++nrepeats;
448 --nreceived;
449 } else {
450 SET(recv_seq % MAX_DUP_CHK);
451 dupmsg += 7;
452 }
453
454 if (option_mask32 & OPT_QUIET)
455 return;
456
457 printf("%d bytes from %s: seq=%u ttl=%d", sz,
458 from_str, recv_seq, ttl);
459 if (tp)
Denis Vlasenko76791452007-06-18 08:55:57 +0000460 printf(" time=%u.%03u ms", triptime / 1000, triptime % 1000);
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000461 puts(dupmsg);
462 fflush(stdout);
463}
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000464static void unpack4(char *buf, int sz, struct sockaddr_in *from)
Eric Andersen485b9551999-12-07 23:14:59 +0000465{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000466 struct icmp *icmppkt;
467 struct iphdr *iphdr;
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000468 int hlen;
Eric Andersen485b9551999-12-07 23:14:59 +0000469
Erik Andersene49d5ec2000-02-08 19:58:47 +0000470 /* discard if too short */
Pavel Roskin0024abc2000-06-07 20:38:15 +0000471 if (sz < (datalen + ICMP_MINLEN))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000472 return;
Eric Andersen485b9551999-12-07 23:14:59 +0000473
Denis Vlasenko2cbe6e62006-09-02 16:17:30 +0000474 /* check IP header */
475 iphdr = (struct iphdr *) buf;
476 hlen = iphdr->ihl << 2;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000477 sz -= hlen;
478 icmppkt = (struct icmp *) (buf + hlen);
Erik Andersen227a59b2000-04-25 23:24:55 +0000479 if (icmppkt->icmp_id != myid)
Denis Vlasenkocb6874c2006-09-02 16:13:36 +0000480 return; /* not our ping */
Erik Andersen227a59b2000-04-25 23:24:55 +0000481
Erik Andersene49d5ec2000-02-08 19:58:47 +0000482 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
Denis Vlasenko35d4da02007-01-22 14:04:27 +0000483 uint16_t recv_seq = ntohs(icmppkt->icmp_seq);
Denis Vlasenko76791452007-06-18 08:55:57 +0000484 uint32_t *tp = NULL;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000485
Denis Vlasenko76791452007-06-18 08:55:57 +0000486 if (sz >= ICMP_MINLEN + sizeof(uint32_t))
487 tp = (uint32_t *) icmppkt->icmp_data;
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000488 unpack_tail(sz, tp,
489 inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr),
490 recv_seq, iphdr->ttl);
491 } else if (icmppkt->icmp_type != ICMP_ECHO) {
492 bb_error_msg("warning: got ICMP %d (%s)",
493 icmppkt->icmp_type,
494 icmp_type_name(icmppkt->icmp_type));
Denis Vlasenko35d4da02007-01-22 14:04:27 +0000495 }
Eric Andersen485b9551999-12-07 23:14:59 +0000496}
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000497#if ENABLE_PING6
Denis Vlasenko68404f12008-03-17 09:00:54 +0000498static void unpack6(char *packet, int sz, /*struct sockaddr_in6 *from,*/ int hoplimit)
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000499{
500 struct icmp6_hdr *icmppkt;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000501 char buf[INET6_ADDRSTRLEN];
Eric Andersen485b9551999-12-07 23:14:59 +0000502
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000503 /* discard if too short */
504 if (sz < (datalen + sizeof(struct icmp6_hdr)))
505 return;
506
507 icmppkt = (struct icmp6_hdr *) packet;
508 if (icmppkt->icmp6_id != myid)
509 return; /* not our ping */
510
511 if (icmppkt->icmp6_type == ICMP6_ECHO_REPLY) {
512 uint16_t recv_seq = ntohs(icmppkt->icmp6_seq);
Denis Vlasenko76791452007-06-18 08:55:57 +0000513 uint32_t *tp = NULL;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000514
Denis Vlasenko76791452007-06-18 08:55:57 +0000515 if (sz >= sizeof(struct icmp6_hdr) + sizeof(uint32_t))
516 tp = (uint32_t *) &icmppkt->icmp6_data8[4];
Denis Vlasenko19c238b2007-03-03 00:36:35 +0000517 unpack_tail(sz, tp,
518 inet_ntop(AF_INET6, &pingaddr.sin6.sin6_addr,
519 buf, sizeof(buf)),
520 recv_seq, hoplimit);
521 } else if (icmppkt->icmp6_type != ICMP6_ECHO_REQUEST) {
522 bb_error_msg("warning: got ICMP %d (%s)",
523 icmppkt->icmp6_type,
524 icmp6_type_name(icmppkt->icmp6_type));
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000525 }
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000526}
527#endif
528
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000529static void ping4(len_and_sockaddr *lsa)
Eric Andersen485b9551999-12-07 23:14:59 +0000530{
Pavel Roskin0024abc2000-06-07 20:38:15 +0000531 char packet[datalen + MAXIPLEN + MAXICMPLEN];
Erik Andersene49d5ec2000-02-08 19:58:47 +0000532 int sockopt;
533
Matt Kraai06ef1652001-07-13 20:56:27 +0000534 pingsock = create_icmp_socket();
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000535 pingaddr.sin = lsa->u.sin;
Denis Vlasenko5ad10482007-06-19 22:54:21 +0000536 if (source_lsa) {
537 if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF,
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000538 &source_lsa->u.sa, source_lsa->len))
Denis Vlasenko5ad10482007-06-19 22:54:21 +0000539 bb_error_msg_and_die("can't set multicast source interface");
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000540 xbind(pingsock, &source_lsa->u.sa, source_lsa->len);
Denis Vlasenko5ad10482007-06-19 22:54:21 +0000541 }
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000542 if (opt_I)
Denis Vlasenko2edbc2a2007-10-20 02:00:49 +0000543 setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, opt_I, strlen(opt_I) + 1);
Denis Vlasenko2cbe6e62006-09-02 16:17:30 +0000544
Erik Andersene49d5ec2000-02-08 19:58:47 +0000545 /* enable broadcast pings */
Denis Vlasenko48237b02006-11-22 23:22:06 +0000546 setsockopt_broadcast(pingsock);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000547
548 /* set recv buf for broadcast pings */
Denis Vlasenko35d4da02007-01-22 14:04:27 +0000549 sockopt = 48 * 1024; /* explain why 48k? */
Denis Vlasenko703e2022007-01-22 14:12:08 +0000550 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000551
Erik Andersene49d5ec2000-02-08 19:58:47 +0000552 signal(SIGINT, pingstats);
553
554 /* start the ping's going ... */
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000555 sendping4(0);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000556
557 /* listen for replies */
558 while (1) {
559 struct sockaddr_in from;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000560 socklen_t fromlen = (socklen_t) sizeof(from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000561 int c;
562
Denis Vlasenko44c2eb22007-01-08 23:55:33 +0000563 c = recvfrom(pingsock, packet, sizeof(packet), 0,
564 (struct sockaddr *) &from, &fromlen);
565 if (c < 0) {
566 if (errno != EINTR)
567 bb_perror_msg("recvfrom");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000568 continue;
569 }
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000570 unpack4(packet, c, &from);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000571 if (pingcount > 0 && nreceived >= pingcount)
572 break;
573 }
Eric Andersen485b9551999-12-07 23:14:59 +0000574}
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000575#if ENABLE_PING6
576extern int BUG_bad_offsetof_icmp6_cksum(void);
577static void ping6(len_and_sockaddr *lsa)
578{
579 char packet[datalen + MAXIPLEN + MAXICMPLEN];
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000580 int sockopt;
581 struct msghdr msg;
582 struct sockaddr_in6 from;
583 struct iovec iov;
584 char control_buf[CMSG_SPACE(36)];
585
586 pingsock = create_icmp6_socket();
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000587 pingaddr.sin6 = lsa->u.sin6;
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000588 /* untested whether "-I addr" really works for IPv6: */
589 if (source_lsa)
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000590 xbind(pingsock, &source_lsa->u.sa, source_lsa->len);
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000591 if (opt_I)
Denis Vlasenko2edbc2a2007-10-20 02:00:49 +0000592 setsockopt(pingsock, SOL_SOCKET, SO_BINDTODEVICE, opt_I, strlen(opt_I) + 1);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000593
594#ifdef ICMP6_FILTER
595 {
596 struct icmp6_filter filt;
597 if (!(option_mask32 & OPT_VERBOSE)) {
598 ICMP6_FILTER_SETBLOCKALL(&filt);
599 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt);
600 } else {
601 ICMP6_FILTER_SETPASSALL(&filt);
602 }
603 if (setsockopt(pingsock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
604 sizeof(filt)) < 0)
605 bb_error_msg_and_die("setsockopt(ICMP6_FILTER)");
606 }
607#endif /*ICMP6_FILTER*/
608
609 /* enable broadcast pings */
610 setsockopt_broadcast(pingsock);
611
612 /* set recv buf for broadcast pings */
613 sockopt = 48 * 1024; /* explain why 48k? */
614 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
615
616 sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
617 if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2)
618 BUG_bad_offsetof_icmp6_cksum();
619 setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt));
620
621 /* request ttl info to be returned in ancillary data */
622 setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, &const_int_1, sizeof(const_int_1));
623
624 if (if_index)
Denis Vlasenkoaeb4bdd2007-01-25 00:00:02 +0000625 pingaddr.sin6.sin6_scope_id = if_index;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000626
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000627 signal(SIGINT, pingstats);
628
629 /* start the ping's going ... */
630 sendping6(0);
631
632 /* listen for replies */
633 msg.msg_name = &from;
634 msg.msg_namelen = sizeof(from);
635 msg.msg_iov = &iov;
636 msg.msg_iovlen = 1;
637 msg.msg_control = control_buf;
638 iov.iov_base = packet;
639 iov.iov_len = sizeof(packet);
640 while (1) {
641 int c;
642 struct cmsghdr *mp;
643 int hoplimit = -1;
644 msg.msg_controllen = sizeof(control_buf);
645
646 c = recvmsg(pingsock, &msg, 0);
647 if (c < 0) {
648 if (errno != EINTR)
649 bb_perror_msg("recvfrom");
650 continue;
651 }
652 for (mp = CMSG_FIRSTHDR(&msg); mp; mp = CMSG_NXTHDR(&msg, mp)) {
653 if (mp->cmsg_level == SOL_IPV6
654 && mp->cmsg_type == IPV6_HOPLIMIT
655 /* don't check len - we trust the kernel: */
656 /* && mp->cmsg_len >= CMSG_LEN(sizeof(int)) */
657 ) {
658 hoplimit = *(int*)CMSG_DATA(mp);
659 }
660 }
Denis Vlasenko68404f12008-03-17 09:00:54 +0000661 unpack6(packet, c, /*&from,*/ hoplimit);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000662 if (pingcount > 0 && nreceived >= pingcount)
663 break;
664 }
665}
666#endif
Eric Andersen485b9551999-12-07 23:14:59 +0000667
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000668static void ping(len_and_sockaddr *lsa)
Denis Vlasenko2cbe6e62006-09-02 16:17:30 +0000669{
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000670 printf("PING %s (%s)", hostname, dotted);
671 if (source_lsa) {
672 printf(" from %s",
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000673 xmalloc_sockaddr2dotted_noport(&source_lsa->u.sa));
Denis Vlasenko2cbe6e62006-09-02 16:17:30 +0000674 }
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000675 printf(": %d data bytes\n", datalen);
676
677#if ENABLE_PING6
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000678 if (lsa->u.sa.sa_family == AF_INET6)
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000679 ping6(lsa);
680 else
681#endif
682 ping4(lsa);
Denis Vlasenko2cbe6e62006-09-02 16:17:30 +0000683}
684
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000685int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenko68404f12008-03-17 09:00:54 +0000686int ping_main(int argc ATTRIBUTE_UNUSED, char **argv)
Eric Andersen485b9551999-12-07 23:14:59 +0000687{
Denis Vlasenkoaeb4bdd2007-01-25 00:00:02 +0000688 len_and_sockaddr *lsa;
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000689 char *opt_c, *opt_s;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000690 USE_PING6(sa_family_t af = AF_UNSPEC;)
Eric Andersen485b9551999-12-07 23:14:59 +0000691
Denis Vlasenko821cc252007-06-04 10:33:48 +0000692 INIT_G();
693
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000694 datalen = DEFDATALEN;
Mark Whitley59ab0252001-01-23 22:30:04 +0000695
Denis Vlasenkoe9356022007-01-29 18:03:54 +0000696 /* exactly one argument needed, -v and -q don't mix */
Denis Vlasenko581930c2007-01-24 23:55:34 +0000697 opt_complementary = "=1:q--v:v--q";
Denis Vlasenkofe7cd642007-08-18 15:32:12 +0000698 getopt32(argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000699 if (option_mask32 & OPT_c)
700 pingcount = xatoul(opt_c); // -c
701 if (option_mask32 & OPT_s)
702 datalen = xatou16(opt_s); // -s
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000703 if (option_mask32 & OPT_I) { // -I
704 if_index = if_nametoindex(opt_I);
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000705 if (!if_index) {
706 /* TODO: I'm not sure it takes IPv6 unless in [XX:XX..] format */
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000707 source_lsa = xdotted2sockaddr(opt_I, 0);
Denis Vlasenko1a7afb42007-10-19 21:39:25 +0000708 opt_I = NULL; /* don't try to bind to device later */
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000709 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000710 }
Denis Vlasenko1c9ad622007-05-27 00:53:41 +0000711 myid = (uint16_t) getpid();
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000712 hostname = argv[optind];
713#if ENABLE_PING6
714 if (option_mask32 & OPT_IPV4)
715 af = AF_INET;
716 if (option_mask32 & OPT_IPV6)
717 af = AF_INET6;
Denis Vlasenko42823d52007-02-04 02:39:08 +0000718 lsa = xhost_and_af2sockaddr(hostname, 0, af);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000719#else
Denis Vlasenko42823d52007-02-04 02:39:08 +0000720 lsa = xhost_and_af2sockaddr(hostname, 0, AF_INET);
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000721#endif
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000722
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000723 if (source_lsa && source_lsa->u.sa.sa_family != lsa->u.sa.sa_family)
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000724 /* leaking it here... */
725 source_lsa = NULL;
726
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +0000727 dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
Denis Vlasenko9ca26d32007-02-09 17:32:16 +0000728 ping(lsa);
Denis Vlasenkoaeb4bdd2007-01-25 00:00:02 +0000729 pingstats(0);
Eric Andersene90e7412002-06-06 11:47:00 +0000730 return EXIT_SUCCESS;
Eric Andersen485b9551999-12-07 23:14:59 +0000731}
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000732#endif /* FEATURE_FANCY_PING */
733
734
735#if ENABLE_PING6
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000736int ping6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000737int ping6_main(int argc, char **argv)
738{
Denis Vlasenko89ef65f2007-01-29 23:43:18 +0000739 argv[0] = (char*)"-6";
Denis Vlasenkob9a279b2007-01-24 23:53:22 +0000740 return ping_main(argc + 1, argv - 1);
741}
742#endif
743
744/* from ping6.c:
745 * Copyright (c) 1989 The Regents of the University of California.
746 * All rights reserved.
747 *
748 * This code is derived from software contributed to Berkeley by
749 * Mike Muuss.
750 *
751 * Redistribution and use in source and binary forms, with or without
752 * modification, are permitted provided that the following conditions
753 * are met:
754 * 1. Redistributions of source code must retain the above copyright
755 * notice, this list of conditions and the following disclaimer.
756 * 2. Redistributions in binary form must reproduce the above copyright
757 * notice, this list of conditions and the following disclaimer in the
758 * documentation and/or other materials provided with the distribution.
759 *
760 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
761 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
762 *
763 * 4. Neither the name of the University nor the names of its contributors
764 * may be used to endorse or promote products derived from this software
765 * without specific prior written permission.
766 *
767 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
768 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
769 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
770 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
771 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
772 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
773 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
774 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
775 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
776 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
777 * SUCH DAMAGE.
778 */