aboutsummaryrefslogtreecommitdiff
path: root/ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'ping.c')
-rw-r--r--ping.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/ping.c b/ping.c
index dca4c3cfe..9f83002a2 100644
--- a/ping.c
+++ b/ping.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: ping.c,v 1.13 2000/04/21 01:26:49 erik Exp $ 3 * $Id: ping.c,v 1.14 2000/04/25 23:24:55 erik Exp $
4 * Mini ping implementation for busybox 4 * Mini ping implementation for busybox
5 * 5 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -262,6 +262,26 @@ static void sendping(int ign)
262 } 262 }
263} 263}
264 264
265static char *icmp_type_name (int id)
266{
267 switch (id) {
268 case ICMP_ECHOREPLY: return "Echo Reply";
269 case ICMP_DEST_UNREACH: return "Destination Unreachable";
270 case ICMP_SOURCE_QUENCH: return "Source Quench";
271 case ICMP_REDIRECT: return "Redirect (change route)";
272 case ICMP_ECHO: return "Echo Request";
273 case ICMP_TIME_EXCEEDED: return "Time Exceeded";
274 case ICMP_PARAMETERPROB: return "Parameter Problem";
275 case ICMP_TIMESTAMP: return "Timestamp Request";
276 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
277 case ICMP_INFO_REQUEST: return "Information Request";
278 case ICMP_INFO_REPLY: return "Information Reply";
279 case ICMP_ADDRESS: return "Address Mask Request";
280 case ICMP_ADDRESSREPLY: return "Address Mask Reply";
281 default: return "unknown ICMP type";
282 }
283}
284
265static void unpack(char *buf, int sz, struct sockaddr_in *from) 285static void unpack(char *buf, int sz, struct sockaddr_in *from)
266{ 286{
267 struct icmp *icmppkt; 287 struct icmp *icmppkt;
@@ -282,10 +302,11 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
282 sz -= hlen; 302 sz -= hlen;
283 icmppkt = (struct icmp *) (buf + hlen); 303 icmppkt = (struct icmp *) (buf + hlen);
284 304
305 if (icmppkt->icmp_id != myid)
306 return; /* not our ping */
307
285 if (icmppkt->icmp_type == ICMP_ECHOREPLY) { 308 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
286 if (icmppkt->icmp_id != myid) 309 ++nreceived;
287 return; /* not our ping */
288 ++nreceived;
289 tp = (struct timeval *) icmppkt->icmp_data; 310 tp = (struct timeval *) icmppkt->icmp_data;
290 311
291 if ((tv.tv_usec -= tp->tv_usec) < 0) { 312 if ((tv.tv_usec -= tp->tv_usec) < 0) {
@@ -321,10 +342,11 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
321 if (dupflag) 342 if (dupflag)
322 printf(" (DUP!)"); 343 printf(" (DUP!)");
323 printf("\n"); 344 printf("\n");
324 } else { 345 } else
325 fprintf(stderr, 346 if (icmppkt->icmp_type != ICMP_ECHO)
326 "Warning: unknown ICMP packet received (not echo-reply)\n"); 347 fprintf(stderr,
327 } 348 "Warning: Got ICMP %d (%s)\n",
349 icmppkt->icmp_type, icmp_type_name (icmppkt->icmp_type));
328} 350}
329 351
330static void ping(char *host) 352static void ping(char *host)