summaryrefslogtreecommitdiffstats
path: root/sbin/ping
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2004-09-30 07:35:56 +0000
committermaxim <maxim@FreeBSD.org>2004-09-30 07:35:56 +0000
commit9fddea1399dbade46d602410b3a41fe5510b2d64 (patch)
treeed2949408e9ff0a4212339cdff6037432f1992eb /sbin/ping
parentfbd7b98a6af12291eb512778ba82211637aee056 (diff)
downloadFreeBSD-src-9fddea1399dbade46d602410b3a41fe5510b2d64.zip
FreeBSD-src-9fddea1399dbade46d602410b3a41fe5510b2d64.tar.gz
o Store timestamp in network byte order.
o Remove an assumption sizeof(struct timeval) == 8 (this is not true on sparc64). Reviewed by: imp, -hackers Obtained from: NetBSD (rev. 1.75) MT5 after: 1 month
Diffstat (limited to 'sbin/ping')
-rw-r--r--sbin/ping/ping.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index d312721..282f9b1 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -92,7 +92,7 @@ __FBSDID("$FreeBSD$");
#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 @@ __FBSDID("$FreeBSD$");
#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 @@ static void
pinger(void)
{
struct timeval now;
+ struct tv32 tv32;
struct ip *ip;
struct icmp *icp;
int cc, i;
@@ -856,13 +862,15 @@ pinger(void)
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 @@ pr_pack(buf, cc, from, tv)
triptime = 0.0;
if (timing) {
struct timeval tv1;
+ struct tv32 tv32;
#ifndef icmp_data
tp = &icp->icmp_ip;
#else
@@ -951,7 +960,9 @@ pr_pack(buf, cc, from, tv)
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;
OpenPOWER on IntegriCloud