www.usr.com/support/gpl/USR9113_release1.0.tar.gz
[bcm963xx.git] / userapps / opensource / busybox / networking / ping.c
index 00fa7ca..0a2ba49 100755 (executable)
@@ -62,7 +62,7 @@ static const int PINGINTERVAL = 1;            /* second */
 
 #define O_QUIET         (1 << 0)
 #define O_LOG           2
 
 #define O_QUIET         (1 << 0)
 #define O_LOG           2
-
+#define PING_PID_FILE   "/var/pingPid"
 #define        A(bit)          rcvd_tbl[(bit)>>3]      /* identify byte in array */
 #define        B(bit)          (1 << ((bit) & 0x07))   /* identify bit in byte */
 #define        SET(bit)        (A(bit) |= B(bit))
 #define        A(bit)          rcvd_tbl[(bit)>>3]      /* identify byte in array */
 #define        B(bit)          (1 << ((bit) & 0x07))   /* identify bit in byte */
 #define        SET(bit)        (A(bit) |= B(bit))
@@ -210,13 +210,19 @@ static void logStat(int finish)
   memcpy(&addr, hostent->h_addr, sizeof(ip));
   strncpy(ip,inet_ntoa(addr),16);
   /* IP, sent, receive, lost, min, max, average */
   memcpy(&addr, hostent->h_addr, sizeof(ip));
   strncpy(ip,inet_ntoa(addr),16);
   /* IP, sent, receive, lost, min, max, average */
+  if( nreceived )
   fprintf(pingFile,"IP = %s Sent = %ld Receive = %ld Lost = %ld Min = %lu.%lu ms Max = %lu.%lu ms  Average = %lu.%lu ms \n",
           ip, ntransmitted, nreceived, (ntransmitted-nreceived),
           (tmin / 10), (tmin % 10),
           (tmax / 10), (tmax % 10),
           ((tsum / (nreceived + nrepeats)) / 10),
           ((tsum / (nreceived + nrepeats)) % 10));
   fprintf(pingFile,"IP = %s Sent = %ld Receive = %ld Lost = %ld Min = %lu.%lu ms Max = %lu.%lu ms  Average = %lu.%lu ms \n",
           ip, ntransmitted, nreceived, (ntransmitted-nreceived),
           (tmin / 10), (tmin % 10),
           (tmax / 10), (tmax % 10),
           ((tsum / (nreceived + nrepeats)) / 10),
           ((tsum / (nreceived + nrepeats)) % 10));
-
+  else
+  fprintf(pingFile,"IP = %s Sent = %ld Receive = %ld Lost = %ld Min = %lu.%lu ms Max = %lu.%lu ms  Average = %lu.%lu ms \n",
+          ip, ntransmitted, nreceived, (ntransmitted-nreceived),
+          (tmin / 10), (tmin % 10),
+          (tmin / 10), (tmin % 10),
+          (tmin / 10), (tmin % 10));
   fclose(pingFile);
 }
 
   fclose(pingFile);
 }
 
@@ -248,8 +254,7 @@ static void pingstats(int junk)
         //BRCM begin
         if (options & O_LOG) {
           logStat(1);
         //BRCM begin
         if (options & O_LOG) {
           logStat(1);
-          if (access("/var/pingPid",F_OK) == 0)
-            unlink("/var/pingPid");
+         remove_file(PING_PID_FILE,FILEUTILS_FORCE);
         }
         //BRCM end
 
         }
         //BRCM end
 
@@ -446,7 +451,7 @@ static void ping(const char *host)
 
 extern int ping_main(int argc, char **argv)
 {
 
 extern int ping_main(int argc, char **argv)
 {
-        FILE *fd;
+  //        FILE *fd;
        char *thisarg;
 
        datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
        char *thisarg;
 
        datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
@@ -476,7 +481,7 @@ extern int ping_main(int argc, char **argv)
                        break;
                 //BRCM begin
                 case 'l':
                        break;
                 //BRCM begin
                 case 'l':
-                        if ((pingPid = fopen ("/var/pingPid", "w")) != NULL) {
+                        if ((pingPid = fopen (PING_PID_FILE, "w")) != NULL) {
                           fprintf(pingPid,"%d\n",getpid());
                           (void)fclose(pingPid);
                         }
                           fprintf(pingPid,"%d\n",getpid());
                           (void)fclose(pingPid);
                         }
@@ -497,9 +502,7 @@ extern int ping_main(int argc, char **argv)
        ping(*argv);
 
         if (options & O_LOG) {
        ping(*argv);
 
         if (options & O_LOG) {
-          if (access("/var/pingPid",F_OK) == 0) {
-            unlink("/var/pingPid");
-          }
+         remove_file(PING_PID_FILE,FILEUTILS_FORCE);
         }
        return EXIT_SUCCESS;
 }
         }
        return EXIT_SUCCESS;
 }