From owner-p4-projects@FreeBSD.ORG Sat Jun 7 22:09:53 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 25890106568C; Sat, 7 Jun 2008 22:09:53 +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 DBCDE10656AB for ; Sat, 7 Jun 2008 22:09:52 +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 E12808FC0A for ; Sat, 7 Jun 2008 22:09:52 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m57M9qjS079476 for ; Sat, 7 Jun 2008 22:09:52 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m57M9q8n079474 for perforce@freebsd.org; Sat, 7 Jun 2008 22:09:52 GMT (envelope-from rpaulo@FreeBSD.org) Date: Sat, 7 Jun 2008 22:09:52 GMT Message-Id: <200806072209.m57M9q8n079474@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 143090 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: Sat, 07 Jun 2008 22:09:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=143090 Change 143090 by rpaulo@rpaulo_epsilon on 2008/06/07 22:09:37 Implement -r option (ala tcpdump). Affected files ... .. //depot/projects/soc2008/rpaulo-tcpad/main.c#6 edit Differences ... ==== //depot/projects/soc2008/rpaulo-tcpad/main.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/main.c#5 $ + * $P4: //depot/projects/soc2008/rpaulo-tcpad/main.c#6 $ */ #include @@ -43,7 +43,7 @@ usage(void) { fprintf(stderr, "%s\n", pcap_lib_version()); - fprintf(stderr, "%s: [-pD] [-i interface] [-s snaplen]\n", + fprintf(stderr, "%s: [-r file] [-pD] [-i interface] [-s snaplen]\n", getprogname()); exit(1); } @@ -55,6 +55,7 @@ int snaplen; int ch; char *interface; + char *readfile; char errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program fp; char filter[] = "ip proto \\tcp"; @@ -63,8 +64,11 @@ promisc = 1; snaplen = 100; interface = NULL; - while ((ch = getopt(argc, argv, "pDi:s:l")) != -1) { + readfile = NULL; + while ((ch = getopt(argc, argv, "r:pDi:s:l")) != -1) { switch (ch) { + case 'r': + readfile = optarg; case 'p': promisc = 0; break; @@ -87,10 +91,14 @@ argc -= optind; argv += optind; - if (interface == NULL) - errx(1, "interface not specified"); - - p = pcap_open_live(interface, snaplen, promisc, 100, errbuf); + if (readfile) + p = pcap_open_offline(readfile, errbuf); + else { + if (interface == NULL) + errx(1, "interface not specified"); + else + p = pcap_open_live(interface, snaplen, promisc, 100, errbuf); + } if (p == NULL) err(1, "pcap_open_live");