Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/shmif_dumpbus Apropos, pcap doesn't export the on-di...



details:   https://anonhg.NetBSD.org/src/rev/1fb400a26946
branches:  trunk
changeset: 763198:1fb400a26946
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sat Mar 12 18:27:42 2011 +0000

description:
Apropos, pcap doesn't export the on-disk pcap packet header but
only the in-memory one.  Since the in-memory one uses struct timeval
and the on-disk one uses 32bit time_t, things didn't work so well
on -current.  Generate a suitable local packetheader to fix things.
(don't think it's worth writing via libpcap for something as simple
as this)

noticed both by bouyer and the shmif_dumpbus test

diffstat:

 usr.bin/shmif_dumpbus/shmif_dumpbus.c |  21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diffs (49 lines):

diff -r f4deff273d03 -r 1fb400a26946 usr.bin/shmif_dumpbus/shmif_dumpbus.c
--- a/usr.bin/shmif_dumpbus/shmif_dumpbus.c     Sat Mar 12 16:52:05 2011 +0000
+++ b/usr.bin/shmif_dumpbus/shmif_dumpbus.c     Sat Mar 12 18:27:42 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shmif_dumpbus.c,v 1.3 2011/03/10 10:11:25 pooka Exp $  */
+/*     $NetBSD: shmif_dumpbus.c,v 1.4 2011/03/12 18:27:42 pooka Exp $  */
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -55,6 +55,19 @@
        exit(1);
 }
 
+/*
+ * Apparently pcap uses a non-exported structure as the on-disk
+ * packet header.  Since that format isn't very likely to change
+ * soon, just define a local version
+ */
+struct ondisk_pcaphdr {
+       uint32_t ts_sec;
+       uint32_t ts_usec;
+       uint32_t caplen;
+       uint32_t len;
+
+};
+
 #define BUFSIZE 64*1024
 int
 main(int argc, char *argv[])
@@ -153,7 +166,7 @@
 
        i = 0;
        while (curbus <= buslast || bonus) {
-               struct pcap_pkthdr packhdr;
+               struct ondisk_pcaphdr packhdr;
                struct shmif_pkthdr sp;
                uint32_t oldoff;
                bool wrap;
@@ -187,8 +200,8 @@
 
                memset(&packhdr, 0, sizeof(packhdr));
                packhdr.caplen = packhdr.len = sp.sp_len;
-               packhdr.ts.tv_sec = sp.sp_sec;
-               packhdr.ts.tv_usec = sp.sp_usec;
+               packhdr.ts_sec = sp.sp_sec;
+               packhdr.ts_usec = sp.sp_usec;
                assert(sp.sp_len <= BUFSIZE);
 
                if (write(pfd, &packhdr, sizeof(packhdr)) != sizeof(packhdr))



Home | Main Index | Thread Index | Old Index