From owner-freebsd-hackers@FreeBSD.ORG Tue Sep 28 16:56:58 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D42D416A4CE for ; Tue, 28 Sep 2004 16:56:58 +0000 (GMT) Received: from mp2.macomnet.net (mp2.macomnet.net [195.128.64.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id A4BF643D5C for ; Tue, 28 Sep 2004 16:56:55 +0000 (GMT) (envelope-from maxim@macomnet.ru) Received-SPF: pass (mp2.macomnet.net: domain of maxim@macomnet.ru designates 127.0.0.1 as permitted sender) receiver=mp2.macomnet.net; client_ip=127.0.0.1; envelope-from=maxim@macomnet.ru; Received: from localhost (localhost [127.0.0.1]) by mp2.macomnet.net (8.12.11/8.12.11) with ESMTP id i8SGuswm025901 for ; Tue, 28 Sep 2004 20:56:54 +0400 (MSD) (envelope-from maxim@macomnet.ru) Date: Tue, 28 Sep 2004 20:56:54 +0400 (MSD) From: Maxim Konovalov To: hackers@freebsd.org Message-ID: <20040928205116.T25866@mp2.macomnet.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: ping(8) 64BTT friendly patch X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2004 16:56:59 -0000 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 #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