[BACK]Return to ping.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sbin / ping

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sbin/ping/ping.c between version 1.102 and 1.102.6.4

version 1.102, 2012/01/04 16:09:42 version 1.102.6.4, 2014/08/20 00:02:27
Line 116  __RCSID("$NetBSD$");
Line 116  __RCSID("$NetBSD$");
 #define F_TIMING64      0x10000         /* 64 bit time, nanoseconds */  #define F_TIMING64      0x10000         /* 64 bit time, nanoseconds */
 #ifdef IPSEC  #ifdef IPSEC
 #ifdef IPSEC_POLICY_IPSEC  #ifdef IPSEC_POLICY_IPSEC
 #define F_POLICY        0x10000  #define F_POLICY        0x20000
 #else  #else
 #define F_AUTHHDR       0x10000  #define F_AUTHHDR       0x20000
 #define F_ENCRYPT       0x20000  #define F_ENCRYPT       0x40000
 #endif /*IPSEC_POLICY_IPSEC*/  #endif /*IPSEC_POLICY_IPSEC*/
 #endif /*IPSEC*/  #endif /*IPSEC*/
   
Line 467  main(int argc, char *argv[])
Line 467  main(int argc, char *argv[])
                 phdrlen = PHDR_LEN;                  phdrlen = PHDR_LEN;
         } else          } else
                 phdrlen = 0;                  phdrlen = 0;
         datalen -= phdrlen;  
   
         packlen = datalen + 60 + 76;    /* MAXIP + MAXICMP */          packlen = datalen + 60 + 76;    /* MAXIP + MAXICMP */
           datalen -= phdrlen;
         if ((packet = malloc(packlen)) == NULL)          if ((packet = malloc(packlen)) == NULL)
                 err(1, "Out of memory");                  err(1, "Out of memory");
   
Line 637  main(int argc, char *argv[])
Line 637  main(int argc, char *argv[])
 #endif /*IPSEC*/  #endif /*IPSEC*/
   
         (void)printf("PING %s (%s): %d data bytes\n", hostname,          (void)printf("PING %s (%s): %d data bytes\n", hostname,
                      inet_ntoa(whereto.sin_addr), datalen);                       inet_ntoa(whereto.sin_addr), datalen + phdrlen);
   
         /* When pinging the broadcast address, you can get a lot          /* When pinging the broadcast address, you can get a lot
          * of answers.  Doing something so evil is useful if you           * of answers.  Doing something so evil is useful if you
Line 857  pinger(void)
Line 857  pinger(void)
                                (char *)&sw,sizeof(sw)) < 0)                                 (char *)&sw,sizeof(sw)) < 0)
                         err(1, "Can't turn off special IP header");                          err(1, "Can't turn off special IP header");
                 if (prog_sendto(sloop, (char *) &opack_icmp,                  if (prog_sendto(sloop, (char *) &opack_icmp,
                            phdrlen, MSG_DONTROUTE,                             ICMP_MINLEN, MSG_DONTROUTE,
                            (struct sockaddr *)&loc_addr,                             (struct sockaddr *)&loc_addr,
                            sizeof(struct sockaddr_in)) < 0) {                             sizeof(struct sockaddr_in)) < 0) {
                         /*                          /*
Line 887  pinger(void)
Line 887  pinger(void)
         } else if (pingflags & F_TIMING64)          } else if (pingflags & F_TIMING64)
                 (void) memcpy(&opack_icmp.icmp_data[0], &now, sizeof(now));                  (void) memcpy(&opack_icmp.icmp_data[0], &now, sizeof(now));
   
         cc = datalen + phdrlen;          cc = MAX(datalen, ICMP_MINLEN) + phdrlen;
         opack_icmp.icmp_cksum = 0;          opack_icmp.icmp_cksum = 0;
         opack_icmp.icmp_cksum = in_cksum((u_int16_t *)&opack_icmp, cc);          opack_icmp.icmp_cksum = in_cksum((u_int16_t *)&opack_icmp, cc);
   
Line 953  pr_pack_sub(int cc,
Line 953  pr_pack_sub(int cc,
         if (dupflag)          if (dupflag)
                 (void)printf(" DUP!");                  (void)printf(" DUP!");
         (void)printf(" ttl=%d", ttl);          (void)printf(" ttl=%d", ttl);
         if (pingflags & (F_TIMING|F_TIMING64))          if (pingflags & (F_TIMING|F_TIMING64)) {
                 (void)printf(" time=%.3f ms", triptime*1000.0);                  const unsigned int prec = (pingflags & F_TIMING64) != 0 ? 6 : 3;
   
                   (void)printf(" time=%.*f ms", prec, triptime*1000.0);
           }
   
         /*          /*
          * Send beep to stderr, since that's more likely than stdout           * Send beep to stderr, since that's more likely than stdout
Line 1008  pr_pack(u_char *buf,
Line 1011  pr_pack(u_char *buf,
         icp = (struct icmp *)(buf + hlen);          icp = (struct icmp *)(buf + hlen);
         if (icp->icmp_type == ICMP_ECHOREPLY          if (icp->icmp_type == ICMP_ECHOREPLY
             && icp->icmp_id == ident) {              && icp->icmp_id == ident) {
                 struct timespec tv;  
   
                 if (icp->icmp_seq == htons((u_int16_t)(ntransmitted-1)))                  if (icp->icmp_seq == htons((u_int16_t)(ntransmitted-1)))
                         lastrcvd = 1;                          lastrcvd = 1;
Line 1016  pr_pack(u_char *buf,
Line 1018  pr_pack(u_char *buf,
                 if (first_rx.tv_sec == 0)                  if (first_rx.tv_sec == 0)
                         first_rx = last_rx;                          first_rx = last_rx;
                 nreceived++;                  nreceived++;
                 if (pingflags & F_TIMING) {                  if (pingflags & (F_TIMING|F_TIMING64)) {
                         struct tv32 tv32;                          struct timespec tv;
   
                         (void) memcpy(&tv32, icp->icmp_data, sizeof(tv32));                          if (pingflags & F_TIMING) {
                         tv.tv_sec = (uint32_t)ntohl(tv32.tv32_sec);                                  struct tv32 tv32;
                         tv.tv_nsec = ntohl(tv32.tv32_usec) * 1000;  
                 } else if (pingflags & F_TIMING64)                                  (void)memcpy(&tv32, icp->icmp_data, sizeof(tv32));
                         (void) memcpy(&tv, icp->icmp_data, sizeof(tv));                                  tv.tv_sec = (uint32_t)ntohl(tv32.tv32_sec);
                                   tv.tv_nsec = ntohl(tv32.tv32_usec) * 1000;
                           } else if (pingflags & F_TIMING64)
                                   (void)memcpy(&tv, icp->icmp_data, sizeof(tv));
                           else
                                   memset(&tv, 0, sizeof(tv));     /* XXX: gcc */
   
                 if (pingflags & (F_TIMING|F_TIMING64)) {  
                         triptime = diffsec(&last_rx, &tv);                          triptime = diffsec(&last_rx, &tv);
                         tsum += triptime;                          tsum += triptime;
                         tsumsq += triptime * triptime;                          tsumsq += triptime * triptime;
Line 1096  pr_pack(u_char *buf,
Line 1102  pr_pack(u_char *buf,
                         PR_PACK_SUB();                          PR_PACK_SUB();
   
                 /* check the data */                  /* check the data */
                 if (datalen > phdrlen                  if ((size_t)(tot_len - hlen) >
                       offsetof(struct icmp, icmp_data) + datalen
                     && !(pingflags & F_PING_RANDOM)                      && !(pingflags & F_PING_RANDOM)
                     && memcmp(icp->icmp_data + phdrlen,                      && memcmp(icp->icmp_data + phdrlen,
                             opack_icmp.icmp_data + phdrlen,                              opack_icmp.icmp_data + phdrlen,
Line 1112  pr_pack(u_char *buf,
Line 1119  pr_pack(u_char *buf,
                                      (u_char)opack_icmp.icmp_data[i],                                       (u_char)opack_icmp.icmp_data[i],
                                      (u_char)icp->icmp_data[i]);                                       (u_char)icp->icmp_data[i]);
                         for (i = phdrlen; i < datalen; i++) {                          for (i = phdrlen; i < datalen; i++) {
                                 if ((i % 16) == phdrlen)                                  if ((i % 16) == 0)
                                         (void)printf("\n\t");                                          (void)printf("\n\t");
                                 (void)printf("%2x ",(u_char)icp->icmp_data[i]);                                  (void)printf("%2x ",(u_char)icp->icmp_data[i]);
                         }                          }
Line 1339  summary(int header)
Line 1346  summary(int header)
                 double n = nreceived + nrepeats;                  double n = nreceived + nrepeats;
                 double avg = (tsum / n);                  double avg = (tsum / n);
                 double variance = 0.0;                  double variance = 0.0;
                   const unsigned int prec = (pingflags & F_TIMING64) != 0 ? 6 : 3;
                 if (n>1)                  if (n>1)
                         variance = (tsumsq - n*avg*avg) /(n-1);                          variance = (tsumsq - n*avg*avg) /(n-1);
   
                 printf("round-trip min/avg/max/stddev = "                  printf("round-trip min/avg/max/stddev = "
                         "%.3f/%.3f/%.3f/%.3f ms\n",                          "%.*f/%.*f/%.*f/%.*f ms\n",
                         tmin * 1000.0, avg * 1000.0,                          prec, tmin * 1000.0,
                         tmax * 1000.0, sqrt(variance) * 1000.0);                          prec, avg * 1000.0,
                           prec, tmax * 1000.0,
                           prec, sqrt(variance) * 1000.0);
                 if (pingflags & F_FLOOD) {                  if (pingflags & F_FLOOD) {
                         double r = diffsec(&last_rx, &first_rx);                          double r = diffsec(&last_rx, &first_rx);
                         double t = diffsec(&last_tx, &first_tx);                          double t = diffsec(&last_tx, &first_tx);

Legend:
Removed from v.1.102  
changed lines
  Added in v.1.102.6.4

CVSweb <webmaster@jp.NetBSD.org>