summaryrefslogtreecommitdiff
path: root/networking/ping.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2002-02-01 16:54:00 +0000
committerMatt Kraai <kraai@debian.org>2002-02-01 16:54:00 +0000
commit369da77d5eb818e7a6f1e5e5829a4066e7785680 (patch)
tree5806bf7476fc081bc78f75eaf57967d829b657af /networking/ping.c
parent20d739adf7fb1542015537dbdb969689118ceb02 (diff)
downloadbusybox-w32-369da77d5eb818e7a6f1e5e5829a4066e7785680.tar.gz
busybox-w32-369da77d5eb818e7a6f1e5e5829a4066e7785680.tar.bz2
busybox-w32-369da77d5eb818e7a6f1e5e5829a4066e7785680.zip
2002-01-30 Neal H Walfield <neal@cs.uml.edu>
* networking/ping.c (hostname): Removed. [CONFIG_FEATURE_FANCY_PING] (noresp): Moved from here . . . [CONFIG_FEATURE_FANCY_PING] (ping:noresp): . . . to here. Use H->h_name, not hostname. [CONFIG_FEATURE_FANCY_PING] (ping): Do not copy H->h_name into hostname. Use H->h_name directly. [!CONFIG_FEATURE_FANCY_PING] (hostent): New global variable. [!CONFIG_FEATURE_FANCY_PING] (pingstats): Use hostent in favor of the now obsolete hostname global variable. [!CONFIG_FEATURE_FANCY_PING] (ping): Likewise. No need to copy H; use hostent instead. [!CONFIG_FEATURE_FANCY_PING] (ntransmitted, nreceived, nrepeats, pingcount, myid, options, tmax, tsum): Removed superfluous zero initializers.
Diffstat (limited to 'networking/ping.c')
-rw-r--r--networking/ping.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 476c15cea..eaaf91a04 100644
--- a/networking/ping.c
+++ b/networking/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.47 2001/10/24 04:59:56 andersen Exp $ 3 * $Id: ping.c,v 1.48 2002/02/01 16:54:00 kraai 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>
@@ -175,13 +175,6 @@ static int in_cksum(unsigned short *buf, int sz)
175 175
176/* simple version */ 176/* simple version */
177#ifndef CONFIG_FEATURE_FANCY_PING 177#ifndef CONFIG_FEATURE_FANCY_PING
178static char *hostname = NULL;
179
180static void noresp(int ign)
181{
182 printf("No response from %s\n", hostname);
183 exit(0);
184}
185 178
186static void ping(const char *host) 179static void ping(const char *host)
187{ 180{
@@ -191,6 +184,12 @@ static void ping(const char *host)
191 int pingsock, c; 184 int pingsock, c;
192 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; 185 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
193 186
187 void noresp(int ign)
188 {
189 printf("No response from %s\n", h->h_name);
190 exit(0);
191 }
192
194 pingsock = create_icmp_socket(); 193 pingsock = create_icmp_socket();
195 194
196 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 195 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
@@ -198,7 +197,6 @@ static void ping(const char *host)
198 pingaddr.sin_family = AF_INET; 197 pingaddr.sin_family = AF_INET;
199 h = xgethostbyname(host); 198 h = xgethostbyname(host);
200 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr)); 199 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
201 hostname = h->h_name;
202 200
203 pkt = (struct icmp *) packet; 201 pkt = (struct icmp *) packet;
204 memset(pkt, 0, sizeof(packet)); 202 memset(pkt, 0, sizeof(packet));
@@ -233,7 +231,7 @@ static void ping(const char *host)
233 break; 231 break;
234 } 232 }
235 } 233 }
236 printf("%s is alive!\n", hostname); 234 printf("%s is alive!\n", h->h_name);
237 return; 235 return;
238} 236}
239 237
@@ -249,16 +247,17 @@ extern int ping_main(int argc, char **argv)
249 247
250#else /* ! CONFIG_FEATURE_FANCY_PING */ 248#else /* ! CONFIG_FEATURE_FANCY_PING */
251/* full(er) version */ 249/* full(er) version */
252static char *hostname = NULL;
253static struct sockaddr_in pingaddr; 250static struct sockaddr_in pingaddr;
254static int pingsock = -1; 251static int pingsock = -1;
255static int datalen; /* intentionally uninitialized to work around gcc bug */ 252static int datalen; /* intentionally uninitialized to work around gcc bug */
256 253
257static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0; 254static long ntransmitted, nreceived, nrepeats, pingcount;
258static int myid = 0, options = 0; 255static int myid, options;
259static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0; 256static unsigned long tmin = ULONG_MAX, tmax, tsum;
260static char rcvd_tbl[MAX_DUP_CHK / 8]; 257static char rcvd_tbl[MAX_DUP_CHK / 8];
261 258
259struct hostent *hostent;
260
262static void sendping(int); 261static void sendping(int);
263static void pingstats(int); 262static void pingstats(int);
264static void unpack(char *, int, struct sockaddr_in *); 263static void unpack(char *, int, struct sockaddr_in *);
@@ -271,7 +270,7 @@ static void pingstats(int junk)
271 270
272 signal(SIGINT, SIG_IGN); 271 signal(SIGINT, SIG_IGN);
273 272
274 printf("\n--- %s ping statistics ---\n", hostname); 273 printf("\n--- %s ping statistics ---\n", hostent->h_name);
275 printf("%ld packets transmitted, ", ntransmitted); 274 printf("%ld packets transmitted, ", ntransmitted);
276 printf("%ld packets received, ", nreceived); 275 printf("%ld packets received, ", nreceived);
277 if (nrepeats) 276 if (nrepeats)
@@ -416,8 +415,6 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
416 415
417static void ping(const char *host) 416static void ping(const char *host)
418{ 417{
419 struct hostent *h;
420 char buf[MAXHOSTNAMELEN];
421 char packet[datalen + MAXIPLEN + MAXICMPLEN]; 418 char packet[datalen + MAXIPLEN + MAXICMPLEN];
422 int sockopt; 419 int sockopt;
423 420
@@ -426,13 +423,11 @@ static void ping(const char *host)
426 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 423 memset(&pingaddr, 0, sizeof(struct sockaddr_in));
427 424
428 pingaddr.sin_family = AF_INET; 425 pingaddr.sin_family = AF_INET;
429 h = xgethostbyname(host); 426 hostent = xgethostbyname(host);
430 if (h->h_addrtype != AF_INET) 427 if (hostent->h_addrtype != AF_INET)
431 error_msg_and_die("unknown address type; only AF_INET is currently supported."); 428 error_msg_and_die("unknown address type; only AF_INET is currently supported.");
432 429
433 memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr)); 430 memcpy(&pingaddr.sin_addr, hostent->h_addr, sizeof(pingaddr.sin_addr));
434 strncpy(buf, h->h_name, sizeof(buf) - 1);
435 hostname = buf;
436 431
437 /* enable broadcast pings */ 432 /* enable broadcast pings */
438 sockopt = 1; 433 sockopt = 1;
@@ -445,7 +440,7 @@ static void ping(const char *host)
445 sizeof(sockopt)); 440 sizeof(sockopt));
446 441
447 printf("PING %s (%s): %d data bytes\n", 442 printf("PING %s (%s): %d data bytes\n",
448 hostname, 443 hostent->h_name,
449 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr), 444 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr),
450 datalen); 445 datalen);
451 446