aboutsummaryrefslogtreecommitdiff
path: root/networking/ping.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 14:04:27 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 14:04:27 +0000
commit35d4da0fb5884236fa7a131a13416268239c9e69 (patch)
tree1598327194a13be915980de0cb8be6a84e5c362c /networking/ping.c
parent85629f08bcea5d4a44b6d511422fd608bbc3fc45 (diff)
downloadbusybox-w32-35d4da0fb5884236fa7a131a13416268239c9e69.tar.gz
busybox-w32-35d4da0fb5884236fa7a131a13416268239c9e69.tar.bz2
busybox-w32-35d4da0fb5884236fa7a131a13416268239c9e69.zip
exterminate u_intXXX.
fix ping6 buglet (memset is too short), minor sync between ping and ping6
Diffstat (limited to 'networking/ping.c')
-rw-r--r--networking/ping.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/networking/ping.c b/networking/ping.c
index 12730bec5..d8a70334d 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -1,13 +1,15 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * $Id: ping.c,v 1.56 2004/03/15 08:28:48 andersen Exp $
4 * Mini ping implementation for busybox 3 * Mini ping implementation for busybox
5 * 4 *
6 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> 5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
7 * 6 *
8 * Adapted from the ping in netkit-base 0.10: 7 * Adapted from the ping in netkit-base 0.10:
9 * Copyright (c) 1989 The Regents of the University of California. 8 * Copyright (c) 1989 The Regents of the University of California.
10 * Derived from software contributed to Berkeley by Mike Muuss. 9 * All rights reserved.
10 *
11 * This code is derived from software contributed to Berkeley by
12 * Mike Muuss.
11 * 13 *
12 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 14 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 */ 15 */
@@ -74,7 +76,7 @@ static void ping(const char *host)
74 76
75 pingsock = create_icmp_socket(); 77 pingsock = create_icmp_socket();
76 78
77 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 79 memset(&pingaddr, 0, sizeof(pingaddr));
78 80
79 pingaddr.sin_family = AF_INET; 81 pingaddr.sin_family = AF_INET;
80 h = xgethostbyname(host); 82 h = xgethostbyname(host);
@@ -202,7 +204,7 @@ static void sendping(int junk)
202 pkt->icmp_cksum = 0; 204 pkt->icmp_cksum = 0;
203 pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */ 205 pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
204 pkt->icmp_id = myid; 206 pkt->icmp_id = myid;
205 CLR(ntohs(pkt->icmp_seq) % MAX_DUP_CHK); 207 CLR((uint16_t)ntransmitted % MAX_DUP_CHK);
206 ntransmitted++; 208 ntransmitted++;
207 209
208 gettimeofday((struct timeval *) &pkt->icmp_dun, NULL); 210 gettimeofday((struct timeval *) &pkt->icmp_dun, NULL);
@@ -230,20 +232,20 @@ static void sendping(int junk)
230static char *icmp_type_name(int id) 232static char *icmp_type_name(int id)
231{ 233{
232 switch (id) { 234 switch (id) {
233 case ICMP_ECHOREPLY: return "Echo Reply"; 235 case ICMP_ECHOREPLY: return "Echo Reply";
234 case ICMP_DEST_UNREACH: return "Destination Unreachable"; 236 case ICMP_DEST_UNREACH: return "Destination Unreachable";
235 case ICMP_SOURCE_QUENCH: return "Source Quench"; 237 case ICMP_SOURCE_QUENCH: return "Source Quench";
236 case ICMP_REDIRECT: return "Redirect (change route)"; 238 case ICMP_REDIRECT: return "Redirect (change route)";
237 case ICMP_ECHO: return "Echo Request"; 239 case ICMP_ECHO: return "Echo Request";
238 case ICMP_TIME_EXCEEDED: return "Time Exceeded"; 240 case ICMP_TIME_EXCEEDED: return "Time Exceeded";
239 case ICMP_PARAMETERPROB: return "Parameter Problem"; 241 case ICMP_PARAMETERPROB: return "Parameter Problem";
240 case ICMP_TIMESTAMP: return "Timestamp Request"; 242 case ICMP_TIMESTAMP: return "Timestamp Request";
241 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply"; 243 case ICMP_TIMESTAMPREPLY: return "Timestamp Reply";
242 case ICMP_INFO_REQUEST: return "Information Request"; 244 case ICMP_INFO_REQUEST: return "Information Request";
243 case ICMP_INFO_REPLY: return "Information Reply"; 245 case ICMP_INFO_REPLY: return "Information Reply";
244 case ICMP_ADDRESS: return "Address Mask Request"; 246 case ICMP_ADDRESS: return "Address Mask Request";
245 case ICMP_ADDRESSREPLY: return "Address Mask Reply"; 247 case ICMP_ADDRESSREPLY: return "Address Mask Reply";
246 default: return "unknown ICMP type"; 248 default: return "unknown ICMP type";
247 } 249 }
248} 250}
249 251
@@ -270,7 +272,7 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
270 return; /* not our ping */ 272 return; /* not our ping */
271 273
272 if (icmppkt->icmp_type == ICMP_ECHOREPLY) { 274 if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
273 u_int16_t recv_seq = ntohs(icmppkt->icmp_seq); 275 uint16_t recv_seq = ntohs(icmppkt->icmp_seq);
274 ++nreceived; 276 ++nreceived;
275 tp = (struct timeval *) icmppkt->icmp_data; 277 tp = (struct timeval *) icmppkt->icmp_data;
276 278
@@ -307,11 +309,12 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
307 if (dupflag) 309 if (dupflag)
308 printf(" (DUP!)"); 310 printf(" (DUP!)");
309 puts(""); 311 puts("");
310 } else 312 } else {
311 if (icmppkt->icmp_type != ICMP_ECHO) 313 if (icmppkt->icmp_type != ICMP_ECHO)
312 bb_error_msg("warning: got ICMP %d (%s)", 314 bb_error_msg("warning: got ICMP %d (%s)",
313 icmppkt->icmp_type, 315 icmppkt->icmp_type,
314 icmp_type_name(icmppkt->icmp_type)); 316 icmp_type_name(icmppkt->icmp_type));
317 }
315 fflush(stdout); 318 fflush(stdout);
316} 319}
317 320
@@ -326,7 +329,7 @@ static void ping(const char *host)
326 xbind(pingsock, (struct sockaddr*)&sourceaddr, sizeof(sourceaddr)); 329 xbind(pingsock, (struct sockaddr*)&sourceaddr, sizeof(sourceaddr));
327 } 330 }
328 331
329 memset(&pingaddr, 0, sizeof(struct sockaddr_in)); 332 memset(&pingaddr, 0, sizeof(pingaddr));
330 333
331 pingaddr.sin_family = AF_INET; 334 pingaddr.sin_family = AF_INET;
332 hostent = xgethostbyname(host); 335 hostent = xgethostbyname(host);
@@ -339,7 +342,7 @@ static void ping(const char *host)
339 setsockopt_broadcast(pingsock); 342 setsockopt_broadcast(pingsock);
340 343
341 /* set recv buf for broadcast pings */ 344 /* set recv buf for broadcast pings */
342 sockopt = 48 * 1024; 345 sockopt = 48 * 1024; /* explain why 48k? */
343 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt, 346 setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
344 sizeof(sockopt)); 347 sizeof(sockopt));
345 348