NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/45257: ping(8) prints bogus round-trip times after Year 2038



On Aug 18,  7:46pm, ryo%nerv.org@localhost (Ryo Shimizu) wrote:
-- Subject: Re: bin/45257: ping(8) prints bogus round-trip times after Year 2

| 
| >Fix:
| pointed out from dsl@ about the seconds wrap case,
| and reviewed by tsutsui@.

Why all the complexity? All you should need is to cast to unsigned when
assigning.

christos

Index: ping.c
===================================================================
RCS file: /cvsroot/src/sbin/ping/ping.c,v
retrieving revision 1.93
diff -u -u -r1.93 ping.c
--- ping.c      11 Mar 2011 09:59:56 -0000      1.93
+++ ping.c      18 Aug 2011 11:10:30 -0000
@@ -137,7 +137,7 @@
 #define TST(seq) (A(seq) & B(seq))
 
 struct tv32 {
-       int32_t tv32_sec;
+       uint32_t tv32_sec;
        int32_t tv32_usec;
 };
 
@@ -859,7 +859,7 @@
 
        opack_icmp.icmp_type = ICMP_ECHO;
        opack_icmp.icmp_id = ident;
-       tv32.tv32_sec = htonl(now.tv_sec);
+       tv32.tv32_sec = (uint32_t)htonl(now.tv_sec);
        tv32.tv32_usec = htonl(now.tv_usec);
        if (pingflags & F_TIMING)
                (void) memcpy(&opack_icmp.icmp_data[0], &tv32, sizeof(tv32));
@@ -995,7 +995,7 @@
                        struct tv32 tv32;
 
                        (void) memcpy(&tv32, icp->icmp_data, sizeof(tv32));
-                       tv.tv_sec = ntohl(tv32.tv32_sec);
+                       tv.tv_sec = (uint32_t)ntohl(tv32.tv32_sec);
                        tv.tv_usec = ntohl(tv32.tv32_usec);
                        triptime = diffsec(&last_rx, &tv);
                        tsum += triptime;


Home | Main Index | Thread Index | Old Index