fa.openbsd.tech
[Top] [All Lists]

let the user specify the read timeout for tcpdump(1)

Subject: let the user specify the read timeout for tcpdump1
From: Enache Adrian
Date: Sat, 10 Nov 2007 04:26:28 UTC
Newsgroups: fa.openbsd.tech

The default of 1 second used for pcap_live() is sometimes too much,
especially when trying to do some 'live' debugging.

Adi

Index: privsep.c
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/privsep.c,v
retrieving revision 1.25
diff -u -r1.25 privsep.c
--- privsep.c   22 Apr 2006 19:26:05 -0000      1.25
+++ privsep.c   7 Nov 2007 19:27:44 -0000
@@ -200,7 +200,7 @@
        /* parse the arguments for required options */
        opterr = 0;
        while ((i = getopt(argc, argv,
-           "ac:deE:fF:i:lLnNOopqr:s:StT:vw:xXy:Y")) != -1) {
+           "ac:deE:fF:i:lLnNOopqr:s:StT:vw:xXy:Yz:")) != -1) {
                switch (i) {
                case 'n':
                        nflag++;
Index: tcpdump.8
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/tcpdump.8,v
retrieving revision 1.65
diff -u -r1.65 tcpdump.8
--- tcpdump.8   28 Aug 2007 12:52:06 -0000      1.65
+++ tcpdump.8   7 Nov 2007 19:27:46 -0000
@@ -274,6 +274,8 @@
 .Cm IEEE802_11_RADIO .
 The choices applicable to a particular device can be listed using
 .Fl L .
+.It Fl z Ar timeout
+Set the read timeout in milliseconds. The default is 1000.
 .El
 .Pp
 .Ar expression
Index: tcpdump.c
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdump/tcpdump.c,v
retrieving revision 1.59
diff -u -r1.59 tcpdump.c
--- tcpdump.c   7 Oct 2007 16:41:05 -0000       1.59
+++ tcpdump.c   7 Nov 2007 19:27:46 -0000
@@ -214,7 +214,7 @@
 int
 main(int argc, char **argv)
 {
-       int cnt = -1, op, i;
+       int cnt = -1, to_ms = 1000, op, i;
        bpf_u_int32 localnet, netmask;
        char *cp, *infile = NULL, *RFileName = NULL;
        char ebuf[PCAP_ERRBUF_SIZE], *WFileName = NULL;
@@ -237,7 +237,7 @@
 
        opterr = 0;
        while ((op = getopt(argc, argv,
-           "ac:deE:fF:i:IlLnNOopqr:s:StT:vw:xXy:Y")) != -1)
+           "ac:deE:fF:i:IlLnNOopqr:s:StT:vw:xXy:Yz:")) != -1)
                switch (op) {
 
                case 'a':
@@ -385,6 +385,12 @@
                                error("bad esp specification `%s'", optarg);
                        break;
 
+               case 'z':
+                       to_ms = atoi(optarg);
+                       if(to_ms <= 0)
+                               error("invalid read timeout `%s'", optarg);
+                       break;
+
                default:
                        usage();
                        /* NOTREACHED */
@@ -422,7 +428,7 @@
                        if (device == NULL)
                                error("%s", ebuf);
                }
-               pd = priv_pcap_live(device, snaplen, !pflag, 1000, ebuf, dlt);
+               pd = priv_pcap_live(device, snaplen, !pflag, to_ms, ebuf, dlt);
                if (pd == NULL)
                        error("%s", ebuf);


<Prev in Thread] Current Thread [Next in Thread>