PERFORCE change 143090 for review

Rui Paulo rpaulo at FreeBSD.org
Sat Jun 7 22:09:53 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143090

Change 143090 by rpaulo at 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");
 


More information about the p4-projects mailing list