Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Jun 2008 22:09:52 GMT
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 143090 for review
Message-ID:  <200806072209.m57M9q8n079474@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <err.h>
@@ -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");
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806072209.m57M9q8n079474>