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 If creating a pcap dump to stdout, pri...



details:   https://anonhg.NetBSD.org/src/rev/e5e0c874cddb
branches:  trunk
changeset: 325361:e5e0c874cddb
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Dec 20 09:32:13 2013 +0000

description:
If creating a pcap dump to stdout, print metainfo to stderr.

diffstat:

 usr.bin/shmif_dumpbus/shmif_dumpbus.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (58 lines):

diff -r e376a9837129 -r e5e0c874cddb usr.bin/shmif_dumpbus/shmif_dumpbus.c
--- a/usr.bin/shmif_dumpbus/shmif_dumpbus.c     Fri Dec 20 09:06:35 2013 +0000
+++ b/usr.bin/shmif_dumpbus/shmif_dumpbus.c     Fri Dec 20 09:32:13 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shmif_dumpbus.c,v 1.8 2011/09/16 15:39:29 joerg Exp $  */
+/*     $NetBSD: shmif_dumpbus.c,v 1.9 2013/12/20 09:32:13 pooka Exp $  */
 
 /*-
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -71,8 +71,9 @@
        int fd, i, ch;
        int bonus;
        char *buf;
-       bool hflag = false, doswap = false, isstdout;
+       bool hflag = false, doswap = false;
        pcap_dumper_t *pdump;
+       FILE *dumploc = stdout;
 
        setprogname(argv[0]);
        while ((ch = getopt(argc, argv, "hp:")) != -1) {
@@ -118,7 +119,11 @@
        if (SWAPME(bmem->shm_version) != SHMIF_VERSION)
                errx(1, "bus vesrsion %d, program %d",
                    SWAPME(bmem->shm_version), SHMIF_VERSION);
-       printf("bus version %d, lock: %d, generation: %" PRIu64
+
+       if (pcapfile && strcmp(pcapfile, "-") == 0)
+               dumploc = stderr;
+
+       fprintf(dumploc, "bus version %d, lock: %d, generation: %" PRIu64
            ", firstoff: 0x%04x, lastoff: 0x%04x\n",
            SWAPME(bmem->shm_version), SWAPME(bmem->shm_lock),
            SWAPME64(bmem->shm_gen),
@@ -128,14 +133,12 @@
                exit(0);
 
        if (pcapfile) {
-               isstdout = strcmp(pcapfile, "-") == 0;
                pcap_t *pcap = pcap_open_dead(DLT_EN10MB, 1518);
                pdump = pcap_dump_open(pcap, pcapfile);
                if (pdump == NULL)
                        err(1, "cannot open pcap dump file");
        } else {
                /* XXXgcc */
-               isstdout = false;
                pdump = NULL;
        }
 
@@ -171,8 +174,7 @@
                        continue;
                }
 
-               if (!(pcapfile && isstdout))
-                       printf("packet %d, offset 0x%04x, length 0x%04x, "
+               fprintf(dumploc, "packet %d, offset 0x%04x, length 0x%04x, "
                            "ts %d/%06d\n", i++, curbus,
                            curlen, SWAPME(sp.sp_sec), SWAPME(sp.sp_usec));
 



Home | Main Index | Thread Index | Old Index