]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add SIGINFO handler from LBL
authorfenner <fenner>
Wed, 4 Jul 2001 22:03:13 +0000 (22:03 +0000)
committerfenner <fenner>
Wed, 4 Jul 2001 22:03:13 +0000 (22:03 +0000)
The rest of the low-level print-*.c handlers need the infodelay
 wrapping too.

interface.h
print-ether.c
print-fddi.c
print-token.c
tcpdump.c

index a91b1b2624747d10d18378d158997f8f4f1581c7..888dd81ecab12f1e548adbcd21227bcb71599aec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000
  *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.164 2001-06-24 21:55:00 itojun Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.165 2001-07-04 22:03:13 fenner Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -153,7 +153,9 @@ extern int fn_printn(const u_char *, u_int, const u_char *);
 extern const char *tok2str(const struct tok *, const char *, int);
 extern char *dnaddr_string(u_short);
 
-extern void wrapup(int);
+extern void info(int);
+extern int infodelay;
+extern int infoprint;
 
 extern void error(const char *, ...)
     __attribute__((noreturn, format (printf, 1, 2)));
index 30956ed7df9fcea4f5e407693e0f6d30c9564432..f0b82f92b3a5f80e72d0f678e9d52caa72567095 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
  *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.64 2001-06-21 17:56:03 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.65 2001-07-04 22:03:14 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -82,6 +82,7 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
        u_short ether_type;
        u_short extracted_ethertype;
 
+       ++infodelay;
        ts_print(&h->ts);
 
        if (caplen < ETHER_HDRLEN) {
@@ -137,6 +138,9 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
                default_print(p, caplen);
  out:
        putchar('\n');
+       --infodelay;
+       if (infoprint)
+               info(0);
 }
 
 /*
index 8911dea102e1831af6c5c014123c8037c767552f..caa1f11fb058e559f1cd14cd5350208d0a20fbff 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.50 2000-12-23 20:48:13 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.51 2001-07-04 22:03:14 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -262,6 +262,7 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h,
        struct ether_header ehdr;
        u_short extracted_ethertype;
 
+       ++infodelay;
        ts_print(&h->ts);
 
        if (caplen < FDDI_HDRLEN) {
@@ -328,4 +329,7 @@ fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h,
                default_print(p, caplen);
 out:
        putchar('\n');
+       --infodelay;
+       if (infoprint)
+               info(0);
 }
index 3f1f44ba97760a6d267eeb244ef868bbd207b608..dd4e2c9fc51147ce5b45434358f41970f7657dac 100644 (file)
@@ -25,7 +25,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.11 2000-12-23 20:48:13 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.12 2001-07-04 22:03:14 fenner Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -119,6 +119,7 @@ token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
 
        trp = (struct token_header *)p;
 
+       ++infodelay;
        ts_print(&h->ts);
 
        if (caplen < TOKEN_HDRLEN) {
@@ -207,4 +208,7 @@ token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
                default_print(p, caplen);
 out:
        putchar('\n');
+       --infodelay;
+       if (infoprint)
+               info(0);
 }
index b59a15212d697357aa969fdf8fd5411d7dc3797d..1ec0a0ff7b0278713b87af6f5c59858f43d447eb 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
  *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #ifndef lint
 static const char copyright[] =
-    "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\
+    "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
 The Regents of the University of California.  All rights reserved.\n";
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.165 2001-06-24 20:38:52 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.166 2001-07-04 22:03:13 fenner Exp $ (LBL)";
 #endif
 
 /*
@@ -81,6 +81,8 @@ char *espsecret = NULL;               /* ESP secret key */
 
 int packettype;
 
+int infodelay;
+int infoprint;
 
 char *program_name;
 
@@ -89,6 +91,9 @@ int32_t thiszone;             /* seconds offset from gmt to local time */
 /* Forwards */
 static RETSIGTYPE cleanup(int);
 static void usage(void) __attribute__((noreturn));
+#ifdef SIGINFO
+RETSIGTYPE requestinfo(int);
+#endif
 
 /* Length of saved portion of packet. */
 int snaplen = DEFAULT_SNAPLEN;
@@ -436,6 +441,9 @@ main(int argc, char **argv)
        } else {
                printer = lookup_printer(pcap_datalink(pd));
                pcap_userdata = 0;
+#ifdef SIGINFO
+               (void)setsignal(SIGINFO, requestinfo);
+#endif
        }
        if (RFileName == NULL) {
                (void)fprintf(stderr, "%s: listening on %s\n",
@@ -455,25 +463,36 @@ main(int argc, char **argv)
 static RETSIGTYPE
 cleanup(int signo)
 {
-       struct pcap_stat stat;
 
        /* Can't print the summary if reading from a savefile */
        if (pd != NULL && pcap_file(pd) == NULL) {
                (void)fflush(stdout);
                putc('\n', stderr);
-               if (pcap_stats(pd, &stat) < 0)
-                       (void)fprintf(stderr, "pcap_stats: %s\n",
-                           pcap_geterr(pd));
-               else {
-                       (void)fprintf(stderr, "%d packets received by filter\n",
-                           stat.ps_recv);
-                       (void)fprintf(stderr, "%d packets dropped by kernel\n",
-                           stat.ps_drop);
-               }
+               info(1);
        }
        exit(0);
 }
 
+void
+info(register int verbose)
+{
+       struct pcap_stat stat;
+
+       if (pcap_stats(pd, &stat) < 0) {
+               (void)fprintf(stderr, "pcap_stats: %s\n", pcap_geterr(pd));
+               return;
+       }
+       if (!verbose)
+               fprintf(stderr, "%s: ", program_name);
+       (void)fprintf(stderr, "%d packets received by filter", stat.ps_recv);
+       if (!verbose)
+               fputs(", ", stderr);
+       else
+               putc('\n', stderr);
+       (void)fprintf(stderr, "%d packets dropped by kernel\n", stat.ps_drop);
+       infoprint = 0;
+}
+
 /* Like default_print() but data need not be aligned */
 void
 default_print_unaligned(register const u_char *cp, register u_int length)
@@ -509,6 +528,16 @@ default_print(register const u_char *bp, register u_int length)
        default_print_unaligned(bp, length);
 }
 
+#ifdef SIGINFO
+RETSIGTYPE requestinfo(int signo)
+{
+       if (infodelay)
+               ++infoprint;
+       else
+               info(0);
+}
+#endif
+
 static void
 usage(void)
 {