Bug 13401 - "ping URL -w 6" always fail
Summary: "ping URL -w 6" always fail
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Networking (show other bugs)
Version: 1.31.x
Hardware: All Linux
: P1 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-19 18:21 UTC by jiangjun.jking
Modified: 2020-12-21 05:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jiangjun.jking 2020-12-19 18:21:50 UTC
ping someurl with -w arguments, it always failed

### EXAMPLE OUTPUT
=========================
$ ./busybox ping www.baidu.com -w 6
PING www.baidu.com (180.101.49.11): 56 data bytes
64 bytes from 180.101.49.11: seq=0 ttl=51 time=10.078 ms
64 bytes from 180.101.49.11: seq=1 ttl=51 time=10.097 ms
64 bytes from 180.101.49.11: seq=2 ttl=51 time=10.109 ms
64 bytes from 180.101.49.11: seq=3 ttl=51 time=10.124 ms
64 bytes from 180.101.49.11: seq=4 ttl=51 time=10.104 ms
64 bytes from 180.101.49.11: seq=5 ttl=51 time=10.084 ms

--- www.baidu.com ping statistics ---
7 packets transmitted, 6 packets received, 14% packet loss
round-trip min/avg/max = 10.078/10.099/10.124 ms

------------------

From above, the transmitted packets number is always bigger than the packets received by 1.


### SUGGESTED FIX:
=====================


diff --git a/networking/ping.c b/networking/ping.c                                   
index a47342f..b8d1a14 100644                                                        
--- a/networking/ping.c                                                              
+++ b/networking/ping.c                                                              
@@ -468,7 +468,6 @@ static void sendping_tail(void (*sp)(int), int size_pkt)         
    int sz;                                                                          
                                                                                     
    CLR((uint16_t)G.ntransmitted % MAX_DUP_CHK);                                     
-   G.ntransmitted++;                                                                
                                                                                     
    size_pkt += datalen;                                                             
                                                                                     
@@ -478,6 +477,8 @@ static void sendping_tail(void (*sp)(int), int size_pkt)         
            print_stats_and_exit(0);                                                 
    }                                                                                
                                                                                     
+   G.ntransmitted++;                                                                
+                                                                                    
    /* sizeof(pingaddr) can be larger than real sa size, but I think                 
     * it doesn't matter */                                                          
    sz = xsendto(pingsock, G.snd_packet, size_pkt, &pingaddr.sa, sizeof(pingaddr));
Comment 1 Denys Vlasenko 2020-12-21 05:31:37 UTC
fixed in git