From: fenner Date: Wed, 4 Jul 2001 22:03:13 +0000 (+0000) Subject: Add SIGINFO handler from LBL X-Git-Tag: tcpdump-3.7.1~133 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/2cfe2bf4a5bdba199215e4c92129a36271b10a64 Add SIGINFO handler from LBL The rest of the low-level print-*.c handlers need the infodelay wrapping too. --- diff --git a/interface.h b/interface.h index a91b1b26..888dd81e 100644 --- a/interface.h +++ b/interface.h @@ -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))); diff --git a/print-ether.c b/print-ether.c index 30956ed7..f0b82f92 100644 --- a/print-ether.c +++ b/print-ether.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 @@ -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); } /* diff --git a/print-fddi.c b/print-fddi.c index 8911dea1..caa1f11f 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -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); } diff --git a/print-token.c b/print-token.c index 3f1f44ba..dd4e2c9f 100644 --- a/print-token.c +++ b/print-token.c @@ -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); } diff --git a/tcpdump.c b/tcpdump.c index b59a1521..1ec0a0ff 100644 --- 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 @@ -21,10 +21,10 @@ #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) {