shithub: riscv

Download patch

ref: 46bbeea04060257c6257d14112c6a8d317d7f930
parent: a53ae2782a6e8b1996c1d5dea4190eb11d06d056
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Dec 22 21:00:09 EST 2015

snoopy: fix timestamps for pcap files (thanks BurnZeZ)

the pcap files produced by snoopy had the wrong timestamps because it expected:

/* magic=0xa1b2c3d4 */
ulong ts_sec;	/* seconds*/
ulong ts_usec;	/* microseconds */

but we wrote:

uvlong ts;		/* nanoseconds */

now, we write:

/* magic=0xa1b23c4d */
ulong ts_sec;	/* seconds */
ulong ts_nsec;	/* nanoseconds */

--- a/sys/src/cmd/ip/snoopy/main.c
+++ b/sys/src/cmd/ip/snoopy/main.c
@@ -273,7 +273,7 @@
  */
 #define PCAP_VERSION_MAJOR 2
 #define PCAP_VERSION_MINOR 4
-#define TCPDUMP_MAGIC 0xa1b2c3d4
+#define TCPDUMP_MAGIC 0xa1b23c4d
 
 struct pcap_file_header {
 	ulong		magic;
@@ -286,7 +286,8 @@
 };
 
 struct pcap_pkthdr {
-        uvlong	ts;	/* time stamp */
+	ulong	ts_sec;
+	ulong	ts_nsec;
         ulong	caplen;	/* length of portion present */
         ulong	len;	/* length this packet (off wire) */
 };
@@ -323,7 +324,8 @@
 		len = Mflag;
 	if(pcap){
 		goo = (struct pcap_pkthdr*)(ps-16);
-		goo->ts = pkttime;
+		goo->ts_sec  = (uvlong)pkttime / 1000000000;
+		goo->ts_nsec = (uvlong)pkttime % 1000000000;
 		goo->caplen = len;
 		goo->len = len;
 		write(1, goo, len+16);