2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Support for splitting captures into multiple files with a maximum
25 * Seth Webster <swebster@sst.ll.mit.edu>
29 static const char copyright
[] _U_
=
30 "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
31 The Regents of the University of California. All rights reserved.\n";
35 * tcpdump - dump traffic on a network
37 * First written in 1987 by Van Jacobson, Lawrence Berkeley Laboratory.
38 * Mercilessly hacked and occasionally improved since then via the
39 * combined efforts of Van, Steve McCanne and Craig Leres of LBL.
47 * Mac OS X may ship pcap.h from libpcap 0.6 with a libpcap based on
48 * 0.8. That means it has pcap_findalldevs() but the header doesn't
49 * define pcap_if_t, meaning that we can't actually *use* pcap_findalldevs().
51 #ifdef HAVE_PCAP_FINDALLDEVS
52 #ifndef HAVE_PCAP_IF_T
53 #undef HAVE_PCAP_FINDALLDEVS
57 #include <netdissect-stdinc.h>
66 #include <openssl/crypto.h>
69 #ifdef HAVE_GETOPT_LONG
72 #include "getopt_long.h"
74 /* Capsicum-specific code requires macros from <net/bpf.h>, which will fail
75 * to compile if <pcap.h> has already been included; including the headers
76 * in the opposite order works fine.
79 #include <sys/capability.h>
80 #include <sys/ioccom.h>
83 #endif /* HAVE_CAPSICUM */
93 #include <sys/resource.h>
98 /* capabilities convenience library */
99 /* If a code depends on HAVE_LIBCAP_NG, it depends also on HAVE_CAP_NG_H.
100 * If HAVE_CAP_NG_H is not defined, undefine HAVE_LIBCAP_NG.
101 * Thus, the later tests are done only on HAVE_LIBCAP_NG.
103 #ifdef HAVE_LIBCAP_NG
107 #undef HAVE_LIBCAP_NG
108 #endif /* HAVE_CAP_NG_H */
109 #endif /* HAVE_LIBCAP_NG */
111 #include "netdissect.h"
112 #include "interface.h"
113 #include "addrtoname.h"
115 #include "setsignal.h"
116 #include "gmt2local.h"
117 #include "pcap-missing.h"
118 #include "ascii_strcasecmp.h"
123 #define PATH_MAX 1024
127 #define SIGNAL_REQ_INFO SIGINFO
129 #define SIGNAL_REQ_INFO SIGUSR1
132 static int Bflag
; /* buffer size */
133 static int Cflag
; /* rotate dump files after this many bytes */
134 static int Cflag_count
; /* Keep track of which file number we're writing */
135 static int Dflag
; /* list available devices and exit */
137 * This is exported because, in some versions of libpcap, if libpcap
138 * is built with optimizer debugging code (which is *NOT* the default
139 * configuration!), the library *imports*(!) a variable named dflag,
140 * under the expectation that tcpdump is exporting it, to govern
141 * how much debugging information to print when optimizing
142 * the generated BPF code.
144 * This is a horrible hack; newer versions of libpcap don't import
145 * dflag but, instead, *if* built with optimizer debugging code,
146 * *export* a routine to set that flag.
148 int dflag
; /* print filter code */
149 static int Gflag
; /* rotate dump files after this many seconds */
150 static int Gflag_count
; /* number of files created with Gflag rotation */
151 static time_t Gflag_time
; /* The last time_t the dump file was rotated. */
152 static int Lflag
; /* list available data link types and exit */
153 static int Iflag
; /* rfmon (monitor) mode */
154 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
155 static int Jflag
; /* list available time stamp types */
157 static int jflag
= -1; /* packet time stamp source */
158 static int pflag
; /* don't go promiscuous */
159 #ifdef HAVE_PCAP_SETDIRECTION
160 int Qflag
= -1; /* restrict captured packet by send/receive direction */
162 static int Uflag
; /* "unbuffered" output of dump files */
163 static int Wflag
; /* recycle output files after this number of files */
164 static int WflagChars
;
165 static char *zflag
= NULL
; /* compress each savefile using a specified command (like gzip or bzip2) */
166 static int immediate_mode
;
168 static int infodelay
;
169 static int infoprint
;
174 static void error(const char *, ...)
175 __attribute__((noreturn
))
176 #ifdef __ATTRIBUTE___FORMAT_OK
177 __attribute__((format (printf
, 1, 2)))
178 #endif /* __ATTRIBUTE___FORMAT_OK */
180 static void warning(const char *, ...)
181 #ifdef __ATTRIBUTE___FORMAT_OK
182 __attribute__((format (printf
, 1, 2)))
183 #endif /* __ATTRIBUTE___FORMAT_OK */
185 static void exit_tcpdump(int) __attribute__((noreturn
));
186 static RETSIGTYPE
cleanup(int);
187 static RETSIGTYPE
child_cleanup(int);
188 static void print_version(void);
189 static void print_usage(void);
190 static void show_tstamp_types_and_exit(const char *device
) __attribute__((noreturn
));
191 static void show_dlts_and_exit(const char *device
) __attribute__((noreturn
));
193 static void print_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
194 static void dump_packet_and_trunc(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
195 static void dump_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
196 static void droproot(const char *, const char *);
198 #ifdef SIGNAL_REQ_INFO
199 RETSIGTYPE
requestinfo(int);
202 #if defined(USE_WIN32_MM_TIMER)
203 #include <MMsystem.h>
204 static UINT timer_id
;
205 static void CALLBACK
verbose_stats_dump(UINT
, UINT
, DWORD_PTR
, DWORD_PTR
, DWORD_PTR
);
206 #elif defined(HAVE_ALARM)
207 static void verbose_stats_dump(int sig
);
210 static void info(int);
211 static u_int packets_captured
;
213 #ifdef HAVE_PCAP_FINDALLDEVS
214 static const struct tok status_flags
[] = {
216 { PCAP_IF_UP
, "Up" },
218 #ifdef PCAP_IF_RUNNING
219 { PCAP_IF_RUNNING
, "Running" },
221 { PCAP_IF_LOOPBACK
, "Loopback" },
228 static int supports_monitor_mode
;
236 char *CurrentFileName
;
244 #if defined(HAVE_PCAP_SET_PARSER_DEBUG)
246 * We have pcap_set_parser_debug() in libpcap; declare it (it's not declared
247 * by any libpcap header, because it's a special hack, only available if
248 * libpcap was configured to include it, and only intended for use by
249 * libpcap developers trying to debug the parser for filter expressions).
252 __declspec(dllimport
)
256 void pcap_set_parser_debug(int);
257 #elif defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
259 * We don't have pcap_set_parser_debug() in libpcap, but we do have
260 * pcap_debug or yydebug. Make a local version of pcap_set_parser_debug()
261 * to set the flag, and define HAVE_PCAP_SET_PARSER_DEBUG.
264 pcap_set_parser_debug(int value
)
266 #ifdef HAVE_PCAP_DEBUG
267 extern int pcap_debug
;
270 #else /* HAVE_PCAP_DEBUG */
274 #endif /* HAVE_PCAP_DEBUG */
277 #define HAVE_PCAP_SET_PARSER_DEBUG
280 #if defined(HAVE_PCAP_SET_OPTIMIZER_DEBUG)
282 * We have pcap_set_optimizer_debug() in libpcap; declare it (it's not declared
283 * by any libpcap header, because it's a special hack, only available if
284 * libpcap was configured to include it, and only intended for use by
285 * libpcap developers trying to debug the optimizer for filter expressions).
288 __declspec(dllimport
)
292 void pcap_set_optimizer_debug(int);
297 error(const char *fmt
, ...)
301 (void)fprintf(stderr
, "%s: ", program_name
);
303 (void)vfprintf(stderr
, fmt
, ap
);
308 (void)fputc('\n', stderr
);
316 warning(const char *fmt
, ...)
320 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
322 (void)vfprintf(stderr
, fmt
, ap
);
327 (void)fputc('\n', stderr
);
332 exit_tcpdump(int status
)
338 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
340 show_tstamp_types_and_exit(const char *device
)
343 int *tstamp_types
= 0;
344 const char *tstamp_type_name
;
347 n_tstamp_types
= pcap_list_tstamp_types(pd
, &tstamp_types
);
348 if (n_tstamp_types
< 0)
349 error("%s", pcap_geterr(pd
));
351 if (n_tstamp_types
== 0) {
352 fprintf(stderr
, "Time stamp type cannot be set for %s\n",
356 fprintf(stderr
, "Time stamp types for %s (use option -j to set):\n",
358 for (i
= 0; i
< n_tstamp_types
; i
++) {
359 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
360 if (tstamp_type_name
!= NULL
) {
361 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
362 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
364 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
367 pcap_free_tstamp_types(tstamp_types
);
373 show_dlts_and_exit(const char *device
)
377 const char *dlt_name
;
379 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
381 error("%s", pcap_geterr(pd
));
382 else if (n_dlts
== 0 || !dlts
)
383 error("No data link types.");
386 * If the interface is known to support monitor mode, indicate
387 * whether these are the data link types available when not in
388 * monitor mode, if -I wasn't specified, or when in monitor mode,
389 * when -I was specified (the link-layer types available in
390 * monitor mode might be different from the ones available when
391 * not in monitor mode).
393 if (supports_monitor_mode
)
394 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
396 Iflag
? "when in monitor mode" : "when not in monitor mode");
398 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
401 for (i
= 0; i
< n_dlts
; i
++) {
402 dlt_name
= pcap_datalink_val_to_name(dlts
[i
]);
403 if (dlt_name
!= NULL
) {
404 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
405 pcap_datalink_val_to_description(dlts
[i
]));
408 * OK, does tcpdump handle that type?
410 if (!has_printer(dlts
[i
]))
411 (void) fprintf(stderr
, " (printing not supported)");
412 fprintf(stderr
, "\n");
414 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
418 #ifdef HAVE_PCAP_FREE_DATALINKS
419 pcap_free_datalinks(dlts
);
424 #ifdef HAVE_PCAP_FINDALLDEVS
426 show_devices_and_exit (void)
428 pcap_if_t
*dev
, *devlist
;
429 char ebuf
[PCAP_ERRBUF_SIZE
];
432 if (pcap_findalldevs(&devlist
, ebuf
) < 0)
434 for (i
= 0, dev
= devlist
; dev
!= NULL
; i
++, dev
= dev
->next
) {
435 printf("%d.%s", i
+1, dev
->name
);
436 if (dev
->description
!= NULL
)
437 printf(" (%s)", dev
->description
);
439 printf(" [%s]", bittok2str(status_flags
, "none", dev
->flags
));
442 pcap_freealldevs(devlist
);
445 #endif /* HAVE_PCAP_FINDALLDEVS */
450 * Note that there we use all letters for short options except for g, k,
451 * o, and P, and those are used by other versions of tcpdump, and we should
452 * only use them for the same purposes that the other versions of tcpdump
455 * OS X tcpdump uses -g to force non--v output for IP to be on one
456 * line, making it more "g"repable;
458 * OS X tcpdump uses -k tospecify that packet comments in pcap-ng files
461 * OpenBSD tcpdump uses -o to indicate that OS fingerprinting should be done
462 * for hosts sending TCP SYN packets;
464 * OS X tcpdump uses -P to indicate that -w should write pcap-ng rather
467 * OS X tcpdump also uses -Q to specify expressions that match packet
468 * metadata, including but not limited to the packet direction.
469 * The expression syntax is different from a simple "in|out|inout",
470 * and those expressions aren't accepted by OS X tcpdump, but the
471 * equivalents would be "in" = "dir=in", "out" = "dir=out", and
472 * "inout" = "dir=in or dir=out", and the parser could conceivably
473 * special-case "in", "out", and "inout" as expressions for backwards
474 * compatibility, so all is not (yet) lost.
478 * Set up flags that might or might not be supported depending on the
479 * version of libpcap we're using.
481 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
483 #define B_FLAG_USAGE " [ -B size ]"
484 #else /* defined(HAVE_PCAP_CREATE) || defined(_WIN32) */
487 #endif /* defined(HAVE_PCAP_CREATE) || defined(_WIN32) */
489 #ifdef HAVE_PCAP_CREATE
491 #else /* HAVE_PCAP_CREATE */
493 #endif /* HAVE_PCAP_CREATE */
495 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
497 #define j_FLAG_USAGE " [ -j tstamptype ]"
499 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
503 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
505 #ifdef HAVE_PCAP_FINDALLDEVS
511 #ifdef HAVE_PCAP_DUMP_FLUSH
517 #ifdef HAVE_PCAP_SETDIRECTION
523 #define SHORTOPTS "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNOpq" Q_FLAG "r:s:StT:u" U_FLAG "vV:w:W:xXy:Yz:Z:#"
528 * We do not currently have long options corresponding to all short
529 * options; we should probably pick appropriate option names for them.
531 * However, the short options where the number of times the option is
532 * specified matters, such as -v and -d and -t, should probably not
533 * just map to a long option, as saying
535 * tcpdump --verbose --verbose
537 * doesn't make sense; it should be --verbosity={N} or something such
540 * For long options with no corresponding short options, we define values
541 * outside the range of ASCII graphic characters, make that the last
542 * component of the entry for the long option, and have a case for that
543 * option in the switch statement.
545 #define OPTION_VERSION 128
546 #define OPTION_TSTAMP_PRECISION 129
547 #define OPTION_IMMEDIATE_MODE 130
549 static const struct option longopts
[] = {
550 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
551 { "buffer-size", required_argument
, NULL
, 'B' },
553 { "list-interfaces", no_argument
, NULL
, 'D' },
554 { "help", no_argument
, NULL
, 'h' },
555 { "interface", required_argument
, NULL
, 'i' },
556 #ifdef HAVE_PCAP_CREATE
557 { "monitor-mode", no_argument
, NULL
, 'I' },
559 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
560 { "time-stamp-type", required_argument
, NULL
, 'j' },
561 { "list-time-stamp-types", no_argument
, NULL
, 'J' },
563 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
564 { "time-stamp-precision", required_argument
, NULL
, OPTION_TSTAMP_PRECISION
},
566 { "dont-verify-checksums", no_argument
, NULL
, 'K' },
567 { "list-data-link-types", no_argument
, NULL
, 'L' },
568 { "no-optimize", no_argument
, NULL
, 'O' },
569 { "no-promiscuous-mode", no_argument
, NULL
, 'p' },
570 #ifdef HAVE_PCAP_SETDIRECTION
571 { "direction", required_argument
, NULL
, 'Q' },
573 { "snapshot-length", required_argument
, NULL
, 's' },
574 { "absolute-tcp-sequence-numbers", no_argument
, NULL
, 'S' },
575 #ifdef HAVE_PCAP_DUMP_FLUSH
576 { "packet-buffered", no_argument
, NULL
, 'U' },
578 { "linktype", required_argument
, NULL
, 'y' },
579 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
580 { "immediate-mode", no_argument
, NULL
, OPTION_IMMEDIATE_MODE
},
582 #ifdef HAVE_PCAP_SET_PARSER_DEBUG
583 { "debug-filter-parser", no_argument
, NULL
, 'Y' },
585 { "relinquish-privileges", required_argument
, NULL
, 'Z' },
586 { "number", no_argument
, NULL
, '#' },
587 { "version", no_argument
, NULL
, OPTION_VERSION
},
592 /* Drop root privileges and chroot if necessary */
594 droproot(const char *username
, const char *chroot_dir
)
596 struct passwd
*pw
= NULL
;
598 if (chroot_dir
&& !username
) {
599 fprintf(stderr
, "%s: Chroot without dropping root is insecure\n",
604 pw
= getpwnam(username
);
607 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
608 fprintf(stderr
, "%s: Couldn't chroot/chdir to '%.64s': %s\n",
609 program_name
, chroot_dir
, pcap_strerror(errno
));
613 #ifdef HAVE_LIBCAP_NG
615 int ret
= capng_change_id(pw
->pw_uid
, pw
->pw_gid
, CAPNG_NO_FLAG
);
617 fprintf(stderr
, "error : ret %d\n", ret
);
619 fprintf(stderr
, "dropped privs to %s\n", username
);
623 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
624 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
625 fprintf(stderr
, "%s: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
626 program_name
, username
,
627 (unsigned long)pw
->pw_uid
,
628 (unsigned long)pw
->pw_gid
,
629 pcap_strerror(errno
));
633 fprintf(stderr
, "dropped privs to %s\n", username
);
635 #endif /* HAVE_LIBCAP_NG */
638 fprintf(stderr
, "%s: Couldn't find user '%.32s'\n",
639 program_name
, username
);
642 #ifdef HAVE_LIBCAP_NG
643 /* We don't need CAP_SETUID and CAP_SETGID any more. */
646 CAPNG_EFFECTIVE
| CAPNG_PERMITTED
,
650 capng_apply(CAPNG_SELECT_BOTH
);
651 #endif /* HAVE_LIBCAP_NG */
672 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
674 char *filename
= malloc(PATH_MAX
+ 1);
675 if (filename
== NULL
)
676 error("Makefilename: malloc");
678 /* Process with strftime if Gflag is set. */
682 /* Convert Gflag_time to a usable format */
683 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
684 error("MakeTimedFilename: localtime");
687 /* There's no good way to detect an error in strftime since a return
688 * value of 0 isn't necessarily failure.
690 strftime(filename
, PATH_MAX
, orig_name
, local_tm
);
692 strncpy(filename
, orig_name
, PATH_MAX
);
695 if (cnt
== 0 && max_chars
== 0)
696 strncpy(buffer
, filename
, PATH_MAX
+ 1);
698 if (snprintf(buffer
, PATH_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > PATH_MAX
)
699 /* Report an error if the filename is too large */
700 error("too many output files or filename is too long (> %d)", PATH_MAX
);
705 get_next_file(FILE *VFile
, char *ptr
)
709 ret
= fgets(ptr
, PATH_MAX
, VFile
);
713 if (ptr
[strlen(ptr
) - 1] == '\n')
714 ptr
[strlen(ptr
) - 1] = '\0';
719 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
721 tstamp_precision_from_string(const char *precision
)
723 if (strncmp(precision
, "nano", strlen("nano")) == 0)
724 return PCAP_TSTAMP_PRECISION_NANO
;
726 if (strncmp(precision
, "micro", strlen("micro")) == 0)
727 return PCAP_TSTAMP_PRECISION_MICRO
;
733 tstamp_precision_to_string(int precision
)
737 case PCAP_TSTAMP_PRECISION_MICRO
:
740 case PCAP_TSTAMP_PRECISION_NANO
:
751 * Ensure that, on a dump file's descriptor, we have all the rights
752 * necessary to make the standard I/O library work with an fdopen()ed
753 * FILE * from that descriptor.
755 * A long time ago, in a galaxy far far away, AT&T decided that, instead
756 * of providing separate APIs for getting and setting the FD_ flags on a
757 * descriptor, getting and setting the O_ flags on a descriptor, and
758 * locking files, they'd throw them all into a kitchen-sink fcntl() call
759 * along the lines of ioctl(), the fact that ioctl() operations are
760 * largely specific to particular character devices but fcntl() operations
761 * are either generic to all descriptors or generic to all descriptors for
762 * regular files nonwithstanding.
764 * The Capsicum people decided that fine-grained control of descriptor
765 * operations was required, so that you need to grant permission for
766 * reading, writing, seeking, and fcntl-ing. The latter, courtesy of
767 * AT&T's decision, means that "fcntl-ing" isn't a thing, but a motley
768 * collection of things, so there are *individual* fcntls for which
769 * permission needs to be granted.
771 * The FreeBSD standard I/O people implemented some optimizations that
772 * requires that the standard I/O routines be able to determine whether
773 * the descriptor for the FILE * is open append-only or not; as that
774 * descriptor could have come from an open() rather than an fopen(),
775 * that requires that it be able to do an F_GETFL fcntl() to read
778 * Tcpdump uses ftell() to determine how much data has been written
779 * to a file in order to, when used with -C, determine when it's time
780 * to rotate capture files. ftell() therefore needs to do an lseek()
781 * to find out the file offset and must, thanks to the aforementioned
782 * optimization, also know whether the descriptor is open append-only
785 * The net result of all the above is that we need to grant CAP_SEEK,
786 * CAP_WRITE, and CAP_FCNTL with the CAP_FCNTL_GETFL subcapability.
788 * Perhaps this is the universe's way of saying that either
790 * 1) there needs to be an fopenat() call and a pcap_dump_openat() call
791 * using it, so that Capsicum-capable tcpdump wouldn't need to do
796 * 2) there needs to be a cap_fdopen() call in the FreeBSD standard
797 * I/O library that knows what rights are needed by the standard
798 * I/O library, based on the open mode, and assigns them, perhaps
799 * with an additional argument indicating, for example, whether
800 * seeking should be allowed, so that tcpdump doesn't need to know
801 * what the standard I/O library happens to require this week.
804 set_dumper_capsicum_rights(pcap_dumper_t
*p
)
806 int fd
= fileno(pcap_dump_file(p
));
809 cap_rights_init(&rights
, CAP_SEEK
, CAP_WRITE
, CAP_FCNTL
);
810 if (cap_rights_limit(fd
, &rights
) < 0 && errno
!= ENOSYS
) {
811 error("unable to limit dump descriptor");
813 if (cap_fcntls_limit(fd
, CAP_FCNTL_GETFL
) < 0 && errno
!= ENOSYS
) {
814 error("unable to limit dump descriptor fcntls");
820 * Copy arg vector into a new buffer, concatenating arguments with spaces.
823 copy_argv(register char **argv
)
826 register u_int len
= 0;
835 len
+= strlen(*p
++) + 1;
837 buf
= (char *)malloc(len
);
839 error("copy_argv: malloc");
843 while ((src
= *p
++) != NULL
) {
844 while ((*dst
++ = *src
++) != '\0')
854 * On Windows, we need to open the file in binary mode, so that
855 * we get all the bytes specified by the size we get from "fstat()".
856 * On UNIX, that's not necessary. O_BINARY is defined on Windows;
857 * we define it as 0 if it's not defined, so it does nothing.
864 read_infile(char *fname
)
866 register int i
, fd
, cc
;
870 fd
= open(fname
, O_RDONLY
|O_BINARY
);
872 error("can't open %s: %s", fname
, pcap_strerror(errno
));
874 if (fstat(fd
, &buf
) < 0)
875 error("can't stat %s: %s", fname
, pcap_strerror(errno
));
877 cp
= malloc((u_int
)buf
.st_size
+ 1);
879 error("malloc(%d) for %s: %s", (u_int
)buf
.st_size
+ 1,
880 fname
, pcap_strerror(errno
));
881 cc
= read(fd
, cp
, (u_int
)buf
.st_size
);
883 error("read %s: %s", fname
, pcap_strerror(errno
));
884 if (cc
!= buf
.st_size
)
885 error("short read %s (%d != %d)", fname
, cc
, (int)buf
.st_size
);
888 /* replace "# comment" with spaces */
889 for (i
= 0; i
< cc
; i
++) {
891 while (i
< cc
&& cp
[i
] != '\n')
898 #ifdef HAVE_PCAP_FINDALLDEVS
900 parse_interface_number(const char *device
)
905 devnum
= strtol(device
, &end
, 10);
906 if (device
!= end
&& *end
== '\0') {
908 * It's all-numeric, but is it a valid number?
912 * No, it's not an ordinal.
914 error("Invalid adapter index");
919 * It's not all-numeric; return -1, so our caller
927 find_interface_by_number(long devnum
)
929 pcap_if_t
*dev
, *devlist
;
931 char ebuf
[PCAP_ERRBUF_SIZE
];
934 if (pcap_findalldevs(&devlist
, ebuf
) < 0)
937 * Look for the devnum-th entry in the list of devices (1-based).
939 for (i
= 0, dev
= devlist
; i
< devnum
-1 && dev
!= NULL
;
940 i
++, dev
= dev
->next
)
943 error("Invalid adapter index");
944 device
= strdup(dev
->name
);
945 pcap_freealldevs(devlist
);
951 open_interface(const char *device
, netdissect_options
*ndo
, char *ebuf
)
954 #ifdef HAVE_PCAP_CREATE
959 #ifdef HAVE_PCAP_CREATE
960 pc
= pcap_create(device
, ebuf
);
963 * If this failed with "No such device", that means
964 * the interface doesn't exist; return NULL, so that
965 * the caller can see whether the device name is
966 * actually an interface index.
968 if (strstr(ebuf
, "No such device") != NULL
)
972 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
974 show_tstamp_types_and_exit(device
);
976 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
977 status
= pcap_set_tstamp_precision(pc
, ndo
->ndo_tstamp_precision
);
979 error("%s: Can't set %ssecond time stamp precision: %s",
981 tstamp_precision_to_string(ndo
->ndo_tstamp_precision
),
982 pcap_statustostr(status
));
985 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
986 if (immediate_mode
) {
987 status
= pcap_set_immediate_mode(pc
, 1);
989 error("%s: Can't set immediate mode: %s",
991 pcap_statustostr(status
));
995 * Is this an interface that supports monitor mode?
997 if (pcap_can_set_rfmon(pc
) == 1)
998 supports_monitor_mode
= 1;
1000 supports_monitor_mode
= 0;
1001 status
= pcap_set_snaplen(pc
, ndo
->ndo_snaplen
);
1003 error("%s: Can't set snapshot length: %s",
1004 device
, pcap_statustostr(status
));
1005 status
= pcap_set_promisc(pc
, !pflag
);
1007 error("%s: Can't set promiscuous mode: %s",
1008 device
, pcap_statustostr(status
));
1010 status
= pcap_set_rfmon(pc
, 1);
1012 error("%s: Can't set monitor mode: %s",
1013 device
, pcap_statustostr(status
));
1015 status
= pcap_set_timeout(pc
, 1000);
1017 error("%s: pcap_set_timeout failed: %s",
1018 device
, pcap_statustostr(status
));
1020 status
= pcap_set_buffer_size(pc
, Bflag
);
1022 error("%s: Can't set buffer size: %s",
1023 device
, pcap_statustostr(status
));
1025 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1027 status
= pcap_set_tstamp_type(pc
, jflag
);
1029 error("%s: Can't set time stamp type: %s",
1030 device
, pcap_statustostr(status
));
1033 status
= pcap_activate(pc
);
1036 * pcap_activate() failed.
1038 cp
= pcap_geterr(pc
);
1039 if (status
== PCAP_ERROR
)
1041 else if (status
== PCAP_ERROR_NO_SUCH_DEVICE
) {
1043 * Return an error for our caller to handle.
1046 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s: %s\n(%s)",
1047 device
, pcap_statustostr(status
), cp
);
1049 } else if (status
== PCAP_ERROR_PERM_DENIED
&& *cp
!= '\0')
1050 error("%s: %s\n(%s)", device
,
1051 pcap_statustostr(status
), cp
);
1053 error("%s: %s", device
,
1054 pcap_statustostr(status
));
1055 } else if (status
> 0) {
1057 * pcap_activate() succeeded, but it's warning us
1058 * of a problem it had.
1060 cp
= pcap_geterr(pc
);
1061 if (status
== PCAP_WARNING
)
1063 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1065 warning("%s: %s\n(%s)", device
,
1066 pcap_statustostr(status
), cp
);
1068 warning("%s: %s", device
,
1069 pcap_statustostr(status
));
1071 #ifdef HAVE_PCAP_SETDIRECTION
1073 status
= pcap_setdirection(pc
, Qflag
);
1075 error("%s: pcap_setdirection() failed: %s",
1076 device
, pcap_geterr(pc
));
1078 #endif /* HAVE_PCAP_SETDIRECTION */
1079 #else /* HAVE_PCAP_CREATE */
1081 pc
= pcap_open_live(device
, ndo
->ndo_snaplen
, !pflag
, 1000, ebuf
);
1084 * If this failed with "No such device", that means
1085 * the interface doesn't exist; return NULL, so that
1086 * the caller can see whether the device name is
1087 * actually an interface index.
1089 if (strstr(ebuf
, "No such device") != NULL
)
1094 warning("%s", ebuf
);
1095 #endif /* HAVE_PCAP_CREATE */
1101 main(int argc
, char **argv
)
1103 register int cnt
, op
, i
;
1104 bpf_u_int32 localnet
=0 , netmask
= 0;
1105 int timezone_offset
= 0;
1106 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *VFileName
, *WFileName
;
1107 pcap_handler callback
;
1109 const char *dlt_name
;
1110 struct bpf_program fcode
;
1112 RETSIGTYPE (*oldhandler
)(int);
1114 struct dump_info dumpinfo
;
1115 u_char
*pcap_userdata
;
1116 char ebuf
[PCAP_ERRBUF_SIZE
];
1117 char VFileLine
[PATH_MAX
+ 1];
1118 char *username
= NULL
;
1119 char *chroot_dir
= NULL
;
1122 #ifdef HAVE_PCAP_FINDALLDEVS
1128 #ifdef HAVE_CAPSICUM
1129 cap_rights_t rights
;
1131 #endif /* HAVE_CAPSICUM */
1132 int Oflag
= 1; /* run filter code optimizer */
1134 const char *yflag_dlt_name
= NULL
;
1136 netdissect_options Ndo
;
1137 netdissect_options
*ndo
= &Ndo
;
1140 * Initialize the netdissect code.
1142 if (nd_init(ebuf
, sizeof ebuf
) == -1)
1145 memset(ndo
, 0, sizeof(*ndo
));
1146 ndo_set_function_pointers(ndo
);
1147 ndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
1157 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
1158 ndo
->program_name
= program_name
= cp
+ 1;
1160 ndo
->program_name
= program_name
= argv
[0];
1163 if (pcap_wsockinit() != 0)
1164 error("Attempting to initialize Winsock failed");
1168 * On platforms where the CPU doesn't support unaligned loads,
1169 * force unaligned accesses to abort with SIGBUS, rather than
1170 * being fixed up (slowly) by the OS kernel; on those platforms,
1171 * misaligned accesses are bugs, and we want tcpdump to crash so
1172 * that the bugs are reported.
1174 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
1178 (op
= getopt_long(argc
, argv
, SHORTOPTS
, longopts
, NULL
)) != -1)
1182 /* compatibility for old -a */
1193 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
1195 Bflag
= atoi(optarg
)*1024;
1197 error("invalid packet buffer size %s", optarg
);
1199 #endif /* defined(HAVE_PCAP_CREATE) || defined(_WIN32) */
1204 error("invalid packet count %s", optarg
);
1208 Cflag
= atoi(optarg
) * 1000000;
1210 error("invalid file size %s", optarg
);
1230 #ifndef HAVE_LIBCRYPTO
1231 warning("crypto code not compiled in");
1233 ndo
->ndo_espsecret
= optarg
;
1245 Gflag
= atoi(optarg
);
1247 error("invalid number of seconds %s", optarg
);
1249 /* We will create one file initially. */
1252 /* Grab the current time for rotation use. */
1253 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
1254 error("main: can't get current time: %s",
1255 pcap_strerror(errno
));
1272 #ifdef HAVE_PCAP_CREATE
1276 #endif /* HAVE_PCAP_CREATE */
1278 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1280 jflag
= pcap_tstamp_type_name_to_val(optarg
);
1282 error("invalid time stamp type %s", optarg
);
1293 * _IOLBF is the same as _IOFBF in Microsoft's C
1294 * libraries; the only alternative they offer
1297 * XXX - this should really be checking for MSVC++,
1298 * not _WIN32, if, for example, MinGW has its own
1299 * C library that is more UNIX-compatible.
1301 setvbuf(stdout
, NULL
, _IONBF
, 0);
1303 #ifdef HAVE_SETLINEBUF
1306 setvbuf(stdout
, NULL
, _IOLBF
, 0);
1316 if (nd_have_smi_support()) {
1317 if (nd_load_smi_module(optarg
, ebuf
, sizeof ebuf
) == -1)
1320 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
1321 program_name
, optarg
);
1322 (void)fprintf(stderr
, "(no libsmi support)\n");
1327 /* TCP-MD5 shared secret */
1328 #ifndef HAVE_LIBCRYPTO
1329 warning("crypto code not compiled in");
1331 ndo
->ndo_sigsecret
= optarg
;
1352 ++ndo
->ndo_suppress_default_print
;
1355 #ifdef HAVE_PCAP_SETDIRECTION
1357 if (ascii_strcasecmp(optarg
, "in") == 0)
1359 else if (ascii_strcasecmp(optarg
, "out") == 0)
1361 else if (ascii_strcasecmp(optarg
, "inout") == 0)
1362 Qflag
= PCAP_D_INOUT
;
1364 error("unknown capture direction `%s'", optarg
);
1366 #endif /* HAVE_PCAP_SETDIRECTION */
1373 ndo
->ndo_snaplen
= strtol(optarg
, &end
, 0);
1374 if (optarg
== end
|| *end
!= '\0'
1375 || ndo
->ndo_snaplen
< 0 || ndo
->ndo_snaplen
> MAXIMUM_SNAPLEN
)
1376 error("invalid snaplen %s", optarg
);
1377 else if (ndo
->ndo_snaplen
== 0)
1378 ndo
->ndo_snaplen
= MAXIMUM_SNAPLEN
;
1390 if (ascii_strcasecmp(optarg
, "vat") == 0)
1391 ndo
->ndo_packettype
= PT_VAT
;
1392 else if (ascii_strcasecmp(optarg
, "wb") == 0)
1393 ndo
->ndo_packettype
= PT_WB
;
1394 else if (ascii_strcasecmp(optarg
, "rpc") == 0)
1395 ndo
->ndo_packettype
= PT_RPC
;
1396 else if (ascii_strcasecmp(optarg
, "rtp") == 0)
1397 ndo
->ndo_packettype
= PT_RTP
;
1398 else if (ascii_strcasecmp(optarg
, "rtcp") == 0)
1399 ndo
->ndo_packettype
= PT_RTCP
;
1400 else if (ascii_strcasecmp(optarg
, "snmp") == 0)
1401 ndo
->ndo_packettype
= PT_SNMP
;
1402 else if (ascii_strcasecmp(optarg
, "cnfp") == 0)
1403 ndo
->ndo_packettype
= PT_CNFP
;
1404 else if (ascii_strcasecmp(optarg
, "tftp") == 0)
1405 ndo
->ndo_packettype
= PT_TFTP
;
1406 else if (ascii_strcasecmp(optarg
, "aodv") == 0)
1407 ndo
->ndo_packettype
= PT_AODV
;
1408 else if (ascii_strcasecmp(optarg
, "carp") == 0)
1409 ndo
->ndo_packettype
= PT_CARP
;
1410 else if (ascii_strcasecmp(optarg
, "radius") == 0)
1411 ndo
->ndo_packettype
= PT_RADIUS
;
1412 else if (ascii_strcasecmp(optarg
, "zmtp1") == 0)
1413 ndo
->ndo_packettype
= PT_ZMTP1
;
1414 else if (ascii_strcasecmp(optarg
, "vxlan") == 0)
1415 ndo
->ndo_packettype
= PT_VXLAN
;
1416 else if (ascii_strcasecmp(optarg
, "pgm") == 0)
1417 ndo
->ndo_packettype
= PT_PGM
;
1418 else if (ascii_strcasecmp(optarg
, "pgm_zmtp1") == 0)
1419 ndo
->ndo_packettype
= PT_PGM_ZMTP1
;
1420 else if (ascii_strcasecmp(optarg
, "lmp") == 0)
1421 ndo
->ndo_packettype
= PT_LMP
;
1422 else if (ascii_strcasecmp(optarg
, "resp") == 0)
1423 ndo
->ndo_packettype
= PT_RESP
;
1425 error("unknown packet type `%s'", optarg
);
1432 #ifdef HAVE_PCAP_DUMP_FLUSH
1451 Wflag
= atoi(optarg
);
1453 error("invalid number of output files %s", optarg
);
1454 WflagChars
= getWflagChars(Wflag
);
1459 ++ndo
->ndo_suppress_default_print
;
1464 ++ndo
->ndo_suppress_default_print
;
1468 yflag_dlt_name
= optarg
;
1470 pcap_datalink_name_to_val(yflag_dlt_name
);
1472 error("invalid data link type %s", yflag_dlt_name
);
1475 #ifdef HAVE_PCAP_SET_PARSER_DEBUG
1478 /* Undocumented flag */
1479 pcap_set_parser_debug(1);
1492 ndo
->ndo_packet_number
= 1;
1495 case OPTION_VERSION
:
1500 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
1501 case OPTION_TSTAMP_PRECISION
:
1502 ndo
->ndo_tstamp_precision
= tstamp_precision_from_string(optarg
);
1503 if (ndo
->ndo_tstamp_precision
< 0)
1504 error("unsupported time stamp precision");
1508 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
1509 case OPTION_IMMEDIATE_MODE
:
1520 #ifdef HAVE_PCAP_FINDALLDEVS
1522 show_devices_and_exit();
1525 switch (ndo
->ndo_tflag
) {
1527 case 0: /* Default */
1528 case 4: /* Default + Date*/
1529 timezone_offset
= gmt2local(0);
1532 case 1: /* No time stamp */
1533 case 2: /* Unix timeval style */
1534 case 3: /* Microseconds since previous packet */
1535 case 5: /* Microseconds since first packet */
1538 default: /* Not supported */
1539 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1543 if (ndo
->ndo_fflag
!= 0 && (VFileName
!= NULL
|| RFileName
!= NULL
))
1544 error("-f can not be used with -V or -r");
1546 if (VFileName
!= NULL
&& RFileName
!= NULL
)
1547 error("-V and -r are mutually exclusive.");
1549 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
1551 * If we're printing dissected packets to the standard output
1552 * rather than saving raw packets to a file, and the standard
1553 * output is a terminal, use immediate mode, as the user's
1554 * probably expecting to see packets pop up immediately.
1556 if (WFileName
== NULL
&& isatty(1))
1561 /* if run as root, prepare for chrooting */
1562 if (getuid() == 0 || geteuid() == 0) {
1563 /* future extensibility for cmd-line arguments */
1565 chroot_dir
= WITH_CHROOT
;
1570 /* if run as root, prepare for dropping root privileges */
1571 if (getuid() == 0 || geteuid() == 0) {
1572 /* Run with '-Z root' to restore old behaviour */
1574 username
= WITH_USER
;
1578 if (RFileName
!= NULL
|| VFileName
!= NULL
) {
1580 * If RFileName is non-null, it's the pathname of a
1581 * savefile to read. If VFileName is non-null, it's
1582 * the pathname of a file containing a list of pathnames
1583 * (one per line) of savefiles to read.
1585 * In either case, we're reading a savefile, not doing
1590 * We don't need network access, so relinquish any set-UID
1591 * or set-GID privileges we have (if any).
1593 * We do *not* want set-UID privileges when opening a
1594 * trace file, as that might let the user read other
1595 * people's trace files (especially if we're set-UID
1598 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1599 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1601 if (VFileName
!= NULL
) {
1602 if (VFileName
[0] == '-' && VFileName
[1] == '\0')
1605 VFile
= fopen(VFileName
, "r");
1608 error("Unable to open file: %s\n", pcap_strerror(errno
));
1610 ret
= get_next_file(VFile
, VFileLine
);
1612 error("Nothing in %s\n", VFileName
);
1613 RFileName
= VFileLine
;
1616 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
1617 pd
= pcap_open_offline_with_tstamp_precision(RFileName
,
1618 ndo
->ndo_tstamp_precision
, ebuf
);
1620 pd
= pcap_open_offline(RFileName
, ebuf
);
1625 #ifdef HAVE_CAPSICUM
1626 cap_rights_init(&rights
, CAP_READ
);
1627 if (cap_rights_limit(fileno(pcap_file(pd
)), &rights
) < 0 &&
1629 error("unable to limit pcap descriptor");
1632 dlt
= pcap_datalink(pd
);
1633 dlt_name
= pcap_datalink_val_to_name(dlt
);
1634 if (dlt_name
== NULL
) {
1635 fprintf(stderr
, "reading from file %s, link-type %u\n",
1639 "reading from file %s, link-type %s (%s)\n",
1640 RFileName
, dlt_name
,
1641 pcap_datalink_val_to_description(dlt
));
1645 * We're doing a live capture.
1647 if (device
== NULL
) {
1649 * No interface was specified. Pick one.
1651 #ifdef HAVE_PCAP_FINDALLDEVS
1653 * Find the list of interfaces, and pick
1654 * the first interface.
1656 if (pcap_findalldevs(&devlist
, ebuf
) >= 0 &&
1658 device
= strdup(devlist
->name
);
1659 pcap_freealldevs(devlist
);
1661 #else /* HAVE_PCAP_FINDALLDEVS */
1663 * Use whatever interface pcap_lookupdev()
1666 device
= pcap_lookupdev(ebuf
);
1673 * Try to open the interface with the specified name.
1675 pd
= open_interface(device
, ndo
, ebuf
);
1678 * That failed. If we can get a list of
1679 * interfaces, and the interface name
1680 * is purely numeric, try to use it as
1681 * a 1-based index in the list of
1684 #ifdef HAVE_PCAP_FINDALLDEVS
1685 devnum
= parse_interface_number(device
);
1688 * It's not a number; just report
1689 * the open error and fail.
1695 * OK, it's a number; try to find the
1696 * interface with that index, and try
1699 * find_interface_by_number() exits if it
1700 * couldn't be found.
1702 device
= find_interface_by_number(devnum
);
1703 pd
= open_interface(device
, ndo
, ebuf
);
1706 #else /* HAVE_PCAP_FINDALLDEVS */
1708 * We can't get a list of interfaces; just
1712 #endif /* HAVE_PCAP_FINDALLDEVS */
1716 * Let user own process after socket has been opened.
1719 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1720 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1722 #if !defined(HAVE_PCAP_CREATE) && defined(_WIN32)
1724 if(pcap_setbuff(pd
, Bflag
)==-1){
1725 error("%s", pcap_geterr(pd
));
1727 #endif /* !defined(HAVE_PCAP_CREATE) && defined(_WIN32) */
1729 show_dlts_and_exit(device
);
1730 if (yflag_dlt
>= 0) {
1731 #ifdef HAVE_PCAP_SET_DATALINK
1732 if (pcap_set_datalink(pd
, yflag_dlt
) < 0)
1733 error("%s", pcap_geterr(pd
));
1736 * We don't actually support changing the
1737 * data link type, so we only let them
1738 * set it to what it already is.
1740 if (yflag_dlt
!= pcap_datalink(pd
)) {
1741 error("%s is not one of the DLTs supported by this device\n",
1745 (void)fprintf(stderr
, "%s: data link type %s\n",
1746 program_name
, yflag_dlt_name
);
1747 (void)fflush(stderr
);
1749 i
= pcap_snapshot(pd
);
1750 if (ndo
->ndo_snaplen
< i
) {
1751 warning("snaplen raised from %d to %d", ndo
->ndo_snaplen
, i
);
1752 ndo
->ndo_snaplen
= i
;
1754 if(ndo
->ndo_fflag
!= 0) {
1755 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1756 warning("foreign (-f) flag used but: %s", ebuf
);
1762 cmdbuf
= read_infile(infile
);
1764 cmdbuf
= copy_argv(&argv
[optind
]);
1766 #ifdef HAVE_PCAP_SET_OPTIMIZER_DEBUG
1767 pcap_set_optimizer_debug(dflag
);
1769 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1770 error("%s", pcap_geterr(pd
));
1772 bpf_dump(&fcode
, dflag
);
1775 pcap_freecode(&fcode
);
1778 init_print(ndo
, localnet
, netmask
, timezone_offset
);
1781 (void)setsignal(SIGPIPE
, cleanup
);
1782 (void)setsignal(SIGTERM
, cleanup
);
1783 (void)setsignal(SIGINT
, cleanup
);
1785 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1786 (void)setsignal(SIGCHLD
, child_cleanup
);
1788 /* Cooperate with nohup(1) */
1790 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1791 (void)setsignal(SIGHUP
, oldhandler
);
1796 * If a user name was specified with "-Z", attempt to switch to
1797 * that user's UID. This would probably be used with sudo,
1798 * to allow tcpdump to be run in a special restricted
1799 * account (if you just want to allow users to open capture
1800 * devices, and can't just give users that permission,
1801 * you'd make tcpdump set-UID or set-GID).
1803 * Tcpdump doesn't necessarily write only to one savefile;
1804 * the general only way to allow a -Z instance to write to
1805 * savefiles as the user under whose UID it's run, rather
1806 * than as the user specified with -Z, would thus be to switch
1807 * to the original user ID before opening a capture file and
1808 * then switch back to the -Z user ID after opening the savefile.
1809 * Switching to the -Z user ID only after opening the first
1810 * savefile doesn't handle the general case.
1813 if (getuid() == 0 || geteuid() == 0) {
1814 #ifdef HAVE_LIBCAP_NG
1815 /* Initialize capng */
1816 capng_clear(CAPNG_SELECT_BOTH
);
1820 CAPNG_PERMITTED
| CAPNG_EFFECTIVE
,
1829 CAPNG_PERMITTED
| CAPNG_EFFECTIVE
,
1833 capng_apply(CAPNG_SELECT_BOTH
);
1834 #endif /* HAVE_LIBCAP_NG */
1835 if (username
|| chroot_dir
)
1836 droproot(username
, chroot_dir
);
1841 if (pcap_setfilter(pd
, &fcode
) < 0)
1842 error("%s", pcap_geterr(pd
));
1843 #ifdef HAVE_CAPSICUM
1844 if (RFileName
== NULL
&& VFileName
== NULL
) {
1845 static const unsigned long cmds
[] = { BIOCGSTATS
, BIOCROTZBUF
};
1847 cap_rights_init(&rights
, CAP_IOCTL
, CAP_READ
);
1848 if (cap_rights_limit(pcap_fileno(pd
), &rights
) < 0 &&
1850 error("unable to limit pcap descriptor");
1852 if (cap_ioctls_limit(pcap_fileno(pd
), cmds
,
1853 sizeof(cmds
) / sizeof(cmds
[0])) < 0 && errno
!= ENOSYS
) {
1854 error("unable to limit ioctls on pcap descriptor");
1860 /* Do not exceed the default PATH_MAX for files. */
1861 dumpinfo
.CurrentFileName
= (char *)malloc(PATH_MAX
+ 1);
1863 if (dumpinfo
.CurrentFileName
== NULL
)
1864 error("malloc of dumpinfo.CurrentFileName");
1866 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1868 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1870 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1872 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1873 #ifdef HAVE_LIBCAP_NG
1874 /* Give up CAP_DAC_OVERRIDE capability.
1875 * Only allow it to be restored if the -C or -G flag have been
1876 * set since we may need to create more files later on.
1880 (Cflag
|| Gflag
? 0 : CAPNG_PERMITTED
)
1884 capng_apply(CAPNG_SELECT_BOTH
);
1885 #endif /* HAVE_LIBCAP_NG */
1887 error("%s", pcap_geterr(pd
));
1888 #ifdef HAVE_CAPSICUM
1889 set_dumper_capsicum_rights(p
);
1891 if (Cflag
!= 0 || Gflag
!= 0) {
1892 #ifdef HAVE_CAPSICUM
1893 dumpinfo
.WFileName
= strdup(basename(WFileName
));
1894 if (dumpinfo
.WFileName
== NULL
) {
1895 error("Unable to allocate memory for file %s",
1898 dumpinfo
.dirfd
= open(dirname(WFileName
),
1899 O_DIRECTORY
| O_RDONLY
);
1900 if (dumpinfo
.dirfd
< 0) {
1901 error("unable to open directory %s",
1902 dirname(WFileName
));
1904 cap_rights_init(&rights
, CAP_CREATE
, CAP_FCNTL
,
1905 CAP_FTRUNCATE
, CAP_LOOKUP
, CAP_SEEK
, CAP_WRITE
);
1906 if (cap_rights_limit(dumpinfo
.dirfd
, &rights
) < 0 &&
1908 error("unable to limit directory rights");
1910 if (cap_fcntls_limit(dumpinfo
.dirfd
, CAP_FCNTL_GETFL
) < 0 &&
1912 error("unable to limit dump descriptor fcntls");
1914 #else /* !HAVE_CAPSICUM */
1915 dumpinfo
.WFileName
= WFileName
;
1917 callback
= dump_packet_and_trunc
;
1920 pcap_userdata
= (u_char
*)&dumpinfo
;
1922 callback
= dump_packet
;
1923 pcap_userdata
= (u_char
*)p
;
1925 #ifdef HAVE_PCAP_DUMP_FLUSH
1930 dlt
= pcap_datalink(pd
);
1931 ndo
->ndo_if_printer
= get_if_printer(ndo
, dlt
);
1932 callback
= print_packet
;
1933 pcap_userdata
= (u_char
*)ndo
;
1936 #ifdef SIGNAL_REQ_INFO
1938 * We can't get statistics when reading from a file rather
1939 * than capturing from a device.
1941 if (RFileName
== NULL
)
1942 (void)setsignal(SIGNAL_REQ_INFO
, requestinfo
);
1945 if (ndo
->ndo_vflag
> 0 && WFileName
) {
1947 * When capturing to a file, "-v" means tcpdump should,
1948 * every 10 seconds, "v"erbosely report the number of
1951 #ifdef USE_WIN32_MM_TIMER
1952 /* call verbose_stats_dump() each 1000 +/-100msec */
1953 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1954 setvbuf(stderr
, NULL
, _IONBF
, 0);
1955 #elif defined(HAVE_ALARM)
1956 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1961 if (RFileName
== NULL
) {
1963 * Live capture (if -V was specified, we set RFileName
1964 * to a file from the -V file). Print a message to
1965 * the standard error on UN*X.
1967 if (!ndo
->ndo_vflag
&& !WFileName
) {
1968 (void)fprintf(stderr
,
1969 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1972 (void)fprintf(stderr
, "%s: ", program_name
);
1973 dlt
= pcap_datalink(pd
);
1974 dlt_name
= pcap_datalink_val_to_name(dlt
);
1975 if (dlt_name
== NULL
) {
1976 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1977 device
, dlt
, ndo
->ndo_snaplen
);
1979 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1981 pcap_datalink_val_to_description(dlt
), ndo
->ndo_snaplen
);
1983 (void)fflush(stderr
);
1986 #ifdef HAVE_CAPSICUM
1987 cansandbox
= (ndo
->ndo_nflag
&& VFileName
== NULL
&& zflag
== NULL
);
1988 if (cansandbox
&& cap_enter() < 0 && errno
!= ENOSYS
)
1989 error("unable to enter the capability mode");
1990 #endif /* HAVE_CAPSICUM */
1993 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1994 if (WFileName
== NULL
) {
1996 * We're printing packets. Flush the printed output,
1997 * so it doesn't get intermingled with error output.
2001 * We got interrupted, so perhaps we didn't
2002 * manage to finish a line we were printing.
2003 * Print an extra newline, just in case.
2007 (void)fflush(stdout
);
2011 * We got interrupted. If we are reading multiple
2012 * files (via -V) set these so that we stop.
2021 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
2022 program_name
, pcap_geterr(pd
));
2024 if (RFileName
== NULL
) {
2026 * We're doing a live capture. Report the capture
2032 if (VFileName
!= NULL
) {
2033 ret
= get_next_file(VFile
, VFileLine
);
2037 RFileName
= VFileLine
;
2038 pd
= pcap_open_offline(RFileName
, ebuf
);
2041 #ifdef HAVE_CAPSICUM
2042 cap_rights_init(&rights
, CAP_READ
);
2043 if (cap_rights_limit(fileno(pcap_file(pd
)),
2044 &rights
) < 0 && errno
!= ENOSYS
) {
2045 error("unable to limit pcap descriptor");
2048 new_dlt
= pcap_datalink(pd
);
2049 if (new_dlt
!= dlt
) {
2051 * The new file has a different
2052 * link-layer header type from the
2055 if (WFileName
!= NULL
) {
2057 * We're writing raw packets
2058 * that match the filter to
2059 * a pcap file. pcap files
2060 * don't support multiple
2061 * different link-layer
2062 * header types, so we fail
2065 error("%s: new dlt does not match original", RFileName
);
2069 * We're printing the decoded packets;
2070 * switch to the new DLT.
2072 * To do that, we need to change
2073 * the printer, change the DLT name,
2074 * and recompile the filter with
2078 ndo
->ndo_if_printer
= get_if_printer(ndo
, dlt
);
2079 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
2080 error("%s", pcap_geterr(pd
));
2084 * Set the filter on the new file.
2086 if (pcap_setfilter(pd
, &fcode
) < 0)
2087 error("%s", pcap_geterr(pd
));
2090 * Report the new file.
2092 dlt_name
= pcap_datalink_val_to_name(dlt
);
2093 if (dlt_name
== NULL
) {
2094 fprintf(stderr
, "reading from file %s, link-type %u\n",
2098 "reading from file %s, link-type %s (%s)\n",
2099 RFileName
, dlt_name
,
2100 pcap_datalink_val_to_description(dlt
));
2105 while (ret
!= NULL
);
2108 pcap_freecode(&fcode
);
2109 exit_tcpdump(status
== -1 ? 1 : 0);
2112 /* make a clean exit on interrupts */
2114 cleanup(int signo _U_
)
2116 #ifdef USE_WIN32_MM_TIMER
2118 timeKillEvent(timer_id
);
2120 #elif defined(HAVE_ALARM)
2124 #ifdef HAVE_PCAP_BREAKLOOP
2126 * We have "pcap_breakloop()"; use it, so that we do as little
2127 * as possible in the signal handler (it's probably not safe
2128 * to do anything with standard I/O streams in a signal handler -
2129 * the ANSI C standard doesn't say it is).
2134 * We don't have "pcap_breakloop()"; this isn't safe, but
2135 * it's the best we can do. Print the summary if we're
2136 * not reading from a savefile - i.e., if we're doing a
2137 * live capture - and exit.
2139 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
2141 * We got interrupted, so perhaps we didn't
2142 * manage to finish a line we were printing.
2143 * Print an extra newline, just in case.
2146 (void)fflush(stdout
);
2154 On windows, we do not use a fork, so we do not care less about
2155 waiting a child processes to die
2157 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
2159 child_cleanup(int signo _U_
)
2163 #endif /* HAVE_FORK && HAVE_VFORK */
2166 info(register int verbose
)
2168 struct pcap_stat stats
;
2171 * Older versions of libpcap didn't set ps_ifdrop on some
2172 * platforms; initialize it to 0 to handle that.
2174 stats
.ps_ifdrop
= 0;
2175 if (pcap_stats(pd
, &stats
) < 0) {
2176 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
2182 fprintf(stderr
, "%s: ", program_name
);
2184 (void)fprintf(stderr
, "%u packet%s captured", packets_captured
,
2185 PLURAL_SUFFIX(packets_captured
));
2187 fputs(", ", stderr
);
2190 (void)fprintf(stderr
, "%u packet%s received by filter", stats
.ps_recv
,
2191 PLURAL_SUFFIX(stats
.ps_recv
));
2193 fputs(", ", stderr
);
2196 (void)fprintf(stderr
, "%u packet%s dropped by kernel", stats
.ps_drop
,
2197 PLURAL_SUFFIX(stats
.ps_drop
));
2198 if (stats
.ps_ifdrop
!= 0) {
2200 fputs(", ", stderr
);
2203 (void)fprintf(stderr
, "%u packet%s dropped by interface\n",
2204 stats
.ps_ifdrop
, PLURAL_SUFFIX(stats
.ps_ifdrop
));
2210 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
2212 #define fork_subprocess() fork()
2214 #define fork_subprocess() vfork()
2217 compress_savefile(const char *filename
)
2221 child
= fork_subprocess();
2224 "compress_savefile: fork failed: %s\n",
2225 pcap_strerror(errno
));
2229 /* Parent process. */
2235 * Set to lowest priority so that this doesn't disturb the capture.
2238 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
2240 setpriority(PRIO_PROCESS
, 0, 19);
2242 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
2244 "compress_savefile: execlp(%s, %s) failed: %s\n",
2247 pcap_strerror(errno
));
2254 #else /* HAVE_FORK && HAVE_VFORK */
2256 compress_savefile(const char *filename
)
2259 "compress_savefile failed. Functionality not implemented under your system\n");
2261 #endif /* HAVE_FORK && HAVE_VFORK */
2264 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
2266 struct dump_info
*dump_info
;
2272 dump_info
= (struct dump_info
*)user
;
2275 * XXX - this won't force the file to rotate on the specified time
2276 * boundary, but it will rotate on the first packet received after the
2277 * specified Gflag number of seconds. Note: if a Gflag time boundary
2278 * and a Cflag size boundary coincide, the time rotation will occur
2279 * first thereby cancelling the Cflag boundary (since the file should
2283 /* Check if it is time to rotate */
2286 /* Get the current time */
2287 if ((t
= time(NULL
)) == (time_t)-1) {
2288 error("dump_and_trunc_packet: can't get current_time: %s",
2289 pcap_strerror(errno
));
2293 /* If the time is greater than the specified window, rotate */
2294 if (t
- Gflag_time
>= Gflag
) {
2295 #ifdef HAVE_CAPSICUM
2300 /* Update the Gflag_time */
2302 /* Update Gflag_count */
2305 * Close the current file and open a new one.
2307 pcap_dump_close(dump_info
->p
);
2310 * Compress the file we just closed, if the user asked for it
2313 compress_savefile(dump_info
->CurrentFileName
);
2316 * Check to see if we've exceeded the Wflag (when
2319 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
2320 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
2325 if (dump_info
->CurrentFileName
!= NULL
)
2326 free(dump_info
->CurrentFileName
);
2327 /* Allocate space for max filename + \0. */
2328 dump_info
->CurrentFileName
= (char *)malloc(PATH_MAX
+ 1);
2329 if (dump_info
->CurrentFileName
== NULL
)
2330 error("dump_packet_and_trunc: malloc");
2332 * Gflag was set otherwise we wouldn't be here. Reset the count
2333 * so multiple files would end with 1,2,3 in the filename.
2334 * The counting is handled with the -C flow after this.
2339 * This is always the first file in the Cflag
2341 * We also don't need numbering if Cflag is not set.
2344 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
2347 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
2349 #ifdef HAVE_LIBCAP_NG
2350 capng_update(CAPNG_ADD
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2351 capng_apply(CAPNG_SELECT_BOTH
);
2352 #endif /* HAVE_LIBCAP_NG */
2353 #ifdef HAVE_CAPSICUM
2354 fd
= openat(dump_info
->dirfd
,
2355 dump_info
->CurrentFileName
,
2356 O_CREAT
| O_WRONLY
| O_TRUNC
, 0644);
2358 error("unable to open file %s",
2359 dump_info
->CurrentFileName
);
2361 fp
= fdopen(fd
, "w");
2363 error("unable to fdopen file %s",
2364 dump_info
->CurrentFileName
);
2366 dump_info
->p
= pcap_dump_fopen(dump_info
->pd
, fp
);
2367 #else /* !HAVE_CAPSICUM */
2368 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
2370 #ifdef HAVE_LIBCAP_NG
2371 capng_update(CAPNG_DROP
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2372 capng_apply(CAPNG_SELECT_BOTH
);
2373 #endif /* HAVE_LIBCAP_NG */
2374 if (dump_info
->p
== NULL
)
2375 error("%s", pcap_geterr(pd
));
2376 #ifdef HAVE_CAPSICUM
2377 set_dumper_capsicum_rights(dump_info
->p
);
2383 * XXX - this won't prevent capture files from getting
2384 * larger than Cflag - the last packet written to the
2385 * file could put it over Cflag.
2388 long size
= pcap_dump_ftell(dump_info
->p
);
2391 error("ftell fails on output file");
2393 #ifdef HAVE_CAPSICUM
2399 * Close the current file and open a new one.
2401 pcap_dump_close(dump_info
->p
);
2404 * Compress the file we just closed, if the user
2408 compress_savefile(dump_info
->CurrentFileName
);
2412 if (Cflag_count
>= Wflag
)
2415 if (dump_info
->CurrentFileName
!= NULL
)
2416 free(dump_info
->CurrentFileName
);
2417 dump_info
->CurrentFileName
= (char *)malloc(PATH_MAX
+ 1);
2418 if (dump_info
->CurrentFileName
== NULL
)
2419 error("dump_packet_and_trunc: malloc");
2420 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
2421 #ifdef HAVE_LIBCAP_NG
2422 capng_update(CAPNG_ADD
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2423 capng_apply(CAPNG_SELECT_BOTH
);
2424 #endif /* HAVE_LIBCAP_NG */
2425 #ifdef HAVE_CAPSICUM
2426 fd
= openat(dump_info
->dirfd
, dump_info
->CurrentFileName
,
2427 O_CREAT
| O_WRONLY
| O_TRUNC
, 0644);
2429 error("unable to open file %s",
2430 dump_info
->CurrentFileName
);
2432 fp
= fdopen(fd
, "w");
2434 error("unable to fdopen file %s",
2435 dump_info
->CurrentFileName
);
2437 dump_info
->p
= pcap_dump_fopen(dump_info
->pd
, fp
);
2438 #else /* !HAVE_CAPSICUM */
2439 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
2441 #ifdef HAVE_LIBCAP_NG
2442 capng_update(CAPNG_DROP
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2443 capng_apply(CAPNG_SELECT_BOTH
);
2444 #endif /* HAVE_LIBCAP_NG */
2445 if (dump_info
->p
== NULL
)
2446 error("%s", pcap_geterr(pd
));
2447 #ifdef HAVE_CAPSICUM
2448 set_dumper_capsicum_rights(dump_info
->p
);
2453 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
2454 #ifdef HAVE_PCAP_DUMP_FLUSH
2456 pcap_dump_flush(dump_info
->p
);
2465 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
2471 pcap_dump(user
, h
, sp
);
2472 #ifdef HAVE_PCAP_DUMP_FLUSH
2474 pcap_dump_flush((pcap_dumper_t
*)user
);
2483 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
2489 pretty_print_packet((netdissect_options
*)user
, h
, sp
, packets_captured
);
2498 * XXX - there should really be libpcap calls to get the version
2499 * number as a string (the string would be generated from #defines
2500 * at run time, so that it's not generated from string constants
2501 * in the library, as, on many UNIX systems, those constants would
2502 * be statically linked into the application executable image, and
2503 * would thus reflect the version of libpcap on the system on
2504 * which the application was *linked*, not the system on which it's
2507 * That routine should be documented, unlike the "version[]"
2508 * string, so that UNIX vendors providing their own libpcaps
2509 * don't omit it (as a couple of vendors have...).
2511 * Packet.dll should perhaps also export a routine to return the
2512 * version number of the Packet.dll code, to supply the
2513 * "Wpcap_version" information on Windows.
2515 char WDversion
[]="current-git.tcpdump.org";
2516 #if !defined(HAVE_GENERATED_VERSION)
2517 char version
[]="current-git.tcpdump.org";
2519 char pcap_version
[]="current-git.tcpdump.org";
2520 char Wpcap_version
[]="3.1";
2523 #ifdef SIGNAL_REQ_INFO
2524 RETSIGTYPE
requestinfo(int signo _U_
)
2534 * Called once each second in verbose mode while dumping to file
2536 #ifdef USE_WIN32_MM_TIMER
2537 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
2538 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
2541 fprintf(stderr
, "Got %u\r", packets_captured
);
2543 #elif defined(HAVE_ALARM)
2544 static void verbose_stats_dump(int sig _U_
)
2547 fprintf(stderr
, "Got %u\r", packets_captured
);
2552 USES_APPLE_DEPRECATED_API
2556 extern char version
[];
2557 #ifndef HAVE_PCAP_LIB_VERSION
2558 #if defined(_WIN32) || defined(HAVE_PCAP_VERSION)
2559 extern char pcap_version
[];
2560 #else /* defined(_WIN32) || defined(HAVE_PCAP_VERSION) */
2561 static char pcap_version
[] = "unknown";
2562 #endif /* defined(_WIN32) || defined(HAVE_PCAP_VERSION) */
2563 #endif /* HAVE_PCAP_LIB_VERSION */
2564 const char *smi_version_string
;
2566 #ifdef HAVE_PCAP_LIB_VERSION
2568 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
2570 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
2572 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
2573 #else /* HAVE_PCAP_LIB_VERSION */
2575 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
2576 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
2578 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
2579 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
2581 #endif /* HAVE_PCAP_LIB_VERSION */
2583 #if defined(HAVE_LIBCRYPTO) && defined(SSLEAY_VERSION)
2584 (void)fprintf (stderr
, "%s\n", SSLeay_version(SSLEAY_VERSION
));
2587 smi_version_string
= nd_smi_version_string();
2588 if (smi_version_string
!= NULL
)
2589 (void)fprintf (stderr
, "SMI-library: %s\n", smi_version_string
);
2597 (void)fprintf(stderr
,
2598 "Usage: %s [-aAbd" D_FLAG
"efhH" I_FLAG J_FLAG
"KlLnNOpqStu" U_FLAG
"vxX#]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
2599 (void)fprintf(stderr
,
2600 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
2601 (void)fprintf(stderr
,
2602 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ] [ --number ]\n");
2603 #ifdef HAVE_PCAP_SETDIRECTION
2604 (void)fprintf(stderr
,
2605 "\t\t[ -Q in|out|inout ]\n");
2607 (void)fprintf(stderr
,
2608 "\t\t[ -r file ] [ -s snaplen ] ");
2609 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
2610 (void)fprintf(stderr
, "[ --time-stamp-precision precision ]\n");
2611 (void)fprintf(stderr
,
2614 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
2615 (void)fprintf(stderr
, "[ --immediate-mode ] ");
2617 (void)fprintf(stderr
, "[ -T type ] [ --version ] [ -V file ]\n");
2618 (void)fprintf(stderr
,
2619 "\t\t[ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z postrotate-command ]\n");
2620 (void)fprintf(stderr
,
2621 "\t\t[ -Z user ] [ expression ]\n");
2625 * c-style: whitesmith