ping(8) 64BTT friendly patch

From: Maxim Konovalov (maxim_at_macomnet.ru)
Date: 09/28/04

  • Next message: Christian S.J. Peron: "Re: fixes for ipfw and pf lock ordering issues"
    Date: Tue, 28 Sep 2004 20:56:54 +0400 (MSD)
    To: hackers@freebsd.org
    
    

    Here is a patch stolen from OpenBSD via NetBSD (rev. 1.75 ping/ping.c)
    which does two things:

    - stores timestamp in network byte order;
    - removes an assumption that sizeof(struct timeval) == 8 (it's not
    true on sparc64).

    Any comments?

    Index: ping.c
    ===================================================================
    RCS file: /home/ncvs/src/sbin/ping/ping.c,v
    retrieving revision 1.105
    diff -u -r1.105 ping.c
    --- ping.c 14 Aug 2004 17:46:10 -0000 1.105
    +++ ping.c 28 Sep 2004 14:51:04 -0000
    @@ -92,7 +92,7 @@
     #include <unistd.h>

     #define INADDR_LEN ((int)sizeof(in_addr_t))
    -#define TIMEVAL_LEN ((int)sizeof(struct timeval))
    +#define TIMEVAL_LEN ((int)sizeof(struct tv32))
     #define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN)
     #define TS_LEN (ICMP_TSLEN - ICMP_MINLEN)
     #define DEFDATALEN 56 /* default data length */
    @@ -110,6 +110,11 @@
     #define CLR(bit) (A(bit) &= (~B(bit)))
     #define TST(bit) (A(bit) & B(bit))

    +struct tv32 {
    + int32_t tv32_sec;
    + int32_t tv32_usec;
    +};
    +
     /* various options */
     int options;
     #define F_FLOOD 0x0001
    @@ -838,6 +843,7 @@
     pinger(void)
     {
             struct timeval now;
    + struct tv32 tv32;
             struct ip *ip;
             struct icmp *icp;
             int cc, i;
    @@ -856,13 +862,15 @@
             if ((options & F_TIME) || timing) {
                     (void)gettimeofday(&now, NULL);

    + tv32.tv32_sec = htonl(now.tv_sec);
    + tv32.tv32_usec = htonl(now.tv_usec);
                     if (options & F_TIME)
                             icp->icmp_otime = htonl((now.tv_sec % (24*60*60))
                                     * 1000 + now.tv_usec / 1000);
                     if (timing)
    - bcopy((void *)&now,
    + bcopy((void *)&tv32,
                                 (void *)&outpack[ICMP_MINLEN + phdr_len],
    - sizeof(struct timeval));
    + sizeof(tv32));
             }

             cc = ICMP_MINLEN + phdr_len + datalen;
    @@ -942,6 +950,7 @@
                     triptime = 0.0;
                     if (timing) {
                             struct timeval tv1;
    + struct tv32 tv32;
     #ifndef icmp_data
                             tp = &icp->icmp_ip;
     #else
    @@ -951,7 +960,9 @@

                             if (cc - ICMP_MINLEN - phdr_len >= sizeof(tv1)) {
                                     /* Copy to avoid alignment problems: */
    - memcpy(&tv1, tp, sizeof(tv1));
    + memcpy(&tv32, tp, sizeof(tv32));
    + tv1.tv_sec = ntohl(tv32.tv32_sec);
    + tv1.tv_usec = ntohl(tv32.tv32_usec);
                                     tvsub(tv, &tv1);
                                      triptime = ((double)tv->tv_sec) * 1000.0 +
                                          ((double)tv->tv_usec) / 1000.0;
    %%%

    -- 
    Maxim Konovalov
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: Christian S.J. Peron: "Re: fixes for ipfw and pf lock ordering issues"