Date: Mon, 28 Jul 2008 12:29:39 GMT From: Rui Paulo <rpaulo@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 146108 for review Message-ID: <200807281229.m6SCTdcR096739@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <err.h> @@ -32,6 +32,10 @@ #include <unistd.h> #include <pcap.h> #include <sys/queue.h> +#include <sys/socketvar.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <netinet/tcp_var.h> #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 <sys/socketvar.h> -#include <netinet/in.h> -#include <netinet/tcp.h> -#include <netinet/tcp_seq.h> -#include <netinet/tcp_var.h> +#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 <assert.h> @@ -33,8 +33,12 @@ #include <pcap.h> #include <sys/queue.h> #include <sys/time.h> +#include <sys/types.h> +#include <sys/socketvar.h> +#include <netinet/ip.h> +#include <netinet/tcp.h> +#include <netinet/tcp_var.h> #include <netinet/tcp_fsm.h> -#include <netinet/tcp.h> #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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807281229.m6SCTdcR096739>