static const int PINGINTERVAL = 1; /* second */
#define O_QUIET (1 << 0)
+#define O_LOG 2
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
#define CLR(bit) (A(bit) &= (~B(bit)))
#define TST(bit) (A(bit) & B(bit))
+//BRCM begin
+/* store ping statistics to a file */
+FILE *pingFile=NULL;
+FILE *pingPid=NULL;
+//BRCM end
+
static void ping(const char *host);
/* common routines */
static void pingstats(int);
static void unpack(char *, int, struct sockaddr_in *);
+static void logStat(int finish)
+{
+ char ip[16];
+ struct in_addr addr;
+
+ pingFile = fopen ("/var/pingStats", "w");
+ if (pingFile == NULL)
+ return;
+
+ rewind(pingFile);
+ if ((finish) && (ntransmitted == 0))
+ fprintf(pingFile,"%d\n",-1);
+ else
+ fprintf(pingFile,"%d\n",finish);
+
+ memcpy(&addr, hostent->h_addr, sizeof(ip));
+ strncpy(ip,inet_ntoa(addr),16);
+ /* IP, sent, receive, lost, min, max, average */
+ 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));
+
+ fclose(pingFile);
+}
+
/**************************************************************************/
static void pingstats(int junk)
int status;
signal(SIGINT, SIG_IGN);
-
printf("\n--- %s ping statistics ---\n", hostent->h_name);
printf("%ld packets transmitted, ", ntransmitted);
printf("%ld packets received, ", nreceived);
status = EXIT_SUCCESS;
else
status = EXIT_FAILURE;
+
+ //BRCM begin
+ if (options & O_LOG) {
+ logStat(1);
+ if (access("/var/pingPid",F_OK) == 0)
+ unlink("/var/pingPid");
+ }
+ //BRCM end
+
exit(status);
}
SET(icmppkt->icmp_seq % MAX_DUP_CHK);
dupflag = 0;
}
+ //BRCM begin
+ if (options & O_LOG) {
+ logStat(0);
+ usleep(1);
+ } /* O_LOG */
+ //BRCM end
if (options & O_QUIET)
return;
pingaddr.sin_family = AF_INET;
hostent = xgethostbyname(host);
+
if (hostent->h_addrtype != AF_INET)
bb_error_msg_and_die("unknown address type; only AF_INET is currently supported.");
extern int ping_main(int argc, char **argv)
{
+ FILE *fd;
char *thisarg;
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
argv++;
datalen = atoi(*argv);
break;
+ //BRCM begin
+ case 'l':
+ if ((pingPid = fopen ("/var/pingPid", "w")) != NULL) {
+ fprintf(pingPid,"%d\n",getpid());
+ (void)fclose(pingPid);
+ }
+ /* log statistics to file */
+ options |= O_LOG;
+ break;
+ //BRCM end
default:
bb_show_usage();
}
myid = getpid() & 0xFFFF;
ping(*argv);
+
+ if (options & O_LOG) {
+ if (access("/var/pingPid",F_OK) == 0) {
+ unlink("/var/pingPid");
+ }
+ }
return EXIT_SUCCESS;
}
#endif /* ! CONFIG_FEATURE_FANCY_PING */