the output stream for "-w" to be flushed after each packet is dumped.
Add checks for "pcap_dump_flush()", and only enable the "-U" flag if
it's present. Clean up the handling of the "getopt()" argument and the
usage message to get rid of the pile of #ifdefs.
Add documentation for the "-L" and "-y" flags.
Tweak the description of "-r" to properly format "-w" in the text.
Additional people who have contributed patches:
/* Define if you have the inet_pton function. */
#undef HAVE_INET_PTON
+/* Define if you have the pcap_dump_flush function. */
+#undef HAVE_PCAP_DUMP_FLUSH
+
/* Define if you have the pcap_findalldevs function. */
#undef HAVE_PCAP_FINDALLDEVS
#! /bin/sh
-# From configure.in Revision: 1.158
+# From configure.in Revision: 1.159
-for ac_func in pcap_findalldevs
+for ac_func in pcap_findalldevs pcap_dump_flush
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:4102: checking for $ac_func" >&5
-dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.158 2002-12-11 05:00:06 guy Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.159 2002-12-22 00:15:27 guy Exp $ (LBL)
dnl
dnl Copyright (c) 1994, 1995, 1996, 1997
dnl The Regents of the University of California. All rights reserved.
dnl Process this file with autoconf to produce a configure script.
dnl
-AC_REVISION($Revision: 1.158 $)
+AC_REVISION($Revision: 1.159 $)
AC_PREREQ(2.13)
AC_INIT(tcpdump.c)
AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
-AC_CHECK_FUNCS(pcap_findalldevs)
+AC_CHECK_FUNCS(pcap_findalldevs pcap_dump_flush)
AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
AC_TRY_LINK([],
[
-.\" @(#) $Header: /tcpdump/master/tcpdump/Attic/tcpdump.1,v 1.134 2002-12-19 05:44:47 guy Exp $ (LBL)
+.\" @(#) $Header: /tcpdump/master/tcpdump/Attic/tcpdump.1,v 1.135 2002-12-22 00:15:27 guy Exp $ (LBL)
.\"
.\" Copyright (c) 1987, 1988, 1989, 1990, 1991, 1992, 1994, 1995, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
-.TH TCPDUMP 1 "8 August 2002"
+.TH TCPDUMP 1 "21 December 2002"
.SH NAME
tcpdump \- dump traffic on a network
.SH SYNOPSIS
.na
.B tcpdump
[
-.B \-aAdDeflnNOpqRStuvxX
+.B \-aAdDeflnNOpqRStuUvxXy
] [
.B \-c
.I count
.I algo:secret
]
[
+.B \-y
+.I datalinktype
+]
+.ti +8
+[
.I expression
]
.br
``tcpdump\ \ \-l\ \ |\ \ tee dat'' or
``tcpdump\ \ \-l \ \ > dat\ \ &\ \ tail\ \ \-f\ \ dat''.
.TP
+.B \-L
+List the known data link types for the interface and exit.
+.TP
.B \-m
Load SMI MIB module definitions from file \fImodule\fR.
This option
\fItcpdump\fP cannot deduce the version of ESP/AH protocol.
.TP
.B \-r
-Read packets from \fIfile\fR (which was created with the -w option).
+Read packets from \fIfile\fR (which was created with the
+.B \-w
+option).
Standard input is used if \fIfile\fR is ``-''.
.TP
.B \-S
.B \-u
Print undecoded NFS handles.
.TP
+.B \-U
+Make output saved via the
+.B \-w
+option ``packet-buffered''; i.e., as each packet is saved, it will be
+written to the output file, rather than being written only when the
+output buffer fills.
+.IP
+The
+.B \-U
+flag will not be supported if
+.I tcpdump
+was built with an older version of
+.I libpcap
+that lacks the
+.B pcap_dump_flush()
+function.
+.TP
.B \-v
(Slightly more) verbose output.
For example, the time to live,
Print each packet,
.I including
its link level header, in hex and ASCII.
+.TP
+.B \-y
+Set the data link type to use while capturing packets to \fIdatalinktype\fP.
.IP "\fI expression\fP"
.RS
selects which packets will be dumped.
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.193 2002-12-19 09:39:17 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.194 2002-12-22 00:15:28 guy Exp $ (LBL)";
#endif
/*
int sflag = 0; /* use the libsmi to translate OIDs */
int Sflag; /* print raw TCP sequence numbers */
int tflag = 1; /* print packet arrival time */
+int Uflag = 0; /* "unbuffered" output of dump files */
int uflag = 0; /* Print undecoded NFS handles */
int vflag; /* verbose */
int xflag; /* print packet in hex */
exit(0);
}
+/*
+ * Set up flags that might or might not be supported depending on the
+ * version of libpcap we're using.
+ *
+ * Win32 builds are assumed to be done with the latest version of WinPcap.
+ */
+#ifdef WIN32
+#define B_FLAG "B:"
+#define B_FLAG_USAGE " [ -B size ]"
+#define D_FLAG "D"
+#define U_FLAG "U"
+#else /* WIN32 */
+
+#define B_FLAG
+#define B_FLAG_USAGE
+
+#ifdef HAVE_PCAP_FINDALLDEVS
+#define D_FLAG "D"
+#else
+#define D_FLAG
+#endif
+
+#ifdef HAVE_PCAP_DUMP_FLUSH
+#define U_FLAG "U"
+#else
+#define U_FLAG
+#endif
+
+#endif /* WIN32 */
+
int
main(int argc, char **argv)
{
opterr = 0;
while (
-#ifdef WIN32
- (op = getopt(argc, argv, "aAB:c:C:dDeE:fF:i:lLm:nNOpqr:Rs:StT:uvw:xXy:Y")) != -1)
-#else /* WIN32 */
-#ifdef HAVE_PCAP_FINDALLDEVS
- (op = getopt(argc, argv, "aAc:C:dDeE:fF:i:lLm:nNOpqr:Rs:StT:uvw:xXy:Y")) != -1)
-#else /* HAVE_PCAP_FINDALLDEVS */
- (op = getopt(argc, argv, "aAc:C:deE:fF:i:lLm:nNOpqr:Rs:StT:uvw:xXy:Y")) != -1)
-#endif /* HAVE_PCAP_FINDALLDEVS */
-#endif /* WIN32 */
+ (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG "eE:fF:i:lLm:nNOpqr:Rs:StT:u" U_FLAG "vw:xXy:Y")) != -1)
switch (op) {
case 'a':
++uflag;
break;
+#ifdef HAVE_PCAP_DUMP_FLUSH
+ case 'U':
+ ++Uflag;
+ break;
+#endif
+
case 'v':
++vflag;
break;
}
pcap_dump((u_char *)dump_info->p, h, sp);
+#ifdef HAVE_PCAP_FINDALLDEVS
+ if (Uflag)
+ pcap_dump_flush(dump_info->p);
+#endif
--infodelay;
if (infoprint)
++infodelay;
pcap_dump(user, h, sp);
+#ifdef HAVE_PCAP_FINDALLDEVS
+ if (Uflag)
+ pcap_dump_flush((pcap_dumper_t *)user);
+#endif
--infodelay;
if (infoprint)
(void)fprintf(stderr, "libpcap version %s\n", pcap_version);
#endif /* WIN32 */
(void)fprintf(stderr,
-#ifdef WIN32
-"Usage: %s [-aAdDeflLnNOpqRStuvxX] [-B size] [-c count] [ -C file_size ]\n", program_name);
-#else /* WIN32 */
-#ifdef HAVE_PCAP_FINDALLDEVS
-"Usage: %s [-aAdDeflLnNOpqRStuvxX] [-c count] [ -C file_size ]\n", program_name);
-#else /* HAVE_PCAP_FINDALLDEVS */
-"Usage: %s [-aAdeflLnNOpqRStuvxX] [-c count] [ -C file_size ]\n", program_name);
-#endif /* HAVE_PCAP_FINDALLDEVS */
-#endif /* WIN32 */
+"Usage: %s [-aAd" D_FLAG "eflLnNOpqRStu" U_FLAG "vxXy]" B_FLAG_USAGE " [-c count] [ -C file_size ]\n", program_name);
(void)fprintf(stderr,
"\t\t[ -E algo:secret ] [ -F file ] [ -i interface ] [ -r file ]\n");
(void)fprintf(stderr,