diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-09-15 01:32:48 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-09-15 01:32:48 +0000 |
commit | 887a1ad57fe978cd320be358effbe66df8a068bf (patch) | |
tree | 1f5cf363b8942804390e44e43051b2dcb2258628 /networking/ping.c | |
parent | 23f62fc6f3b8d01a953266ddd404c392b128c952 (diff) | |
download | busybox-w32-887a1ad57fe978cd320be358effbe66df8a068bf.tar.gz busybox-w32-887a1ad57fe978cd320be358effbe66df8a068bf.tar.bz2 busybox-w32-887a1ad57fe978cd320be358effbe66df8a068bf.zip |
BsAtHome writes in Bug 433:
Ping packets sent by busybox have wrong endian on f.x. mips32 (openwrt). Attatched is a patch that
uses htons() and ntohs() to be platform independent.
Diffstat (limited to 'networking/ping.c')
-rw-r--r-- | networking/ping.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/networking/ping.c b/networking/ping.c index bba37a025..b36ab1881 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -226,9 +226,9 @@ static void sendping(int junk) | |||
226 | pkt->icmp_type = ICMP_ECHO; | 226 | pkt->icmp_type = ICMP_ECHO; |
227 | pkt->icmp_code = 0; | 227 | pkt->icmp_code = 0; |
228 | pkt->icmp_cksum = 0; | 228 | pkt->icmp_cksum = 0; |
229 | pkt->icmp_seq = ntransmitted++; | 229 | pkt->icmp_seq = htons(ntransmitted++); |
230 | pkt->icmp_id = myid; | 230 | pkt->icmp_id = myid; |
231 | CLR(pkt->icmp_seq % MAX_DUP_CHK); | 231 | CLR(ntohs(pkt->icmp_seq) % MAX_DUP_CHK); |
232 | 232 | ||
233 | gettimeofday((struct timeval *) &packet[8], NULL); | 233 | gettimeofday((struct timeval *) &packet[8], NULL); |
234 | pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet)); | 234 | pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet)); |
@@ -296,6 +296,7 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
296 | return; /* not our ping */ | 296 | return; /* not our ping */ |
297 | 297 | ||
298 | if (icmppkt->icmp_type == ICMP_ECHOREPLY) { | 298 | if (icmppkt->icmp_type == ICMP_ECHOREPLY) { |
299 | u_int16_t recv_seq = ntohs(icmppkt->icmp_seq); | ||
299 | ++nreceived; | 300 | ++nreceived; |
300 | tp = (struct timeval *) icmppkt->icmp_data; | 301 | tp = (struct timeval *) icmppkt->icmp_data; |
301 | 302 | ||
@@ -312,12 +313,12 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
312 | if (triptime > tmax) | 313 | if (triptime > tmax) |
313 | tmax = triptime; | 314 | tmax = triptime; |
314 | 315 | ||
315 | if (TST(icmppkt->icmp_seq % MAX_DUP_CHK)) { | 316 | if (TST(recv_seq % MAX_DUP_CHK)) { |
316 | ++nrepeats; | 317 | ++nrepeats; |
317 | --nreceived; | 318 | --nreceived; |
318 | dupflag = 1; | 319 | dupflag = 1; |
319 | } else { | 320 | } else { |
320 | SET(icmppkt->icmp_seq % MAX_DUP_CHK); | 321 | SET(recv_seq % MAX_DUP_CHK); |
321 | dupflag = 0; | 322 | dupflag = 0; |
322 | } | 323 | } |
323 | 324 | ||
@@ -326,7 +327,7 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
326 | 327 | ||
327 | printf("%d bytes from %s: icmp_seq=%u", sz, | 328 | printf("%d bytes from %s: icmp_seq=%u", sz, |
328 | inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr), | 329 | inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr), |
329 | icmppkt->icmp_seq); | 330 | recv_seq); |
330 | printf(" ttl=%d", iphdr->ttl); | 331 | printf(" ttl=%d", iphdr->ttl); |
331 | printf(" time=%lu.%lu ms", triptime / 10, triptime % 10); | 332 | printf(" time=%lu.%lu ms", triptime / 10, triptime % 10); |
332 | if (dupflag) | 333 | if (dupflag) |