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 - monitor tcp/ip traffic on an ethernet.
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 <tcpdump-stdinc.h>
61 extern int strcasecmp (const char *__s1
, const char *__s2
);
72 #include <openssl/crypto.h>
75 #ifdef HAVE_GETOPT_LONG
78 #include "getopt_long.h"
80 /* Capsicum-specific code requires macros from <net/bpf.h>, which will fail
81 * to compile if <pcap.h> has already been included; including the headers
82 * in the opposite order works fine.
85 #include <sys/capability.h>
86 #include <sys/ioccom.h>
90 #endif /* HAVE_CAPSICUM */
99 #include <sys/resource.h>
104 /* capabilities convenience library */
105 /* If a code depends on HAVE_LIBCAP_NG, it depends also on HAVE_CAP_NG_H.
106 * If HAVE_CAP_NG_H is not defined, undefine HAVE_LIBCAP_NG.
107 * Thus, the later tests are done only on HAVE_LIBCAP_NG.
109 #ifdef HAVE_LIBCAP_NG
113 #undef HAVE_LIBCAP_NG
114 #endif /* HAVE_CAP_NG_H */
115 #endif /* HAVE_LIBCAP_NG */
117 #include "netdissect.h"
118 #include "interface.h"
119 #include "addrtoname.h"
121 #include "setsignal.h"
122 #include "gmt2local.h"
123 #include "pcap-missing.h"
126 #define PATH_MAX 1024
130 #define SIGNAL_REQ_INFO SIGINFO
132 #define SIGNAL_REQ_INFO SIGUSR1
135 netdissect_options Gndo
;
136 netdissect_options
*gndo
= &Gndo
;
138 static int Dflag
; /* list available devices and exit */
139 static int dflag
; /* print filter code */
140 static int Lflag
; /* list available data link types and exit */
141 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
142 static int Jflag
; /* list available time stamp types */
144 #ifdef HAVE_PCAP_SETDIRECTION
145 int Qflag
= -1; /* restrict captured packet by send/receive direction */
147 static char *zflag
= NULL
; /* compress each savefile using a specified command (like gzip or bzip2) */
149 static int infodelay
;
150 static int infoprint
;
154 int32_t thiszone
; /* seconds offset from gmt to local time */
157 static RETSIGTYPE
cleanup(int);
158 static RETSIGTYPE
child_cleanup(int);
159 static void print_version(void);
160 static void print_usage(void);
161 static void show_dlts_and_exit(const char *device
, pcap_t
*pd
) __attribute__((noreturn
));
163 static void print_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
164 static void ndo_default_print(netdissect_options
*, const u_char
*, u_int
);
165 static void dump_packet_and_trunc(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
166 static void dump_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
167 static void droproot(const char *, const char *);
168 static void ndo_error(netdissect_options
*ndo
, const char *fmt
, ...)
169 __attribute__((noreturn
))
170 #ifdef __ATTRIBUTE___FORMAT_OK
171 __attribute__((format (printf
, 2, 3)))
172 #endif /* __ATTRIBUTE___FORMAT_OK */
174 static void ndo_warning(netdissect_options
*ndo
, const char *fmt
, ...)
175 #ifdef __ATTRIBUTE___FORMAT_OK
176 __attribute__((format (printf
, 2, 3)))
177 #endif /* __ATTRIBUTE___FORMAT_OK */
180 #ifdef SIGNAL_REQ_INFO
181 RETSIGTYPE
requestinfo(int);
184 #if defined(USE_WIN32_MM_TIMER)
185 #include <MMsystem.h>
186 static UINT timer_id
;
187 static void CALLBACK
verbose_stats_dump(UINT
, UINT
, DWORD_PTR
, DWORD_PTR
, DWORD_PTR
);
188 #elif defined(HAVE_ALARM)
189 static void verbose_stats_dump(int sig
);
192 static void info(int);
193 static u_int packets_captured
;
207 static const struct printer printers
[] = {
211 static const struct ndo_printer ndo_printers
[] = {
212 { ether_if_print
, DLT_EN10MB
},
214 { ipnet_if_print
, DLT_IPNET
},
216 #ifdef DLT_IEEE802_15_4
217 { ieee802_15_4_if_print
, DLT_IEEE802_15_4
},
219 #ifdef DLT_IEEE802_15_4_NOFCS
220 { ieee802_15_4_if_print
, DLT_IEEE802_15_4_NOFCS
},
223 { ppi_if_print
, DLT_PPI
},
225 #ifdef DLT_NETANALYZER
226 { netanalyzer_if_print
, DLT_NETANALYZER
},
228 #ifdef DLT_NETANALYZER_TRANSPARENT
229 { netanalyzer_transparent_if_print
, DLT_NETANALYZER_TRANSPARENT
},
231 #if defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H)
232 { nflog_if_print
, DLT_NFLOG
},
235 { cip_if_print
, DLT_CIP
},
238 { cip_if_print
, DLT_ATM_CLIP
},
240 #ifdef DLT_IP_OVER_FC
241 { ipfc_if_print
, DLT_IP_OVER_FC
},
243 { null_if_print
, DLT_NULL
},
245 { null_if_print
, DLT_LOOP
},
247 #ifdef DLT_APPLE_IP_OVER_IEEE1394
248 { ap1394_if_print
, DLT_APPLE_IP_OVER_IEEE1394
},
250 #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
251 { bt_if_print
, DLT_BLUETOOTH_HCI_H4_WITH_PHDR
},
254 { lane_if_print
, DLT_LANE8023
},
256 { arcnet_if_print
, DLT_ARCNET
},
257 #ifdef DLT_ARCNET_LINUX
258 { arcnet_linux_if_print
, DLT_ARCNET_LINUX
},
260 { raw_if_print
, DLT_RAW
},
262 { raw_if_print
, DLT_IPV4
},
265 { raw_if_print
, DLT_IPV6
},
267 #ifdef HAVE_PCAP_USB_H
269 { usb_linux_48_byte_print
, DLT_USB_LINUX
},
270 #endif /* DLT_USB_LINUX */
271 #ifdef DLT_USB_LINUX_MMAPPED
272 { usb_linux_64_byte_print
, DLT_USB_LINUX_MMAPPED
},
273 #endif /* DLT_USB_LINUX_MMAPPED */
274 #endif /* HAVE_PCAP_USB_H */
275 #ifdef DLT_SYMANTEC_FIREWALL
276 { symantec_if_print
, DLT_SYMANTEC_FIREWALL
},
279 { chdlc_if_print
, DLT_C_HDLC
},
282 { chdlc_if_print
, DLT_HDLC
},
285 { pppoe_if_print
, DLT_PPP_ETHER
},
287 #if defined(DLT_PFLOG) && defined(HAVE_NET_PFVAR_H)
288 { pflog_if_print
, DLT_PFLOG
},
290 { token_if_print
, DLT_IEEE802
},
291 { fddi_if_print
, DLT_FDDI
},
293 { sll_if_print
, DLT_LINUX_SLL
},
296 { fr_if_print
, DLT_FR
},
299 { fr_if_print
, DLT_FRELAY
},
302 { mfr_if_print
, DLT_MFR
},
304 { atm_if_print
, DLT_ATM_RFC1483
},
306 { sunatm_if_print
, DLT_SUNATM
},
309 { enc_if_print
, DLT_ENC
},
311 { sl_if_print
, DLT_SLIP
},
312 #ifdef DLT_SLIP_BSDOS
313 { sl_bsdos_if_print
, DLT_SLIP_BSDOS
},
316 { ltalk_if_print
, DLT_LTALK
},
318 #ifdef DLT_JUNIPER_ATM1
319 { juniper_atm1_print
, DLT_JUNIPER_ATM1
},
321 #ifdef DLT_JUNIPER_ATM2
322 { juniper_atm2_print
, DLT_JUNIPER_ATM2
},
324 #ifdef DLT_JUNIPER_MFR
325 { juniper_mfr_print
, DLT_JUNIPER_MFR
},
327 #ifdef DLT_JUNIPER_MLFR
328 { juniper_mlfr_print
, DLT_JUNIPER_MLFR
},
330 #ifdef DLT_JUNIPER_MLPPP
331 { juniper_mlppp_print
, DLT_JUNIPER_MLPPP
},
333 #ifdef DLT_JUNIPER_PPPOE
334 { juniper_pppoe_print
, DLT_JUNIPER_PPPOE
},
336 #ifdef DLT_JUNIPER_PPPOE_ATM
337 { juniper_pppoe_atm_print
, DLT_JUNIPER_PPPOE_ATM
},
339 #ifdef DLT_JUNIPER_GGSN
340 { juniper_ggsn_print
, DLT_JUNIPER_GGSN
},
342 #ifdef DLT_JUNIPER_ES
343 { juniper_es_print
, DLT_JUNIPER_ES
},
345 #ifdef DLT_JUNIPER_MONITOR
346 { juniper_monitor_print
, DLT_JUNIPER_MONITOR
},
348 #ifdef DLT_JUNIPER_SERVICES
349 { juniper_services_print
, DLT_JUNIPER_SERVICES
},
351 #ifdef DLT_JUNIPER_ETHER
352 { juniper_ether_print
, DLT_JUNIPER_ETHER
},
354 #ifdef DLT_JUNIPER_PPP
355 { juniper_ppp_print
, DLT_JUNIPER_PPP
},
357 #ifdef DLT_JUNIPER_FRELAY
358 { juniper_frelay_print
, DLT_JUNIPER_FRELAY
},
360 #ifdef DLT_JUNIPER_CHDLC
361 { juniper_chdlc_print
, DLT_JUNIPER_CHDLC
},
364 { pktap_if_print
, DLT_PKTAP
},
366 #ifdef DLT_IEEE802_11_RADIO
367 { ieee802_11_radio_if_print
, DLT_IEEE802_11_RADIO
},
369 #ifdef DLT_IEEE802_11
370 { ieee802_11_if_print
, DLT_IEEE802_11
},
372 #ifdef DLT_IEEE802_11_RADIO_AVS
373 { ieee802_11_radio_avs_if_print
, DLT_IEEE802_11_RADIO_AVS
},
375 #ifdef DLT_PRISM_HEADER
376 { prism_if_print
, DLT_PRISM_HEADER
},
378 { ppp_if_print
, DLT_PPP
},
379 #ifdef DLT_PPP_WITHDIRECTION
380 { ppp_if_print
, DLT_PPP_WITHDIRECTION
},
383 { ppp_bsdos_if_print
, DLT_PPP_BSDOS
},
385 #ifdef DLT_PPP_SERIAL
386 { ppp_hdlc_if_print
, DLT_PPP_SERIAL
},
391 static const struct tok status_flags
[] = {
393 { PCAP_IF_UP
, "Up" },
395 #ifdef PCAP_IF_RUNNING
396 { PCAP_IF_RUNNING
, "Running" },
398 { PCAP_IF_LOOPBACK
, "Loopback" },
403 lookup_printer(int type
)
405 const struct printer
*p
;
407 for (p
= printers
; p
->f
; ++p
)
416 lookup_ndo_printer(int type
)
418 const struct ndo_printer
*p
;
420 for (p
= ndo_printers
; p
->f
; ++p
)
424 #if defined(DLT_USER2) && defined(DLT_PKTAP)
426 * Apple incorrectly chose to use DLT_USER2 for their PKTAP
429 * We map DLT_PKTAP, whether it's DLT_USER2 as it is on Darwin-
430 * based OSes or the same value as LINKTYPE_PKTAP as it is on
431 * other OSes, to LINKTYPE_PKTAP, so files written with
432 * this version of libpcap for a DLT_PKTAP capture have a link-
433 * layer header type of LINKTYPE_PKTAP.
435 * However, files written on OS X Mavericks for a DLT_PKTAP
436 * capture have a link-layer header type of LINKTYPE_USER2.
437 * If we don't have a printer for DLT_USER2, and type is
438 * DLT_USER2, we look up the printer for DLT_PKTAP and use
441 if (type
== DLT_USER2
) {
442 for (p
= ndo_printers
; p
->f
; ++p
)
443 if (DLT_PKTAP
== p
->type
)
454 static int supports_monitor_mode
;
461 netdissect_options
*ndo
;
464 if_ndo_printer ndo_printer
;
471 char *CurrentFileName
;
479 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
481 show_tstamp_types_and_exit(const char *device
, pcap_t
*pd
)
484 int *tstamp_types
= 0;
485 const char *tstamp_type_name
;
488 n_tstamp_types
= pcap_list_tstamp_types(pd
, &tstamp_types
);
489 if (n_tstamp_types
< 0)
490 error("%s", pcap_geterr(pd
));
492 if (n_tstamp_types
== 0) {
493 fprintf(stderr
, "Time stamp type cannot be set for %s\n",
497 fprintf(stderr
, "Time stamp types for %s (use option -j to set):\n",
499 for (i
= 0; i
< n_tstamp_types
; i
++) {
500 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
501 if (tstamp_type_name
!= NULL
) {
502 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
503 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
505 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
508 pcap_free_tstamp_types(tstamp_types
);
514 show_dlts_and_exit(const char *device
, pcap_t
*pd
)
518 const char *dlt_name
;
520 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
522 error("%s", pcap_geterr(pd
));
523 else if (n_dlts
== 0 || !dlts
)
524 error("No data link types.");
527 * If the interface is known to support monitor mode, indicate
528 * whether these are the data link types available when not in
529 * monitor mode, if -I wasn't specified, or when in monitor mode,
530 * when -I was specified (the link-layer types available in
531 * monitor mode might be different from the ones available when
532 * not in monitor mode).
534 if (supports_monitor_mode
)
535 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
537 Iflag
? "when in monitor mode" : "when not in monitor mode");
539 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
542 while (--n_dlts
>= 0) {
543 dlt_name
= pcap_datalink_val_to_name(dlts
[n_dlts
]);
544 if (dlt_name
!= NULL
) {
545 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
546 pcap_datalink_val_to_description(dlts
[n_dlts
]));
549 * OK, does tcpdump handle that type?
551 if (lookup_printer(dlts
[n_dlts
]) == NULL
552 && lookup_ndo_printer(dlts
[n_dlts
]) == NULL
)
553 (void) fprintf(stderr
, " (printing not supported)");
554 fprintf(stderr
, "\n");
556 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
560 #ifdef HAVE_PCAP_FREE_DATALINKS
561 pcap_free_datalinks(dlts
);
566 #ifdef HAVE_PCAP_FINDALLDEVS
568 show_devices_and_exit (void)
570 pcap_if_t
*devpointer
;
571 char ebuf
[PCAP_ERRBUF_SIZE
];
574 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
577 for (i
= 0; devpointer
!= NULL
; i
++) {
578 printf("%d.%s", i
+1, devpointer
->name
);
579 if (devpointer
->description
!= NULL
)
580 printf(" (%s)", devpointer
->description
);
581 if (devpointer
->flags
!= 0)
582 printf(" [%s]", bittok2str(status_flags
, "none", devpointer
->flags
));
584 devpointer
= devpointer
->next
;
589 #endif /* HAVE_PCAP_FINDALLDEVS */
594 * Note that there we use all letters for short options except for g, k,
595 * o, and P, and those are used by other versions of tcpdump, and we should
596 * only use them for the same purposes that the other versions of tcpdump
599 * OS X tcpdump uses -g to force non--v output for IP to be on one
600 * line, making it more "g"repable;
602 * OS X tcpdump uses -k tospecify that packet comments in pcap-ng files
605 * OpenBSD tcpdump uses -o to indicate that OS fingerprinting should be done
606 * for hosts sending TCP SYN packets;
608 * OS X tcpdump uses -P to indicate that -w should write pcap-ng rather
613 * Set up flags that might or might not be supported depending on the
614 * version of libpcap we're using.
616 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
618 #define B_FLAG_USAGE " [ -B size ]"
619 #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
622 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
624 #ifdef HAVE_PCAP_CREATE
626 #else /* HAVE_PCAP_CREATE */
628 #endif /* HAVE_PCAP_CREATE */
630 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
632 #define j_FLAG_USAGE " [ -j tstamptype ]"
634 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
638 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
640 #ifdef HAVE_PCAP_FINDALLDEVS
646 #ifdef HAVE_PCAP_DUMP_FLUSH
652 #ifdef HAVE_PCAP_SETDIRECTION
661 * We do not currently have long options corresponding to all short
662 * options; we should probably pick appropriate option names for them.
664 * However, the short options where the number of times the option is
665 * specified matters, such as -v and -d and -t, should probably not
666 * just map to a long option, as saying
668 * tcpdump --verbose --verbose
670 * doesn't make sense; it should be --verbosity={N} or something such
673 * For long options with no corresponding short options, we define values
674 * outside the range of ASCII graphic characters, make that the last
675 * component of the entry for the long option, and have a case for that
676 * option in the switch statement.
678 #define OPTION_VERSION 128
679 #define OPTION_TSTAMP_PRECISION 129
680 #define OPTION_IMMEDIATE_MODE 130
682 static const struct option longopts
[] = {
683 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
684 { "buffer-size", required_argument
, NULL
, 'B' },
686 { "list-interfaces", no_argument
, NULL
, 'D' },
687 { "help", no_argument
, NULL
, 'h' },
688 { "interface", required_argument
, NULL
, 'i' },
689 #ifdef HAVE_PCAP_CREATE
690 { "monitor-mode", no_argument
, NULL
, 'I' },
692 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
693 { "time-stamp-type", required_argument
, NULL
, 'j' },
694 { "list-time-stamp-types", no_argument
, NULL
, 'J' },
696 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
697 { "time-stamp-precision", required_argument
, NULL
, OPTION_TSTAMP_PRECISION
},
699 { "dont-verify-checksums", no_argument
, NULL
, 'K' },
700 { "list-data-link-types", no_argument
, NULL
, 'L' },
701 { "no-optimize", no_argument
, NULL
, 'O' },
702 { "no-promiscuous-mode", no_argument
, NULL
, 'p' },
703 #ifdef HAVE_PCAP_SETDIRECTION
704 { "direction", required_argument
, NULL
, 'Q' },
706 { "snapshot-length", required_argument
, NULL
, 's' },
707 { "absolute-tcp-sequence-numbers", no_argument
, NULL
, 'S' },
708 #ifdef HAVE_PCAP_DUMP_FLUSH
709 { "packet-buffered", no_argument
, NULL
, 'U' },
711 { "linktype", required_argument
, NULL
, 'y' },
712 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
713 { "immediate-mode", no_argument
, NULL
, OPTION_IMMEDIATE_MODE
},
715 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
716 { "debug-filter-parser", no_argument
, NULL
, 'Y' },
718 { "relinquish-privileges", required_argument
, NULL
, 'Z' },
719 { "number", no_argument
, NULL
, '#' },
720 { "version", no_argument
, NULL
, OPTION_VERSION
},
725 /* Drop root privileges and chroot if necessary */
727 droproot(const char *username
, const char *chroot_dir
)
729 struct passwd
*pw
= NULL
;
731 if (chroot_dir
&& !username
) {
732 fprintf(stderr
, "tcpdump: Chroot without dropping root is insecure\n");
736 pw
= getpwnam(username
);
739 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
740 fprintf(stderr
, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
741 chroot_dir
, pcap_strerror(errno
));
745 #ifdef HAVE_LIBCAP_NG
746 int ret
= capng_change_id(pw
->pw_uid
, pw
->pw_gid
, CAPNG_NO_FLAG
);
748 fprintf(stderr
, "error : ret %d\n", ret
);
751 fprintf(stderr
, "dropped privs to %s\n", username
);
754 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
755 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
756 fprintf(stderr
, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
758 (unsigned long)pw
->pw_uid
,
759 (unsigned long)pw
->pw_gid
,
760 pcap_strerror(errno
));
764 fprintf(stderr
, "dropped privs to %s\n", username
);
766 #endif /* HAVE_LIBCAP_NG */
769 fprintf(stderr
, "tcpdump: Couldn't find user '%.32s'\n",
773 #ifdef HAVE_LIBCAP_NG
774 /* We don't need CAP_SETUID and CAP_SETGID any more. */
777 CAPNG_EFFECTIVE
| CAPNG_PERMITTED
,
781 capng_apply(CAPNG_SELECT_BOTH
);
782 #endif /* HAVE_LIBCAP_NG */
803 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
805 char *filename
= malloc(PATH_MAX
+ 1);
806 if (filename
== NULL
)
807 error("Makefilename: malloc");
809 /* Process with strftime if Gflag is set. */
813 /* Convert Gflag_time to a usable format */
814 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
815 error("MakeTimedFilename: localtime");
818 /* There's no good way to detect an error in strftime since a return
819 * value of 0 isn't necessarily failure.
821 strftime(filename
, PATH_MAX
, orig_name
, local_tm
);
823 strncpy(filename
, orig_name
, PATH_MAX
);
826 if (cnt
== 0 && max_chars
== 0)
827 strncpy(buffer
, filename
, PATH_MAX
+ 1);
829 if (snprintf(buffer
, PATH_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > PATH_MAX
)
830 /* Report an error if the filename is too large */
831 error("too many output files or filename is too long (> %d)", PATH_MAX
);
835 static int tcpdump_printf(netdissect_options
*ndo _U_
,
836 const char *fmt
, ...)
843 ret
=vfprintf(stdout
, fmt
, args
);
849 static struct print_info
850 get_print_info(int type
)
852 struct print_info printinfo
;
854 printinfo
.ndo_type
= 1;
855 printinfo
.ndo
= gndo
;
856 printinfo
.p
.ndo_printer
= lookup_ndo_printer(type
);
857 if (printinfo
.p
.ndo_printer
== NULL
) {
858 printinfo
.p
.printer
= lookup_printer(type
);
859 printinfo
.ndo_type
= 0;
860 if (printinfo
.p
.printer
== NULL
) {
861 gndo
->ndo_dltname
= pcap_datalink_val_to_name(type
);
862 if (gndo
->ndo_dltname
!= NULL
)
863 error("packet printing is not supported for link type %s: use -w",
866 error("packet printing is not supported for link type %d: use -w", type
);
873 get_next_file(FILE *VFile
, char *ptr
)
877 ret
= fgets(ptr
, PATH_MAX
, VFile
);
881 if (ptr
[strlen(ptr
) - 1] == '\n')
882 ptr
[strlen(ptr
) - 1] = '\0';
887 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
889 tstamp_precision_from_string(const char *precision
)
891 if (strncmp(precision
, "nano", strlen("nano")) == 0)
892 return PCAP_TSTAMP_PRECISION_NANO
;
894 if (strncmp(precision
, "micro", strlen("micro")) == 0)
895 return PCAP_TSTAMP_PRECISION_MICRO
;
901 tstamp_precision_to_string(int precision
)
905 case PCAP_TSTAMP_PRECISION_MICRO
:
908 case PCAP_TSTAMP_PRECISION_NANO
:
918 main(int argc
, char **argv
)
920 register int cnt
, op
, i
;
921 bpf_u_int32 localnet
=0 , netmask
= 0;
922 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *VFileName
, *WFileName
;
923 pcap_handler callback
;
927 const char *dlt_name
;
928 struct bpf_program fcode
;
930 RETSIGTYPE (*oldhandler
)(int);
932 struct print_info printinfo
;
933 struct dump_info dumpinfo
;
934 u_char
*pcap_userdata
;
935 char ebuf
[PCAP_ERRBUF_SIZE
];
936 char VFileLine
[PATH_MAX
+ 1];
937 char *username
= NULL
;
938 char *chroot_dir
= NULL
;
941 #ifdef HAVE_PCAP_FINDALLDEVS
942 pcap_if_t
*devpointer
;
950 #endif /* HAVE_CAPSICUM */
953 if(wsockinit() != 0) return 1;
956 jflag
=-1; /* not set */
960 gndo
->ndo_default_print
=ndo_default_print
;
961 gndo
->ndo_printf
=tcpdump_printf
;
962 gndo
->ndo_error
=ndo_error
;
963 gndo
->ndo_warning
=ndo_warning
;
964 gndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
965 gndo
->ndo_immediate
= 0;
975 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
976 program_name
= cp
+ 1;
978 program_name
= argv
[0];
981 * On platforms where the CPU doesn't support unaligned loads,
982 * force unaligned accesses to abort with SIGBUS, rather than
983 * being fixed up (slowly) by the OS kernel; on those platforms,
984 * misaligned accesses are bugs, and we want tcpdump to crash so
985 * that the bugs are reported.
987 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
995 (op
= getopt_long(argc
, argv
, "aAb" B_FLAG
"c:C:d" D_FLAG
"eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG
"KlLm:M:nNOpq" Q_FLAG
"r:Rs:StT:u" U_FLAG
"vV:w:W:xXy:Yz:Z:#", longopts
, NULL
)) != -1)
999 /* compatibility for old -a */
1010 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
1012 Bflag
= atoi(optarg
)*1024;
1014 error("invalid packet buffer size %s", optarg
);
1016 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
1021 error("invalid packet count %s", optarg
);
1025 Cflag
= atoi(optarg
) * 1000000;
1027 error("invalid file size %s", optarg
);
1047 #ifndef HAVE_LIBCRYPTO
1048 warning("crypto code not compiled in");
1050 gndo
->ndo_espsecret
= optarg
;
1062 Gflag
= atoi(optarg
);
1064 error("invalid number of seconds %s", optarg
);
1066 /* We will create one file initially. */
1069 /* Grab the current time for rotation use. */
1070 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
1071 error("main: can't get current time: %s",
1072 pcap_strerror(errno
));
1086 if (optarg
[0] == '0' && optarg
[1] == 0)
1087 error("Invalid adapter index");
1089 #ifdef HAVE_PCAP_FINDALLDEVS
1091 * If the argument is a number, treat it as
1092 * an index into the list of adapters, as
1093 * printed by "tcpdump -D".
1095 * This should be OK on UNIX systems, as interfaces
1096 * shouldn't have names that begin with digits.
1097 * It can be useful on Windows, where more than
1098 * one interface can have the same name.
1100 devnum
= strtol(optarg
, &end
, 10);
1101 if (optarg
!= end
&& *end
== '\0') {
1103 error("Invalid adapter index");
1105 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
1109 * Look for the devnum-th entry
1110 * in the list of devices
1114 i
< devnum
-1 && devpointer
!= NULL
;
1115 i
++, devpointer
= devpointer
->next
)
1117 if (devpointer
== NULL
)
1118 error("Invalid adapter index");
1120 device
= devpointer
->name
;
1123 #endif /* HAVE_PCAP_FINDALLDEVS */
1127 #ifdef HAVE_PCAP_CREATE
1131 #endif /* HAVE_PCAP_CREATE */
1133 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1135 jflag
= pcap_tstamp_type_name_to_val(optarg
);
1137 error("invalid time stamp type %s", optarg
);
1148 * _IOLBF is the same as _IOFBF in Microsoft's C
1149 * libraries; the only alternative they offer
1152 * XXX - this should really be checking for MSVC++,
1153 * not WIN32, if, for example, MinGW has its own
1154 * C library that is more UNIX-compatible.
1156 setvbuf(stdout
, NULL
, _IONBF
, 0);
1158 #ifdef HAVE_SETLINEBUF
1161 setvbuf(stdout
, NULL
, _IOLBF
, 0);
1172 if (smiLoadModule(optarg
) == 0) {
1173 error("could not load MIB module %s", optarg
);
1177 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
1178 program_name
, optarg
);
1179 (void)fprintf(stderr
, "(no libsmi support)\n");
1184 /* TCP-MD5 shared secret */
1185 #ifndef HAVE_LIBCRYPTO
1186 warning("crypto code not compiled in");
1209 ++suppress_default_print
;
1212 #ifdef HAVE_PCAP_SETDIRECTION
1214 if (strcasecmp(optarg
, "in") == 0)
1216 else if (strcasecmp(optarg
, "out") == 0)
1218 else if (strcasecmp(optarg
, "inout") == 0)
1219 Qflag
= PCAP_D_INOUT
;
1221 error("unknown capture direction `%s'", optarg
);
1223 #endif /* HAVE_PCAP_SETDIRECTION */
1234 snaplen
= strtol(optarg
, &end
, 0);
1235 if (optarg
== end
|| *end
!= '\0'
1236 || snaplen
< 0 || snaplen
> MAXIMUM_SNAPLEN
)
1237 error("invalid snaplen %s", optarg
);
1238 else if (snaplen
== 0)
1239 snaplen
= MAXIMUM_SNAPLEN
;
1251 if (strcasecmp(optarg
, "vat") == 0)
1252 packettype
= PT_VAT
;
1253 else if (strcasecmp(optarg
, "wb") == 0)
1255 else if (strcasecmp(optarg
, "rpc") == 0)
1256 packettype
= PT_RPC
;
1257 else if (strcasecmp(optarg
, "rtp") == 0)
1258 packettype
= PT_RTP
;
1259 else if (strcasecmp(optarg
, "rtcp") == 0)
1260 packettype
= PT_RTCP
;
1261 else if (strcasecmp(optarg
, "snmp") == 0)
1262 packettype
= PT_SNMP
;
1263 else if (strcasecmp(optarg
, "cnfp") == 0)
1264 packettype
= PT_CNFP
;
1265 else if (strcasecmp(optarg
, "tftp") == 0)
1266 packettype
= PT_TFTP
;
1267 else if (strcasecmp(optarg
, "aodv") == 0)
1268 packettype
= PT_AODV
;
1269 else if (strcasecmp(optarg
, "carp") == 0)
1270 packettype
= PT_CARP
;
1271 else if (strcasecmp(optarg
, "radius") == 0)
1272 packettype
= PT_RADIUS
;
1273 else if (strcasecmp(optarg
, "zmtp1") == 0)
1274 packettype
= PT_ZMTP1
;
1275 else if (strcasecmp(optarg
, "vxlan") == 0)
1276 packettype
= PT_VXLAN
;
1277 else if (strcasecmp(optarg
, "pgm") == 0)
1278 packettype
= PT_PGM
;
1279 else if (strcasecmp(optarg
, "pgm_zmtp1") == 0)
1280 packettype
= PT_PGM_ZMTP1
;
1281 else if (strcasecmp(optarg
, "lmp") == 0)
1282 packettype
= PT_LMP
;
1284 error("unknown packet type `%s'", optarg
);
1291 #ifdef HAVE_PCAP_DUMP_FLUSH
1310 Wflag
= atoi(optarg
);
1312 error("invalid number of output files %s", optarg
);
1313 WflagChars
= getWflagChars(Wflag
);
1318 ++suppress_default_print
;
1323 ++suppress_default_print
;
1327 gndo
->ndo_dltname
= optarg
;
1329 pcap_datalink_name_to_val(gndo
->ndo_dltname
);
1330 if (gndo
->ndo_dlt
< 0)
1331 error("invalid data link type %s", gndo
->ndo_dltname
);
1334 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
1337 /* Undocumented flag */
1338 #ifdef HAVE_PCAP_DEBUG
1339 extern int pcap_debug
;
1349 zflag
= strdup(optarg
);
1353 username
= strdup(optarg
);
1357 gndo
->ndo_packet_number
= 1;
1360 case OPTION_VERSION
:
1365 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
1366 case OPTION_TSTAMP_PRECISION
:
1367 gndo
->ndo_tstamp_precision
= tstamp_precision_from_string(optarg
);
1368 if (gndo
->ndo_tstamp_precision
< 0)
1369 error("unsupported time stamp precision");
1373 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
1374 case OPTION_IMMEDIATE_MODE
:
1375 gndo
->ndo_immediate
= 1;
1385 #ifdef HAVE_PCAP_FINDALLDEVS
1387 show_devices_and_exit();
1392 case 0: /* Default */
1393 case 4: /* Default + Date*/
1394 thiszone
= gmt2local(0);
1397 case 1: /* No time stamp */
1398 case 2: /* Unix timeval style */
1399 case 3: /* Microseconds since previous packet */
1400 case 5: /* Microseconds since first packet */
1403 default: /* Not supported */
1404 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1408 if (fflag
!= 0 && (VFileName
!= NULL
|| RFileName
!= NULL
))
1409 error("-f can not be used with -V or -r");
1411 if (VFileName
!= NULL
&& RFileName
!= NULL
)
1412 error("-V and -r are mutually exclusive.");
1414 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
1416 * If we're printing dissected packets to the standard output
1417 * rather than saving raw packets to a file, and the standard
1418 * output is a terminal, use immediate mode, as the user's
1419 * probably expecting to see packets pop up immediately.
1421 if (WFileName
== NULL
&& isatty(1))
1422 gndo
->ndo_immediate
= 1;
1426 /* if run as root, prepare for chrooting */
1427 if (getuid() == 0 || geteuid() == 0) {
1428 /* future extensibility for cmd-line arguments */
1430 chroot_dir
= WITH_CHROOT
;
1435 /* if run as root, prepare for dropping root privileges */
1436 if (getuid() == 0 || geteuid() == 0) {
1437 /* Run with '-Z root' to restore old behaviour */
1439 username
= WITH_USER
;
1443 if (RFileName
!= NULL
|| VFileName
!= NULL
) {
1445 * If RFileName is non-null, it's the pathname of a
1446 * savefile to read. If VFileName is non-null, it's
1447 * the pathname of a file containing a list of pathnames
1448 * (one per line) of savefiles to read.
1450 * In either case, we're reading a savefile, not doing
1455 * We don't need network access, so relinquish any set-UID
1456 * or set-GID privileges we have (if any).
1458 * We do *not* want set-UID privileges when opening a
1459 * trace file, as that might let the user read other
1460 * people's trace files (especially if we're set-UID
1463 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1464 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1466 if (VFileName
!= NULL
) {
1467 if (VFileName
[0] == '-' && VFileName
[1] == '\0')
1470 VFile
= fopen(VFileName
, "r");
1473 error("Unable to open file: %s\n", strerror(errno
));
1475 ret
= get_next_file(VFile
, VFileLine
);
1477 error("Nothing in %s\n", VFileName
);
1478 RFileName
= VFileLine
;
1481 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
1482 pd
= pcap_open_offline_with_tstamp_precision(RFileName
,
1483 gndo
->ndo_tstamp_precision
, ebuf
);
1485 pd
= pcap_open_offline(RFileName
, ebuf
);
1490 #ifdef HAVE_CAPSICUM
1491 cap_rights_init(&rights
, CAP_READ
);
1492 if (cap_rights_limit(fileno(pcap_file(pd
)), &rights
) < 0 &&
1494 error("unable to limit pcap descriptor");
1497 dlt
= pcap_datalink(pd
);
1498 dlt_name
= pcap_datalink_val_to_name(dlt
);
1499 if (dlt_name
== NULL
) {
1500 fprintf(stderr
, "reading from file %s, link-type %u\n",
1504 "reading from file %s, link-type %s (%s)\n",
1505 RFileName
, dlt_name
,
1506 pcap_datalink_val_to_description(dlt
));
1510 * We're doing a live capture.
1512 if (device
== NULL
) {
1513 device
= pcap_lookupdev(ebuf
);
1519 * Print a message to the standard error on Windows.
1520 * XXX - why do it here, with a different message?
1522 if(strlen(device
) == 1) /* we assume that an ASCII string is always longer than 1 char */
1523 { /* a Unicode string has a \0 as second byte (so strlen() is 1) */
1524 fprintf(stderr
, "%s: listening on %ws\n", program_name
, device
);
1528 fprintf(stderr
, "%s: listening on %s\n", program_name
, device
);
1533 #ifdef HAVE_PCAP_CREATE
1534 pd
= pcap_create(device
, ebuf
);
1537 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1539 show_tstamp_types_and_exit(device
, pd
);
1541 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
1542 status
= pcap_set_tstamp_precision(pd
, gndo
->ndo_tstamp_precision
);
1544 error("%s: Can't set %ssecond time stamp precision: %s",
1546 tstamp_precision_to_string(gndo
->ndo_tstamp_precision
),
1547 pcap_statustostr(status
));
1550 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
1551 if (gndo
->ndo_immediate
) {
1552 status
= pcap_set_immediate_mode(pd
, 1);
1554 error("%s: Can't set immediate mode: %s",
1556 pcap_statustostr(status
));
1560 * Is this an interface that supports monitor mode?
1562 if (pcap_can_set_rfmon(pd
) == 1)
1563 supports_monitor_mode
= 1;
1565 supports_monitor_mode
= 0;
1566 status
= pcap_set_snaplen(pd
, snaplen
);
1568 error("%s: Can't set snapshot length: %s",
1569 device
, pcap_statustostr(status
));
1570 status
= pcap_set_promisc(pd
, !pflag
);
1572 error("%s: Can't set promiscuous mode: %s",
1573 device
, pcap_statustostr(status
));
1575 status
= pcap_set_rfmon(pd
, 1);
1577 error("%s: Can't set monitor mode: %s",
1578 device
, pcap_statustostr(status
));
1580 status
= pcap_set_timeout(pd
, 1000);
1582 error("%s: pcap_set_timeout failed: %s",
1583 device
, pcap_statustostr(status
));
1585 status
= pcap_set_buffer_size(pd
, Bflag
);
1587 error("%s: Can't set buffer size: %s",
1588 device
, pcap_statustostr(status
));
1590 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1592 status
= pcap_set_tstamp_type(pd
, jflag
);
1594 error("%s: Can't set time stamp type: %s",
1595 device
, pcap_statustostr(status
));
1598 status
= pcap_activate(pd
);
1601 * pcap_activate() failed.
1603 cp
= pcap_geterr(pd
);
1604 if (status
== PCAP_ERROR
)
1606 else if ((status
== PCAP_ERROR_NO_SUCH_DEVICE
||
1607 status
== PCAP_ERROR_PERM_DENIED
) &&
1609 error("%s: %s\n(%s)", device
,
1610 pcap_statustostr(status
), cp
);
1612 error("%s: %s", device
,
1613 pcap_statustostr(status
));
1614 } else if (status
> 0) {
1616 * pcap_activate() succeeded, but it's warning us
1617 * of a problem it had.
1619 cp
= pcap_geterr(pd
);
1620 if (status
== PCAP_WARNING
)
1622 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1624 warning("%s: %s\n(%s)", device
,
1625 pcap_statustostr(status
), cp
);
1627 warning("%s: %s", device
,
1628 pcap_statustostr(status
));
1630 #ifdef HAVE_PCAP_SETDIRECTION
1632 status
= pcap_setdirection(pd
, Qflag
);
1634 error("%s: pcap_setdirection() failed: %s",
1635 device
, pcap_geterr(pd
));
1637 #endif /* HAVE_PCAP_SETDIRECTION */
1640 pd
= pcap_open_live(device
, snaplen
, !pflag
, 1000, ebuf
);
1644 warning("%s", ebuf
);
1645 #endif /* HAVE_PCAP_CREATE */
1647 * Let user own process after socket has been opened.
1650 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1651 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1653 #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
1655 if(pcap_setbuff(pd
, Bflag
)==-1){
1656 error("%s", pcap_geterr(pd
));
1658 #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
1660 show_dlts_and_exit(device
, pd
);
1661 if (gndo
->ndo_dlt
>= 0) {
1662 #ifdef HAVE_PCAP_SET_DATALINK
1663 if (pcap_set_datalink(pd
, gndo
->ndo_dlt
) < 0)
1664 error("%s", pcap_geterr(pd
));
1667 * We don't actually support changing the
1668 * data link type, so we only let them
1669 * set it to what it already is.
1671 if (gndo
->ndo_dlt
!= pcap_datalink(pd
)) {
1672 error("%s is not one of the DLTs supported by this device\n",
1676 (void)fprintf(stderr
, "%s: data link type %s\n",
1677 program_name
, gndo
->ndo_dltname
);
1678 (void)fflush(stderr
);
1680 i
= pcap_snapshot(pd
);
1682 warning("snaplen raised from %d to %d", snaplen
, i
);
1686 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1687 warning("foreign (-f) flag used but: %s", ebuf
);
1693 cmdbuf
= read_infile(infile
);
1695 cmdbuf
= copy_argv(&argv
[optind
]);
1697 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1698 error("%s", pcap_geterr(pd
));
1700 bpf_dump(&fcode
, dflag
);
1705 init_addrtoname(gndo
, localnet
, netmask
);
1709 (void)setsignal(SIGPIPE
, cleanup
);
1710 (void)setsignal(SIGTERM
, cleanup
);
1711 (void)setsignal(SIGINT
, cleanup
);
1713 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1714 (void)setsignal(SIGCHLD
, child_cleanup
);
1716 /* Cooperate with nohup(1) */
1718 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1719 (void)setsignal(SIGHUP
, oldhandler
);
1724 * If a user name was specified with "-Z", attempt to switch to
1725 * that user's UID. This would probably be used with sudo,
1726 * to allow tcpdump to be run in a special restricted
1727 * account (if you just want to allow users to open capture
1728 * devices, and can't just give users that permission,
1729 * you'd make tcpdump set-UID or set-GID).
1731 * Tcpdump doesn't necessarily write only to one savefile;
1732 * the general only way to allow a -Z instance to write to
1733 * savefiles as the user under whose UID it's run, rather
1734 * than as the user specified with -Z, would thus be to switch
1735 * to the original user ID before opening a capture file and
1736 * then switch back to the -Z user ID after opening the savefile.
1737 * Switching to the -Z user ID only after opening the first
1738 * savefile doesn't handle the general case.
1741 if (getuid() == 0 || geteuid() == 0) {
1742 #ifdef HAVE_LIBCAP_NG
1743 /* Initialize capng */
1744 capng_clear(CAPNG_SELECT_BOTH
);
1748 CAPNG_PERMITTED
| CAPNG_EFFECTIVE
,
1757 CAPNG_PERMITTED
| CAPNG_EFFECTIVE
,
1761 capng_apply(CAPNG_SELECT_BOTH
);
1762 #endif /* HAVE_LIBCAP_NG */
1763 if (username
|| chroot_dir
)
1764 droproot(username
, chroot_dir
);
1769 if (pcap_setfilter(pd
, &fcode
) < 0)
1770 error("%s", pcap_geterr(pd
));
1771 #ifdef HAVE_CAPSICUM
1772 if (RFileName
== NULL
&& VFileName
== NULL
) {
1773 static const unsigned long cmds
[] = { BIOCGSTATS
};
1775 cap_rights_init(&rights
, CAP_IOCTL
, CAP_READ
);
1776 if (cap_rights_limit(pcap_fileno(pd
), &rights
) < 0 &&
1778 error("unable to limit pcap descriptor");
1780 if (cap_ioctls_limit(pcap_fileno(pd
), cmds
,
1781 sizeof(cmds
) / sizeof(cmds
[0])) < 0 && errno
!= ENOSYS
) {
1782 error("unable to limit ioctls on pcap descriptor");
1788 /* Do not exceed the default PATH_MAX for files. */
1789 dumpinfo
.CurrentFileName
= (char *)malloc(PATH_MAX
+ 1);
1791 if (dumpinfo
.CurrentFileName
== NULL
)
1792 error("malloc of dumpinfo.CurrentFileName");
1794 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1796 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1798 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1800 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1801 #ifdef HAVE_LIBCAP_NG
1802 /* Give up CAP_DAC_OVERRIDE capability.
1803 * Only allow it to be restored if the -C or -G flag have been
1804 * set since we may need to create more files later on.
1808 (Cflag
|| Gflag
? 0 : CAPNG_PERMITTED
)
1812 capng_apply(CAPNG_SELECT_BOTH
);
1813 #endif /* HAVE_LIBCAP_NG */
1815 error("%s", pcap_geterr(pd
));
1816 #ifdef HAVE_CAPSICUM
1817 cap_rights_init(&rights
, CAP_SEEK
, CAP_WRITE
);
1818 if (cap_rights_limit(fileno(pcap_dump_file(p
)), &rights
) < 0 &&
1820 error("unable to limit dump descriptor");
1823 if (Cflag
!= 0 || Gflag
!= 0) {
1824 #ifdef HAVE_CAPSICUM
1825 dumpinfo
.WFileName
= strdup(basename(WFileName
));
1826 dumpinfo
.dirfd
= open(dirname(WFileName
),
1827 O_DIRECTORY
| O_RDONLY
);
1828 if (dumpinfo
.dirfd
< 0) {
1829 error("unable to open directory %s",
1830 dirname(WFileName
));
1832 cap_rights_init(&rights
, CAP_CREATE
, CAP_FCNTL
,
1833 CAP_FTRUNCATE
, CAP_LOOKUP
, CAP_SEEK
, CAP_WRITE
);
1834 if (cap_rights_limit(dumpinfo
.dirfd
, &rights
) < 0 &&
1836 error("unable to limit directory rights");
1838 #else /* !HAVE_CAPSICUM */
1839 dumpinfo
.WFileName
= WFileName
;
1841 callback
= dump_packet_and_trunc
;
1844 pcap_userdata
= (u_char
*)&dumpinfo
;
1846 callback
= dump_packet
;
1847 pcap_userdata
= (u_char
*)p
;
1849 #ifdef HAVE_PCAP_DUMP_FLUSH
1854 type
= pcap_datalink(pd
);
1855 printinfo
= get_print_info(type
);
1856 callback
= print_packet
;
1857 pcap_userdata
= (u_char
*)&printinfo
;
1860 #ifdef SIGNAL_REQ_INFO
1862 * We can't get statistics when reading from a file rather
1863 * than capturing from a device.
1865 if (RFileName
== NULL
)
1866 (void)setsignal(SIGNAL_REQ_INFO
, requestinfo
);
1869 if (vflag
> 0 && WFileName
) {
1871 * When capturing to a file, "-v" means tcpdump should,
1872 * every 10 secodns, "v"erbosely report the number of
1875 #ifdef USE_WIN32_MM_TIMER
1876 /* call verbose_stats_dump() each 1000 +/-100msec */
1877 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1878 setvbuf(stderr
, NULL
, _IONBF
, 0);
1879 #elif defined(HAVE_ALARM)
1880 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1886 if (RFileName
== NULL
) {
1888 * Live capture (if -V was specified, we set RFileName
1889 * to a file from the -V file). Print a message to
1890 * the standard error on UN*X.
1892 if (!vflag
&& !WFileName
) {
1893 (void)fprintf(stderr
,
1894 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1897 (void)fprintf(stderr
, "%s: ", program_name
);
1898 dlt
= pcap_datalink(pd
);
1899 dlt_name
= pcap_datalink_val_to_name(dlt
);
1900 if (dlt_name
== NULL
) {
1901 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1902 device
, dlt
, snaplen
);
1904 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1906 pcap_datalink_val_to_description(dlt
), snaplen
);
1908 (void)fflush(stderr
);
1912 #ifdef HAVE_CAPSICUM
1913 cansandbox
= (nflag
&& VFileName
== NULL
&& zflag
== NULL
);
1914 if (cansandbox
&& cap_enter() < 0 && errno
!= ENOSYS
)
1915 error("unable to enter the capability mode");
1916 if (cap_sandboxed())
1917 fprintf(stderr
, "capability mode sandbox enabled\n");
1918 #endif /* HAVE_CAPSICUM */
1921 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1922 if (WFileName
== NULL
) {
1924 * We're printing packets. Flush the printed output,
1925 * so it doesn't get intermingled with error output.
1929 * We got interrupted, so perhaps we didn't
1930 * manage to finish a line we were printing.
1931 * Print an extra newline, just in case.
1935 (void)fflush(stdout
);
1939 * We got interrupted. If we are reading multiple
1940 * files (via -V) set these so that we stop.
1949 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
1950 program_name
, pcap_geterr(pd
));
1952 if (RFileName
== NULL
) {
1954 * We're doing a live capture. Report the capture
1960 if (VFileName
!= NULL
) {
1961 ret
= get_next_file(VFile
, VFileLine
);
1963 RFileName
= VFileLine
;
1964 pd
= pcap_open_offline(RFileName
, ebuf
);
1967 #ifdef HAVE_CAPSICUM
1968 cap_rights_init(&rights
, CAP_READ
);
1969 if (cap_rights_limit(fileno(pcap_file(pd
)),
1970 &rights
) < 0 && errno
!= ENOSYS
) {
1971 error("unable to limit pcap descriptor");
1974 new_dlt
= pcap_datalink(pd
);
1975 if (WFileName
&& new_dlt
!= dlt
)
1976 error("%s: new dlt does not match original", RFileName
);
1977 printinfo
= get_print_info(new_dlt
);
1978 dlt_name
= pcap_datalink_val_to_name(new_dlt
);
1979 if (dlt_name
== NULL
) {
1980 fprintf(stderr
, "reading from file %s, link-type %u\n",
1981 RFileName
, new_dlt
);
1984 "reading from file %s, link-type %s (%s)\n",
1985 RFileName
, dlt_name
,
1986 pcap_datalink_val_to_description(new_dlt
));
1988 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1989 error("%s", pcap_geterr(pd
));
1990 if (pcap_setfilter(pd
, &fcode
) < 0)
1991 error("%s", pcap_geterr(pd
));
1995 while (ret
!= NULL
);
1998 exit(status
== -1 ? 1 : 0);
2001 /* make a clean exit on interrupts */
2003 cleanup(int signo _U_
)
2005 #ifdef USE_WIN32_MM_TIMER
2007 timeKillEvent(timer_id
);
2009 #elif defined(HAVE_ALARM)
2013 #ifdef HAVE_PCAP_BREAKLOOP
2015 * We have "pcap_breakloop()"; use it, so that we do as little
2016 * as possible in the signal handler (it's probably not safe
2017 * to do anything with standard I/O streams in a signal handler -
2018 * the ANSI C standard doesn't say it is).
2023 * We don't have "pcap_breakloop()"; this isn't safe, but
2024 * it's the best we can do. Print the summary if we're
2025 * not reading from a savefile - i.e., if we're doing a
2026 * live capture - and exit.
2028 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
2030 * We got interrupted, so perhaps we didn't
2031 * manage to finish a line we were printing.
2032 * Print an extra newline, just in case.
2035 (void)fflush(stdout
);
2043 On windows, we do not use a fork, so we do not care less about
2044 waiting a child processes to die
2046 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
2048 child_cleanup(int signo _U_
)
2052 #endif /* HAVE_FORK && HAVE_VFORK */
2055 info(register int verbose
)
2057 struct pcap_stat stat
;
2060 * Older versions of libpcap didn't set ps_ifdrop on some
2061 * platforms; initialize it to 0 to handle that.
2064 if (pcap_stats(pd
, &stat
) < 0) {
2065 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
2071 fprintf(stderr
, "%s: ", program_name
);
2073 (void)fprintf(stderr
, "%u packet%s captured", packets_captured
,
2074 PLURAL_SUFFIX(packets_captured
));
2076 fputs(", ", stderr
);
2079 (void)fprintf(stderr
, "%u packet%s received by filter", stat
.ps_recv
,
2080 PLURAL_SUFFIX(stat
.ps_recv
));
2082 fputs(", ", stderr
);
2085 (void)fprintf(stderr
, "%u packet%s dropped by kernel", stat
.ps_drop
,
2086 PLURAL_SUFFIX(stat
.ps_drop
));
2087 if (stat
.ps_ifdrop
!= 0) {
2089 fputs(", ", stderr
);
2092 (void)fprintf(stderr
, "%u packet%s dropped by interface\n",
2093 stat
.ps_ifdrop
, PLURAL_SUFFIX(stat
.ps_ifdrop
));
2099 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
2101 compress_savefile(const char *filename
)
2110 * Set to lowest priority so that this doesn't disturb the capture
2113 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
2115 setpriority(PRIO_PROCESS
, 0, 19);
2117 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
2119 "compress_savefile:execlp(%s, %s): %s\n",
2129 #else /* HAVE_FORK && HAVE_VFORK */
2131 compress_savefile(const char *filename
)
2134 "compress_savefile failed. Functionality not implemented under your system\n");
2136 #endif /* HAVE_FORK && HAVE_VFORK */
2139 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
2141 struct dump_info
*dump_info
;
2142 #ifdef HAVE_CAPSICUM
2143 cap_rights_t rights
;
2150 dump_info
= (struct dump_info
*)user
;
2153 * XXX - this won't force the file to rotate on the specified time
2154 * boundary, but it will rotate on the first packet received after the
2155 * specified Gflag number of seconds. Note: if a Gflag time boundary
2156 * and a Cflag size boundary coincide, the time rotation will occur
2157 * first thereby cancelling the Cflag boundary (since the file should
2161 /* Check if it is time to rotate */
2164 /* Get the current time */
2165 if ((t
= time(NULL
)) == (time_t)-1) {
2166 error("dump_and_trunc_packet: can't get current_time: %s",
2167 pcap_strerror(errno
));
2171 /* If the time is greater than the specified window, rotate */
2172 if (t
- Gflag_time
>= Gflag
) {
2173 #ifdef HAVE_CAPSICUM
2178 /* Update the Gflag_time */
2180 /* Update Gflag_count */
2183 * Close the current file and open a new one.
2185 pcap_dump_close(dump_info
->p
);
2188 * Compress the file we just closed, if the user asked for it
2191 compress_savefile(dump_info
->CurrentFileName
);
2194 * Check to see if we've exceeded the Wflag (when
2197 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
2198 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
2203 if (dump_info
->CurrentFileName
!= NULL
)
2204 free(dump_info
->CurrentFileName
);
2205 /* Allocate space for max filename + \0. */
2206 dump_info
->CurrentFileName
= (char *)malloc(PATH_MAX
+ 1);
2207 if (dump_info
->CurrentFileName
== NULL
)
2208 error("dump_packet_and_trunc: malloc");
2210 * Gflag was set otherwise we wouldn't be here. Reset the count
2211 * so multiple files would end with 1,2,3 in the filename.
2212 * The counting is handled with the -C flow after this.
2217 * This is always the first file in the Cflag
2219 * We also don't need numbering if Cflag is not set.
2222 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
2225 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
2227 #ifdef HAVE_LIBCAP_NG
2228 capng_update(CAPNG_ADD
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2229 capng_apply(CAPNG_SELECT_BOTH
);
2230 #endif /* HAVE_LIBCAP_NG */
2231 #ifdef HAVE_CAPSICUM
2232 fd
= openat(dump_info
->dirfd
,
2233 dump_info
->CurrentFileName
,
2234 O_CREAT
| O_WRONLY
| O_TRUNC
, 0644);
2236 error("unable to open file %s",
2237 dump_info
->CurrentFileName
);
2239 fp
= fdopen(fd
, "w");
2241 error("unable to fdopen file %s",
2242 dump_info
->CurrentFileName
);
2244 dump_info
->p
= pcap_dump_fopen(dump_info
->pd
, fp
);
2245 #else /* !HAVE_CAPSICUM */
2246 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
2248 #ifdef HAVE_LIBCAP_NG
2249 capng_update(CAPNG_DROP
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2250 capng_apply(CAPNG_SELECT_BOTH
);
2251 #endif /* HAVE_LIBCAP_NG */
2252 if (dump_info
->p
== NULL
)
2253 error("%s", pcap_geterr(pd
));
2254 #ifdef HAVE_CAPSICUM
2255 cap_rights_init(&rights
, CAP_SEEK
, CAP_WRITE
);
2256 if (cap_rights_limit(fileno(pcap_dump_file(dump_info
->p
)),
2257 &rights
) < 0 && errno
!= ENOSYS
) {
2258 error("unable to limit dump descriptor");
2265 * XXX - this won't prevent capture files from getting
2266 * larger than Cflag - the last packet written to the
2267 * file could put it over Cflag.
2270 long size
= pcap_dump_ftell(dump_info
->p
);
2273 error("ftell fails on output file");
2275 #ifdef HAVE_CAPSICUM
2281 * Close the current file and open a new one.
2283 pcap_dump_close(dump_info
->p
);
2286 * Compress the file we just closed, if the user
2290 compress_savefile(dump_info
->CurrentFileName
);
2294 if (Cflag_count
>= Wflag
)
2297 if (dump_info
->CurrentFileName
!= NULL
)
2298 free(dump_info
->CurrentFileName
);
2299 dump_info
->CurrentFileName
= (char *)malloc(PATH_MAX
+ 1);
2300 if (dump_info
->CurrentFileName
== NULL
)
2301 error("dump_packet_and_trunc: malloc");
2302 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
2303 #ifdef HAVE_LIBCAP_NG
2304 capng_update(CAPNG_ADD
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2305 capng_apply(CAPNG_SELECT_BOTH
);
2306 #endif /* HAVE_LIBCAP_NG */
2307 #ifdef HAVE_CAPSICUM
2308 fd
= openat(dump_info
->dirfd
, dump_info
->CurrentFileName
,
2309 O_CREAT
| O_WRONLY
| O_TRUNC
, 0644);
2311 error("unable to open file %s",
2312 dump_info
->CurrentFileName
);
2314 fp
= fdopen(fd
, "w");
2316 error("unable to fdopen file %s",
2317 dump_info
->CurrentFileName
);
2319 dump_info
->p
= pcap_dump_fopen(dump_info
->pd
, fp
);
2320 #else /* !HAVE_CAPSICUM */
2321 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
2323 #ifdef HAVE_LIBCAP_NG
2324 capng_update(CAPNG_DROP
, CAPNG_EFFECTIVE
, CAP_DAC_OVERRIDE
);
2325 capng_apply(CAPNG_SELECT_BOTH
);
2326 #endif /* HAVE_LIBCAP_NG */
2327 if (dump_info
->p
== NULL
)
2328 error("%s", pcap_geterr(pd
));
2329 #ifdef HAVE_CAPSICUM
2330 cap_rights_init(&rights
, CAP_SEEK
, CAP_WRITE
);
2331 if (cap_rights_limit(fileno(pcap_dump_file(dump_info
->p
)),
2332 &rights
) < 0 && errno
!= ENOSYS
) {
2333 error("unable to limit dump descriptor");
2339 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
2340 #ifdef HAVE_PCAP_DUMP_FLUSH
2342 pcap_dump_flush(dump_info
->p
);
2351 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
2357 pcap_dump(user
, h
, sp
);
2358 #ifdef HAVE_PCAP_DUMP_FLUSH
2360 pcap_dump_flush((pcap_dumper_t
*)user
);
2369 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
2371 struct print_info
*print_info
;
2373 netdissect_options
*ndo
;
2379 print_info
= (struct print_info
*)user
;
2380 ndo
= print_info
->ndo
;
2382 if(ndo
->ndo_packet_number
)
2383 ND_PRINT((ndo
, "%5u ", packets_captured
));
2385 ts_print(ndo
, &h
->ts
);
2388 * Some printers want to check that they're not walking off the
2389 * end of the packet.
2390 * Rather than pass it all the way down, we set this member
2391 * of the netdissect_options structure.
2393 ndo
->ndo_snapend
= sp
+ h
->caplen
;
2395 if(print_info
->ndo_type
) {
2396 hdrlen
= (*print_info
->p
.ndo_printer
)(print_info
->ndo
, h
, sp
);
2398 hdrlen
= (*print_info
->p
.printer
)(h
, sp
);
2402 * Restore the original snapend, as a printer might have
2405 ndo
->ndo_snapend
= sp
+ h
->caplen
;
2406 if (ndo
->ndo_Xflag
) {
2408 * Print the raw packet data in hex and ASCII.
2410 if (ndo
->ndo_Xflag
> 1) {
2412 * Include the link-layer header.
2414 hex_and_ascii_print(ndo
, "\n\t", sp
, h
->caplen
);
2417 * Don't include the link-layer header - and if
2418 * we have nothing past the link-layer header,
2421 if (h
->caplen
> hdrlen
)
2422 hex_and_ascii_print(ndo
, "\n\t", sp
+ hdrlen
,
2423 h
->caplen
- hdrlen
);
2425 } else if (ndo
->ndo_xflag
) {
2427 * Print the raw packet data in hex.
2429 if (ndo
->ndo_xflag
> 1) {
2431 * Include the link-layer header.
2433 hex_print(ndo
, "\n\t", sp
, h
->caplen
);
2436 * Don't include the link-layer header - and if
2437 * we have nothing past the link-layer header,
2440 if (h
->caplen
> hdrlen
)
2441 hex_print(ndo
, "\n\t", sp
+ hdrlen
,
2442 h
->caplen
- hdrlen
);
2444 } else if (ndo
->ndo_Aflag
) {
2446 * Print the raw packet data in ASCII.
2448 if (ndo
->ndo_Aflag
> 1) {
2450 * Include the link-layer header.
2452 ascii_print(ndo
, sp
, h
->caplen
);
2455 * Don't include the link-layer header - and if
2456 * we have nothing past the link-layer header,
2459 if (h
->caplen
> hdrlen
)
2460 ascii_print(ndo
, sp
+ hdrlen
, h
->caplen
- hdrlen
);
2473 * XXX - there should really be libpcap calls to get the version
2474 * number as a string (the string would be generated from #defines
2475 * at run time, so that it's not generated from string constants
2476 * in the library, as, on many UNIX systems, those constants would
2477 * be statically linked into the application executable image, and
2478 * would thus reflect the version of libpcap on the system on
2479 * which the application was *linked*, not the system on which it's
2482 * That routine should be documented, unlike the "version[]"
2483 * string, so that UNIX vendors providing their own libpcaps
2484 * don't omit it (as a couple of vendors have...).
2486 * Packet.dll should perhaps also export a routine to return the
2487 * version number of the Packet.dll code, to supply the
2488 * "Wpcap_version" information on Windows.
2490 char WDversion
[]="current-git.tcpdump.org";
2491 #if !defined(HAVE_GENERATED_VERSION)
2492 char version
[]="current-git.tcpdump.org";
2494 char pcap_version
[]="current-git.tcpdump.org";
2495 char Wpcap_version
[]="3.1";
2499 * By default, print the specified data out in hex and ASCII.
2502 ndo_default_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
2504 hex_and_ascii_print(ndo
, "\n\t", bp
, length
); /* pass on lf and indentation string */
2508 default_print(const u_char
*bp
, u_int length
)
2510 ndo_default_print(gndo
, bp
, length
);
2513 #ifdef SIGNAL_REQ_INFO
2514 RETSIGTYPE
requestinfo(int signo _U_
)
2524 * Called once each second in verbose mode while dumping to file
2526 #ifdef USE_WIN32_MM_TIMER
2527 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
2528 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
2530 struct pcap_stat stat
;
2532 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
2533 fprintf(stderr
, "Got %u\r", packets_captured
);
2535 #elif defined(HAVE_ALARM)
2536 static void verbose_stats_dump(int sig _U_
)
2538 struct pcap_stat stat
;
2540 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
2541 fprintf(stderr
, "Got %u\r", packets_captured
);
2546 USES_APPLE_DEPRECATED_API
2550 extern char version
[];
2551 #ifndef HAVE_PCAP_LIB_VERSION
2552 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
2553 extern char pcap_version
[];
2554 #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
2555 static char pcap_version
[] = "unknown";
2556 #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
2557 #endif /* HAVE_PCAP_LIB_VERSION */
2559 #ifdef HAVE_PCAP_LIB_VERSION
2561 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
2563 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
2565 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
2566 #else /* HAVE_PCAP_LIB_VERSION */
2568 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
2569 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
2571 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
2572 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
2574 #endif /* HAVE_PCAP_LIB_VERSION */
2576 #if defined(HAVE_LIBCRYPTO) && defined(SSLEAY_VERSION)
2577 (void)fprintf (stderr
, "%s\n", SSLeay_version(SSLEAY_VERSION
));
2581 (void)fprintf (stderr
, "SMI-library: %s\n", smi_version_string
);
2590 (void)fprintf(stderr
,
2591 "Usage: %s [-aAbd" D_FLAG
"efhH" I_FLAG J_FLAG
"KlLnNOpqRStu" U_FLAG
"vxX#]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
2592 (void)fprintf(stderr
,
2593 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
2594 (void)fprintf(stderr
,
2595 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ] [ --number ]\n");
2596 #ifdef HAVE_PCAP_SETDIRECTION
2597 (void)fprintf(stderr
,
2598 "\t\t[ -Q in|out|inout ]\n");
2600 (void)fprintf(stderr
,
2601 "\t\t[ -r file ] [ -s snaplen ] ");
2602 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
2603 (void)fprintf(stderr
, "[ --time-stamp-precision precision ]\n");
2604 (void)fprintf(stderr
,
2607 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
2608 (void)fprintf(stderr
, "[ --immediate-mode ] ");
2610 (void)fprintf(stderr
, "[ -T type ] [ --version ] [ -V file ]\n");
2611 (void)fprintf(stderr
,
2612 "\t\t[ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
2613 (void)fprintf(stderr
,
2614 "\t\t[ -Z user ] [ expression ]\n");
2621 ndo_error(netdissect_options
*ndo _U_
, const char *fmt
, ...)
2625 (void)fprintf(stderr
, "%s: ", program_name
);
2627 (void)vfprintf(stderr
, fmt
, ap
);
2631 if (fmt
[-1] != '\n')
2632 (void)fputc('\n', stderr
);
2640 ndo_warning(netdissect_options
*ndo _U_
, const char *fmt
, ...)
2644 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
2646 (void)vfprintf(stderr
, fmt
, ap
);
2650 if (fmt
[-1] != '\n')
2651 (void)fputc('\n', stderr
);
2656 * c-style: whitesmith