aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-02 16:13:36 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-02 16:13:36 +0000
commitcb6874cc66df69fe49c65338a67fec1206d02c4b (patch)
tree456f9bab87457df640ee305716b000f87ed6285c
parentd53dd3e627d158953c124107dae1c7ca48ca0a55 (diff)
downloadbusybox-w32-cb6874cc66df69fe49c65338a67fec1206d02c4b.tar.gz
busybox-w32-cb6874cc66df69fe49c65338a67fec1206d02c4b.tar.bz2
busybox-w32-cb6874cc66df69fe49c65338a67fec1206d02c4b.zip
Sync ping and ping6 a bit, fix style and indentation.
-rw-r--r--networking/ping.c19
-rw-r--r--networking/ping6.c48
2 files changed, 32 insertions, 35 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 5cd6f4a1a..8ccb7e0bf 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -31,7 +31,6 @@
31#include <stdlib.h> 31#include <stdlib.h>
32#include "busybox.h" 32#include "busybox.h"
33 33
34
35enum { 34enum {
36 DEFDATALEN = 56, 35 DEFDATALEN = 56,
37 MAXIPLEN = 60, 36 MAXIPLEN = 60,
@@ -78,7 +77,8 @@ static int in_cksum(unsigned short *buf, int sz)
78 77
79/* simple version */ 78/* simple version */
80#ifndef CONFIG_FEATURE_FANCY_PING 79#ifndef CONFIG_FEATURE_FANCY_PING
81static char *hostname = NULL; 80static char *hostname;
81
82static void noresp(int ign) 82static void noresp(int ign)
83{ 83{
84 printf("No response from %s\n", hostname); 84 printf("No response from %s\n", hostname);
@@ -163,10 +163,7 @@ static int myid, options;
163static unsigned long tmin = ULONG_MAX, tmax, tsum; 163static unsigned long tmin = ULONG_MAX, tmax, tsum;
164static char rcvd_tbl[MAX_DUP_CHK / 8]; 164static char rcvd_tbl[MAX_DUP_CHK / 8];
165 165
166#ifndef CONFIG_FEATURE_FANCY_PING6 166static struct hostent *hostent;
167static
168#endif
169 struct hostent *hostent;
170 167
171static void sendping(int); 168static void sendping(int);
172static void pingstats(int); 169static void pingstats(int);
@@ -278,11 +275,11 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
278 icmppkt = (struct icmp *) (buf + hlen); 275 icmppkt = (struct icmp *) (buf + hlen);
279 276
280 if (icmppkt->icmp_id != myid) 277 if (icmppkt->icmp_id != myid)
281 return; /* not our ping */ 278 return; /* not our ping */
282 279
283 if (icmppkt->icmp_type == ICMP_ECHOREPLY) { 280 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
284 u_int16_t recv_seq = ntohs(icmppkt->icmp_seq); 281 u_int16_t recv_seq = ntohs(icmppkt->icmp_seq);
285 ++nreceived; 282 ++nreceived;
286 tp = (struct timeval *) icmppkt->icmp_data; 283 tp = (struct timeval *) icmppkt->icmp_data;
287 284
288 if ((tv.tv_usec -= tp->tv_usec) < 0) { 285 if ((tv.tv_usec -= tp->tv_usec) < 0) {
@@ -352,7 +349,7 @@ static void ping(const char *host)
352 sizeof(sockopt)); 349 sizeof(sockopt));
353 350
354 printf("PING %s (%s): %d data bytes\n", 351 printf("PING %s (%s): %d data bytes\n",
355 hostent->h_name, 352 hostent->h_name,
356 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr), 353 inet_ntoa(*(struct in_addr *) &pingaddr.sin_addr.s_addr),
357 datalen); 354 datalen);
358 355
@@ -400,13 +397,13 @@ int ping_main(int argc, char **argv)
400 break; 397 break;
401 case 'c': 398 case 'c':
402 if (--argc <= 0) 399 if (--argc <= 0)
403 bb_show_usage(); 400 bb_show_usage();
404 argv++; 401 argv++;
405 pingcount = atoi(*argv); 402 pingcount = atoi(*argv);
406 break; 403 break;
407 case 's': 404 case 's':
408 if (--argc <= 0) 405 if (--argc <= 0)
409 bb_show_usage(); 406 bb_show_usage();
410 argv++; 407 argv++;
411 datalen = atoi(*argv); 408 datalen = atoi(*argv);
412 break; 409 break;
diff --git a/networking/ping6.c b/networking/ping6.c
index fd695f1fc..fdcd4ec46 100644
--- a/networking/ping6.c
+++ b/networking/ping6.c
@@ -68,7 +68,7 @@ static void ping(const char *host);
68#ifndef CONFIG_FEATURE_FANCY_PING6 68#ifndef CONFIG_FEATURE_FANCY_PING6
69static struct hostent *h; 69static struct hostent *h;
70 70
71void noresp(int ign) 71static void noresp(int ign)
72{ 72{
73 printf("No response from %s\n", h->h_name); 73 printf("No response from %s\n", h->h_name);
74 exit(EXIT_FAILURE); 74 exit(EXIT_FAILURE);
@@ -101,8 +101,10 @@ static void ping(const char *host)
101 c = sendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), 0, 101 c = sendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), 0,
102 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in6)); 102 (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in6));
103 103
104 if (c < 0 || c != sizeof(packet)) 104 if (c < 0 || c != sizeof(packet)) {
105 if (ENABLE_FEATURE_CLEAN_UP) close(pingsock);
105 bb_perror_msg_and_die("sendto"); 106 bb_perror_msg_and_die("sendto");
107 }
106 108
107 signal(SIGALRM, noresp); 109 signal(SIGALRM, noresp);
108 alarm(5); /* give the host 5000ms to respond */ 110 alarm(5); /* give the host 5000ms to respond */
@@ -124,6 +126,7 @@ static void ping(const char *host)
124 break; 126 break;
125 } 127 }
126 } 128 }
129 if (ENABLE_FEATURE_CLEAN_UP) close(pingsock);
127 printf("%s is alive!\n", h->h_name); 130 printf("%s is alive!\n", h->h_name);
128 return; 131 return;
129} 132}
@@ -150,10 +153,7 @@ static int myid, options;
150static unsigned long tmin = ULONG_MAX, tmax, tsum; 153static unsigned long tmin = ULONG_MAX, tmax, tsum;
151static char rcvd_tbl[MAX_DUP_CHK / 8]; 154static char rcvd_tbl[MAX_DUP_CHK / 8];
152 155
153# ifdef CONFIG_FEATURE_FANCY_PING 156static struct hostent *hostent;
154extern
155# endif
156 struct hostent *hostent;
157 157
158static void sendping(int); 158static void sendping(int);
159static void pingstats(int); 159static void pingstats(int);
@@ -267,10 +267,10 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit
267 icmppkt = (struct icmp6_hdr *) packet; 267 icmppkt = (struct icmp6_hdr *) packet;
268 268
269 if (icmppkt->icmp6_id != myid) 269 if (icmppkt->icmp6_id != myid)
270 return; /* not our ping */ 270 return; /* not our ping */
271 271
272 if (icmppkt->icmp6_type == ICMP6_ECHO_REPLY) { 272 if (icmppkt->icmp6_type == ICMP6_ECHO_REPLY) {
273 ++nreceived; 273 ++nreceived;
274 tp = (struct timeval *) &icmppkt->icmp6_data8[4]; 274 tp = (struct timeval *) &icmppkt->icmp6_data8[4];
275 275
276 if ((tv.tv_usec -= tp->tv_usec) < 0) { 276 if ((tv.tv_usec -= tp->tv_usec) < 0) {
@@ -339,7 +339,7 @@ static void ping(const char *host)
339 struct icmp6_filter filt; 339 struct icmp6_filter filt;
340 if (!(options & O_VERBOSE)) { 340 if (!(options & O_VERBOSE)) {
341 ICMP6_FILTER_SETBLOCKALL(&filt); 341 ICMP6_FILTER_SETBLOCKALL(&filt);
342 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt); 342 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt);
343 } else { 343 } else {
344 ICMP6_FILTER_SETPASSALL(&filt); 344 ICMP6_FILTER_SETPASSALL(&filt);
345 } 345 }
@@ -374,8 +374,8 @@ static void ping(const char *host)
374 374
375 printf("PING %s (%s): %d data bytes\n", 375 printf("PING %s (%s): %d data bytes\n",
376 hostent->h_name, 376 hostent->h_name,
377 inet_ntop(AF_INET6, &pingaddr.sin6_addr, 377 inet_ntop(AF_INET6, &pingaddr.sin6_addr,
378 buf, sizeof(buf)), 378 buf, sizeof(buf)),
379 datalen); 379 datalen);
380 380
381 signal(SIGINT, pingstats); 381 signal(SIGINT, pingstats);
@@ -384,18 +384,18 @@ static void ping(const char *host)
384 sendping(0); 384 sendping(0);
385 385
386 /* listen for replies */ 386 /* listen for replies */
387 msg.msg_name=&from; 387 msg.msg_name = &from;
388 msg.msg_namelen=sizeof(from); 388 msg.msg_namelen = sizeof(from);
389 msg.msg_iov=&iov; 389 msg.msg_iov = &iov;
390 msg.msg_iovlen=1; 390 msg.msg_iovlen = 1;
391 msg.msg_control=control_buf; 391 msg.msg_control = control_buf;
392 iov.iov_base=packet; 392 iov.iov_base = packet;
393 iov.iov_len=sizeof(packet); 393 iov.iov_len = sizeof(packet);
394 while (1) { 394 while (1) {
395 int c; 395 int c;
396 struct cmsghdr *cmsgptr = NULL; 396 struct cmsghdr *cmsgptr = NULL;
397 int hoplimit=-1; 397 int hoplimit = -1;
398 msg.msg_controllen=sizeof(control_buf); 398 msg.msg_controllen = sizeof(control_buf);
399 399
400 if ((c = recvmsg(pingsock, &msg, 0)) < 0) { 400 if ((c = recvmsg(pingsock, &msg, 0)) < 0) {
401 if (errno == EINTR) 401 if (errno == EINTR)
@@ -407,7 +407,7 @@ static void ping(const char *host)
407 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { 407 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
408 if (cmsgptr->cmsg_level == SOL_IPV6 && 408 if (cmsgptr->cmsg_level == SOL_IPV6 &&
409 cmsgptr->cmsg_type == IPV6_HOPLIMIT ) { 409 cmsgptr->cmsg_type == IPV6_HOPLIMIT ) {
410 hoplimit=*(int*)CMSG_DATA(cmsgptr); 410 hoplimit = *(int*)CMSG_DATA(cmsgptr);
411 } 411 }
412 } 412 }
413 unpack(packet, c, &from, hoplimit); 413 unpack(packet, c, &from, hoplimit);
@@ -441,19 +441,19 @@ int ping6_main(int argc, char **argv)
441 break; 441 break;
442 case 'c': 442 case 'c':
443 if (--argc <= 0) 443 if (--argc <= 0)
444 bb_show_usage(); 444 bb_show_usage();
445 argv++; 445 argv++;
446 pingcount = atoi(*argv); 446 pingcount = atoi(*argv);
447 break; 447 break;
448 case 's': 448 case 's':
449 if (--argc <= 0) 449 if (--argc <= 0)
450 bb_show_usage(); 450 bb_show_usage();
451 argv++; 451 argv++;
452 datalen = atoi(*argv); 452 datalen = atoi(*argv);
453 break; 453 break;
454 case 'I': 454 case 'I':
455 if (--argc <= 0) 455 if (--argc <= 0)
456 bb_show_usage(); 456 bb_show_usage();
457 argv++; 457 argv++;
458 ifname = *argv; 458 ifname = *argv;
459 break; 459 break;