From owner-p4-projects@FreeBSD.ORG Mon Jul 28 12:29:40 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1300D106568E; Mon, 28 Jul 2008 12:29:40 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B1BFD106567D for ; Mon, 28 Jul 2008 12:29:39 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 980708FC5D for ; Mon, 28 Jul 2008 12:29:39 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m6SCTdpZ096741 for ; Mon, 28 Jul 2008 12:29:39 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6SCTdcR096739 for perforce@freebsd.org; Mon, 28 Jul 2008 12:29:39 GMT (envelope-from rpaulo@FreeBSD.org) Date: Mon, 28 Jul 2008 12:29:39 GMT Message-Id: <200807281229.m6SCTdcR096739@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rpaulo@FreeBSD.org using -f From: Rui Paulo To: Perforce Change Reviews Cc: Subject: PERFORCE change 146108 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jul 2008 12:29:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=146108 Change 146108 by rpaulo@rpaulo_epsilon on 2008/07/28 12:29:27 Remove includes from tcpad.h Implement timer_stop() and call it from main(). Small style changes, including "look more like tcpdump". Affected files ... .. //depot/projects/soc2008/rpaulo-tcpad/main.c#9 edit .. //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#13 edit .. //depot/projects/soc2008/rpaulo-tcpad/timer.c#6 edit .. //depot/projects/soc2008/rpaulo-tcpad/timer.h#2 edit Differences ... ==== //depot/projects/soc2008/rpaulo-tcpad/main.c#9 (text+ko) ==== @@ -23,7 +23,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2008/rpaulo-tcpad/main.c#8 $ + * $P4: //depot/projects/soc2008/rpaulo-tcpad/main.c#9 $ */ #include @@ -32,6 +32,10 @@ #include #include #include +#include +#include +#include +#include #include "tcpad.h" #include "dumper.h" @@ -44,9 +48,10 @@ static void usage(void) { + fprintf(stderr, "tcpad version " TCPAD_VERSION "\n"); fprintf(stderr, "%s\n", pcap_lib_version()); - fprintf(stderr, "%s: [-r file] [-p] [-i interface] [-s snaplen]\n", - getprogname()); + fprintf(stderr, "Usage: %s [-r file] [-p] [-i interface] " + "[-s snaplen]\n", getprogname()); exit(1); } @@ -54,7 +59,6 @@ main(int argc, char *argv[]) { int promisc; - int snaplen; int ch; char *interface; char *readfile; @@ -111,7 +115,8 @@ if (interface == NULL) errx(1, "interface not specified"); else - p = pcap_open_live(interface, snaplen, promisc, 100, errbuf); + p = pcap_open_live(interface, snaplen, promisc, 100, + errbuf); } if (p == NULL) err(1, "pcap_open_live"); @@ -134,5 +139,7 @@ pcap_freecode(&fp); pcap_close(p); + timer_stop(); + return (0); } ==== //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#13 (text+ko) ==== @@ -23,20 +23,20 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#12 $ + * $P4: //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#13 $ */ #ifndef _TCPAD_H_ #define _TCPAD_H_ -#include -#include -#include -#include -#include +#define TCPAD_VERSION "0.1" +#define TCPAD_MSL 60 /* sec. */ +/* Globals */ pcap_t *p; +int snaplen; +/* Connection structure */ struct tcpc { LIST_ENTRY(tcpc) entries; struct in_addr sv4addr; @@ -51,6 +51,4 @@ LIST_HEAD(tcpchead, tcpc) tcpchead; - -#define TCPAD_MSL 60 /* sec. */ #endif /* _TCPAD_H_ */ ==== //depot/projects/soc2008/rpaulo-tcpad/timer.c#6 (text+ko) ==== @@ -23,7 +23,7 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2008/rpaulo-tcpad/timer.c#5 $ + * $P4: //depot/projects/soc2008/rpaulo-tcpad/timer.c#6 $ */ #include @@ -33,8 +33,12 @@ #include #include #include +#include +#include +#include +#include +#include #include -#include #include "debug.h" #include "tcpad.h" @@ -44,6 +48,8 @@ static void timer_sigalrm(int sig); +struct itimerval itp; + /** * @brief * Timer setup. @@ -52,7 +58,6 @@ timer_setup(void) { static int firstime = 1; - struct itimerval itp; if (firstime) { DPRINTF(DEBUG_TIMER, "setting up signal function\n"); @@ -100,3 +105,22 @@ DPRINTF(DEBUG_TIMER, "connections being tracked: %d\n", nc/2); prevnc = nc; } + +void +timer_stop(void) +{ + struct tcpc *cp, *cp_t; + + /* Disable the timer. */ + itp.it_value.tv_sec = 0; + setitimer(ITIMER_REAL, &itp, NULL); + + LIST_FOREACH_SAFE(cp, &tcpchead, entries, cp_t) { + if (cp->pktshead) + dumper_free(cp); + if (cp->rcp && cp->rcp->pktshead) + cp->rcp->pktshead = NULL; + LIST_REMOVE(cp, entries); + free(cp); + } +} ==== //depot/projects/soc2008/rpaulo-tcpad/timer.h#2 (text+ko) ==== @@ -23,12 +23,13 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/soc2008/rpaulo-tcpad/timer.h#1 $ + * $P4: //depot/projects/soc2008/rpaulo-tcpad/timer.h#2 $ */ #ifndef _TIMER_H_ #define _TIMER_H_ int timer_setup(void); +void timer_stop(void); #endif /* _TIMER_H_ */