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";
32 static const char rcsid
[] _U_
=
33 "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.283 2008-09-25 21:45:50 guy Exp $ (LBL)";
37 * tcpdump - monitor tcp/ip traffic on an ethernet.
39 * First written in 1987 by Van Jacobson, Lawrence Berkeley Laboratory.
40 * Mercilessly hacked and occasionally improved since then via the
41 * combined efforts of Van, Steve McCanne and Craig Leres of LBL.
48 #include <tcpdump-stdinc.h>
53 extern int strcasecmp (const char *__s1
, const char *__s2
);
71 #include <sys/resource.h>
78 #include "netdissect.h"
79 #include "interface.h"
80 #include "addrtoname.h"
82 #include "setsignal.h"
83 #include "gmt2local.h"
84 #include "pcap-missing.h"
91 #define SIGNAL_REQ_INFO SIGINFO
93 #define SIGNAL_REQ_INFO SIGUSR1
96 netdissect_options Gndo
;
97 netdissect_options
*gndo
= &Gndo
;
99 static int dflag
; /* print filter code */
100 static int Lflag
; /* list available data link types and exit */
101 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
102 static int Jflag
; /* list available time stamp types */
104 static char *zflag
= NULL
; /* compress each savefile using a specified command (like gzip or bzip2) */
106 static int infodelay
;
107 static int infoprint
;
111 int32_t thiszone
; /* seconds offset from gmt to local time */
114 static RETSIGTYPE
cleanup(int);
115 static RETSIGTYPE
child_cleanup(int);
116 static void usage(void) __attribute__((noreturn
));
117 static void show_dlts_and_exit(const char *device
, pcap_t
*pd
) __attribute__((noreturn
));
119 static void print_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
120 static void ndo_default_print(netdissect_options
*, const u_char
*, u_int
);
121 static void dump_packet_and_trunc(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
122 static void dump_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
123 static void droproot(const char *, const char *);
124 static void ndo_error(netdissect_options
*ndo
, const char *fmt
, ...)
125 __attribute__ ((noreturn
, format (printf
, 2, 3)));
126 static void ndo_warning(netdissect_options
*ndo
, const char *fmt
, ...);
128 #ifdef SIGNAL_REQ_INFO
129 RETSIGTYPE
requestinfo(int);
132 #if defined(USE_WIN32_MM_TIMER)
133 #include <MMsystem.h>
134 static UINT timer_id
;
135 static void CALLBACK
verbose_stats_dump(UINT
, UINT
, DWORD_PTR
, DWORD_PTR
, DWORD_PTR
);
136 #elif defined(HAVE_ALARM)
137 static void verbose_stats_dump(int sig
);
140 static void info(int);
141 static u_int packets_captured
;
155 static struct printer printers
[] = {
156 { arcnet_if_print
, DLT_ARCNET
},
157 #ifdef DLT_ARCNET_LINUX
158 { arcnet_linux_if_print
, DLT_ARCNET_LINUX
},
160 { token_if_print
, DLT_IEEE802
},
162 { lane_if_print
, DLT_LANE8023
},
165 { cip_if_print
, DLT_CIP
},
168 { cip_if_print
, DLT_ATM_CLIP
},
170 { sl_if_print
, DLT_SLIP
},
171 #ifdef DLT_SLIP_BSDOS
172 { sl_bsdos_if_print
, DLT_SLIP_BSDOS
},
174 { ppp_if_print
, DLT_PPP
},
175 #ifdef DLT_PPP_WITHDIRECTION
176 { ppp_if_print
, DLT_PPP_WITHDIRECTION
},
179 { ppp_bsdos_if_print
, DLT_PPP_BSDOS
},
181 { fddi_if_print
, DLT_FDDI
},
182 { null_if_print
, DLT_NULL
},
184 { null_if_print
, DLT_LOOP
},
186 { raw_if_print
, DLT_RAW
},
187 { atm_if_print
, DLT_ATM_RFC1483
},
189 { chdlc_if_print
, DLT_C_HDLC
},
192 { chdlc_if_print
, DLT_HDLC
},
194 #ifdef DLT_PPP_SERIAL
195 { ppp_hdlc_if_print
, DLT_PPP_SERIAL
},
198 { pppoe_if_print
, DLT_PPP_ETHER
},
201 { sll_if_print
, DLT_LINUX_SLL
},
203 #ifdef DLT_IEEE802_11
204 { ieee802_11_if_print
, DLT_IEEE802_11
},
207 { ltalk_if_print
, DLT_LTALK
},
209 #if defined(DLT_PFLOG) && defined(HAVE_NET_PFVAR_H)
210 { pflog_if_print
, DLT_PFLOG
},
213 { fr_if_print
, DLT_FR
},
216 { fr_if_print
, DLT_FRELAY
},
219 { sunatm_if_print
, DLT_SUNATM
},
221 #ifdef DLT_IP_OVER_FC
222 { ipfc_if_print
, DLT_IP_OVER_FC
},
224 #ifdef DLT_PRISM_HEADER
225 { prism_if_print
, DLT_PRISM_HEADER
},
227 #ifdef DLT_IEEE802_11_RADIO
228 { ieee802_11_radio_if_print
, DLT_IEEE802_11_RADIO
},
231 { enc_if_print
, DLT_ENC
},
233 #ifdef DLT_SYMANTEC_FIREWALL
234 { symantec_if_print
, DLT_SYMANTEC_FIREWALL
},
236 #ifdef DLT_APPLE_IP_OVER_IEEE1394
237 { ap1394_if_print
, DLT_APPLE_IP_OVER_IEEE1394
},
239 #ifdef DLT_IEEE802_11_RADIO_AVS
240 { ieee802_11_radio_avs_if_print
, DLT_IEEE802_11_RADIO_AVS
},
242 #ifdef DLT_JUNIPER_ATM1
243 { juniper_atm1_print
, DLT_JUNIPER_ATM1
},
245 #ifdef DLT_JUNIPER_ATM2
246 { juniper_atm2_print
, DLT_JUNIPER_ATM2
},
248 #ifdef DLT_JUNIPER_MFR
249 { juniper_mfr_print
, DLT_JUNIPER_MFR
},
251 #ifdef DLT_JUNIPER_MLFR
252 { juniper_mlfr_print
, DLT_JUNIPER_MLFR
},
254 #ifdef DLT_JUNIPER_MLPPP
255 { juniper_mlppp_print
, DLT_JUNIPER_MLPPP
},
257 #ifdef DLT_JUNIPER_PPPOE
258 { juniper_pppoe_print
, DLT_JUNIPER_PPPOE
},
260 #ifdef DLT_JUNIPER_PPPOE_ATM
261 { juniper_pppoe_atm_print
, DLT_JUNIPER_PPPOE_ATM
},
263 #ifdef DLT_JUNIPER_GGSN
264 { juniper_ggsn_print
, DLT_JUNIPER_GGSN
},
266 #ifdef DLT_JUNIPER_ES
267 { juniper_es_print
, DLT_JUNIPER_ES
},
269 #ifdef DLT_JUNIPER_MONITOR
270 { juniper_monitor_print
, DLT_JUNIPER_MONITOR
},
272 #ifdef DLT_JUNIPER_SERVICES
273 { juniper_services_print
, DLT_JUNIPER_SERVICES
},
275 #ifdef DLT_JUNIPER_ETHER
276 { juniper_ether_print
, DLT_JUNIPER_ETHER
},
278 #ifdef DLT_JUNIPER_PPP
279 { juniper_ppp_print
, DLT_JUNIPER_PPP
},
281 #ifdef DLT_JUNIPER_FRELAY
282 { juniper_frelay_print
, DLT_JUNIPER_FRELAY
},
284 #ifdef DLT_JUNIPER_CHDLC
285 { juniper_chdlc_print
, DLT_JUNIPER_CHDLC
},
288 { mfr_if_print
, DLT_MFR
},
290 #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
291 { bt_if_print
, DLT_BLUETOOTH_HCI_H4_WITH_PHDR
},
293 #ifdef HAVE_PCAP_USB_H
295 { usb_linux_48_byte_print
, DLT_USB_LINUX
},
296 #endif /* DLT_USB_LINUX */
297 #ifdef DLT_USB_LINUX_MMAPPED
298 { usb_linux_64_byte_print
, DLT_USB_LINUX_MMAPPED
},
299 #endif /* DLT_USB_LINUX_MMAPPED */
300 #endif /* HAVE_PCAP_USB_H */
302 { raw_if_print
, DLT_IPV4
},
305 { raw_if_print
, DLT_IPV6
},
310 static struct ndo_printer ndo_printers
[] = {
311 { ether_if_print
, DLT_EN10MB
},
313 { ipnet_if_print
, DLT_IPNET
},
315 #ifdef DLT_IEEE802_15_4
316 { ieee802_15_4_if_print
, DLT_IEEE802_15_4
},
318 #ifdef DLT_IEEE802_15_4_NOFCS
319 { ieee802_15_4_if_print
, DLT_IEEE802_15_4_NOFCS
},
322 { ppi_if_print
, DLT_PPI
},
324 #ifdef DLT_NETANALYZER
325 { netanalyzer_if_print
, DLT_NETANALYZER
},
327 #ifdef DLT_NETANALYZER_TRANSPARENT
328 { netanalyzer_transparent_if_print
, DLT_NETANALYZER_TRANSPARENT
},
334 lookup_printer(int type
)
338 for (p
= printers
; p
->f
; ++p
)
347 lookup_ndo_printer(int type
)
349 struct ndo_printer
*p
;
351 for (p
= ndo_printers
; p
->f
; ++p
)
361 static int supports_monitor_mode
;
368 netdissect_options
*ndo
;
371 if_ndo_printer ndo_printer
;
378 char *CurrentFileName
;
383 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
385 show_tstamp_types_and_exit(const char *device
, pcap_t
*pd
)
388 int *tstamp_types
= 0;
389 const char *tstamp_type_name
;
392 n_tstamp_types
= pcap_list_tstamp_types(pd
, &tstamp_types
);
393 if (n_tstamp_types
< 0)
394 error("%s", pcap_geterr(pd
));
396 if (n_tstamp_types
== 0) {
397 fprintf(stderr
, "Time stamp type cannot be set for %s\n",
401 fprintf(stderr
, "Time stamp types for %s (use option -j to set):\n",
403 for (i
= 0; i
< n_tstamp_types
; i
++) {
404 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
405 if (tstamp_type_name
!= NULL
) {
406 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
407 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
409 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
412 pcap_free_tstamp_types(tstamp_types
);
418 show_dlts_and_exit(const char *device
, pcap_t
*pd
)
422 const char *dlt_name
;
424 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
426 error("%s", pcap_geterr(pd
));
427 else if (n_dlts
== 0 || !dlts
)
428 error("No data link types.");
431 * If the interface is known to support monitor mode, indicate
432 * whether these are the data link types available when not in
433 * monitor mode, if -I wasn't specified, or when in monitor mode,
434 * when -I was specified (the link-layer types available in
435 * monitor mode might be different from the ones available when
436 * not in monitor mode).
438 if (supports_monitor_mode
)
439 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
441 Iflag
? "when in monitor mode" : "when not in monitor mode");
443 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
446 while (--n_dlts
>= 0) {
447 dlt_name
= pcap_datalink_val_to_name(dlts
[n_dlts
]);
448 if (dlt_name
!= NULL
) {
449 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
450 pcap_datalink_val_to_description(dlts
[n_dlts
]));
453 * OK, does tcpdump handle that type?
455 if (lookup_printer(dlts
[n_dlts
]) == NULL
456 && lookup_ndo_printer(dlts
[n_dlts
]) == NULL
)
457 (void) fprintf(stderr
, " (printing not supported)");
458 fprintf(stderr
, "\n");
460 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
464 pcap_free_datalinks(dlts
);
469 * Set up flags that might or might not be supported depending on the
470 * version of libpcap we're using.
472 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
474 #define B_FLAG_USAGE " [ -B size ]"
475 #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
478 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
480 #ifdef HAVE_PCAP_CREATE
482 #else /* HAVE_PCAP_CREATE */
484 #endif /* HAVE_PCAP_CREATE */
486 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
488 #define j_FLAG_USAGE " [ -j tstamptype ]"
490 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
494 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
496 #ifdef HAVE_PCAP_FINDALLDEVS
497 #ifndef HAVE_PCAP_IF_T
498 #undef HAVE_PCAP_FINDALLDEVS
502 #ifdef HAVE_PCAP_FINDALLDEVS
508 #ifdef HAVE_PCAP_DUMP_FLUSH
515 /* Drop root privileges and chroot if necessary */
517 droproot(const char *username
, const char *chroot_dir
)
519 struct passwd
*pw
= NULL
;
521 if (chroot_dir
&& !username
) {
522 fprintf(stderr
, "tcpdump: Chroot without dropping root is insecure\n");
526 pw
= getpwnam(username
);
529 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
530 fprintf(stderr
, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
531 chroot_dir
, pcap_strerror(errno
));
535 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
536 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
537 fprintf(stderr
, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
539 (unsigned long)pw
->pw_uid
,
540 (unsigned long)pw
->pw_gid
,
541 pcap_strerror(errno
));
546 fprintf(stderr
, "tcpdump: Couldn't find user '%.32s'\n",
569 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
571 char *filename
= malloc(NAME_MAX
+ 1);
573 /* Process with strftime if Gflag is set. */
577 /* Convert Gflag_time to a usable format */
578 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
579 error("MakeTimedFilename: localtime");
582 /* There's no good way to detect an error in strftime since a return
583 * value of 0 isn't necessarily failure.
585 strftime(filename
, NAME_MAX
, orig_name
, local_tm
);
587 strncpy(filename
, orig_name
, NAME_MAX
);
590 if (cnt
== 0 && max_chars
== 0)
591 strncpy(buffer
, filename
, NAME_MAX
+ 1);
593 if (snprintf(buffer
, NAME_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > NAME_MAX
)
594 /* Report an error if the filename is too large */
595 error("too many output files or filename is too long (> %d)", NAME_MAX
);
599 static int tcpdump_printf(netdissect_options
*ndo _U_
,
600 const char *fmt
, ...)
607 ret
=vfprintf(stdout
, fmt
, args
);
614 main(int argc
, char **argv
)
616 register int cnt
, op
, i
;
617 bpf_u_int32 localnet
, netmask
;
618 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *WFileName
;
619 pcap_handler callback
;
621 struct bpf_program fcode
;
623 RETSIGTYPE (*oldhandler
)(int);
625 struct print_info printinfo
;
626 struct dump_info dumpinfo
;
627 u_char
*pcap_userdata
;
628 char ebuf
[PCAP_ERRBUF_SIZE
];
629 char *username
= NULL
;
630 char *chroot_dir
= NULL
;
631 #ifdef HAVE_PCAP_FINDALLDEVS
632 pcap_if_t
*devpointer
;
637 if(wsockinit() != 0) return 1;
640 jflag
=-1; /* not set */
644 gndo
->ndo_default_print
=ndo_default_print
;
645 gndo
->ndo_printf
=tcpdump_printf
;
646 gndo
->ndo_error
=ndo_error
;
647 gndo
->ndo_warning
=ndo_warning
;
648 gndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
655 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
656 program_name
= cp
+ 1;
658 program_name
= argv
[0];
660 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
668 (op
= getopt(argc
, argv
, "aAb" B_FLAG
"c:C:d" D_FLAG
"eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG
"KlLm:M:nNOpqr:Rs:StT:u" U_FLAG
"vw:W:xXy:Yz:Z:")) != -1)
672 /* compatibility for old -a */
683 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
685 Bflag
= atoi(optarg
)*1024;
687 error("invalid packet buffer size %s", optarg
);
689 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
694 error("invalid packet count %s", optarg
);
698 Cflag
= atoi(optarg
) * 1000000;
700 error("invalid file size %s", optarg
);
707 #ifdef HAVE_PCAP_FINDALLDEVS
709 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
712 for (i
= 0; devpointer
!= 0; i
++) {
713 printf("%d.%s", i
+1, devpointer
->name
);
714 if (devpointer
->description
!= NULL
)
715 printf(" (%s)", devpointer
->description
);
717 devpointer
= devpointer
->next
;
721 #endif /* HAVE_PCAP_FINDALLDEVS */
732 #ifndef HAVE_LIBCRYPTO
733 warning("crypto code not compiled in");
735 gndo
->ndo_espsecret
= optarg
;
747 Gflag
= atoi(optarg
);
749 error("invalid number of seconds %s", optarg
);
751 /* We will create one file initially. */
754 /* Grab the current time for rotation use. */
755 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
756 error("main: can't get current time: %s",
757 pcap_strerror(errno
));
770 if (optarg
[0] == '0' && optarg
[1] == 0)
771 error("Invalid adapter index");
773 #ifdef HAVE_PCAP_FINDALLDEVS
775 * If the argument is a number, treat it as
776 * an index into the list of adapters, as
777 * printed by "tcpdump -D".
779 * This should be OK on UNIX systems, as interfaces
780 * shouldn't have names that begin with digits.
781 * It can be useful on Windows, where more than
782 * one interface can have the same name.
784 if ((devnum
= atoi(optarg
)) != 0) {
786 error("Invalid adapter index");
788 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
792 * Look for the devnum-th entry
793 * in the list of devices
797 i
< devnum
-1 && devpointer
!= NULL
;
798 i
++, devpointer
= devpointer
->next
)
800 if (devpointer
== NULL
)
801 error("Invalid adapter index");
803 device
= devpointer
->name
;
806 #endif /* HAVE_PCAP_FINDALLDEVS */
810 #ifdef HAVE_PCAP_CREATE
814 #endif /* HAVE_PCAP_CREATE */
816 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
818 jflag
= pcap_tstamp_type_name_to_val(optarg
);
820 error("invalid time stamp type %s", optarg
);
831 * _IOLBF is the same as _IOFBF in Microsoft's C
832 * libraries; the only alternative they offer
835 * XXX - this should really be checking for MSVC++,
836 * not WIN32, if, for example, MinGW has its own
837 * C library that is more UNIX-compatible.
839 setvbuf(stdout
, NULL
, _IONBF
, 0);
841 #ifdef HAVE_SETLINEBUF
844 setvbuf(stdout
, NULL
, _IOLBF
, 0);
855 if (smiLoadModule(optarg
) == 0) {
856 error("could not load MIB module %s", optarg
);
860 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
861 program_name
, optarg
);
862 (void)fprintf(stderr
, "(no libsmi support)\n");
867 /* TCP-MD5 shared secret */
868 #ifndef HAVE_LIBCRYPTO
869 warning("crypto code not compiled in");
892 ++suppress_default_print
;
906 snaplen
= strtol(optarg
, &end
, 0);
907 if (optarg
== end
|| *end
!= '\0'
908 || snaplen
< 0 || snaplen
> MAXIMUM_SNAPLEN
)
909 error("invalid snaplen %s", optarg
);
910 else if (snaplen
== 0)
911 snaplen
= MAXIMUM_SNAPLEN
;
924 if (strcasecmp(optarg
, "vat") == 0)
926 else if (strcasecmp(optarg
, "wb") == 0)
928 else if (strcasecmp(optarg
, "rpc") == 0)
930 else if (strcasecmp(optarg
, "rtp") == 0)
932 else if (strcasecmp(optarg
, "rtcp") == 0)
933 packettype
= PT_RTCP
;
934 else if (strcasecmp(optarg
, "snmp") == 0)
935 packettype
= PT_SNMP
;
936 else if (strcasecmp(optarg
, "cnfp") == 0)
937 packettype
= PT_CNFP
;
938 else if (strcasecmp(optarg
, "tftp") == 0)
939 packettype
= PT_TFTP
;
940 else if (strcasecmp(optarg
, "aodv") == 0)
941 packettype
= PT_AODV
;
942 else if (strcasecmp(optarg
, "carp") == 0)
943 packettype
= PT_CARP
;
945 error("unknown packet type `%s'", optarg
);
952 #ifdef HAVE_PCAP_DUMP_FLUSH
967 Wflag
= atoi(optarg
);
969 error("invalid number of output files %s", optarg
);
970 WflagChars
= getWflagChars(Wflag
);
975 ++suppress_default_print
;
980 ++suppress_default_print
;
984 gndo
->ndo_dltname
= optarg
;
986 pcap_datalink_name_to_val(gndo
->ndo_dltname
);
987 if (gndo
->ndo_dlt
< 0)
988 error("invalid data link type %s", gndo
->ndo_dltname
);
991 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
994 /* Undocumented flag */
995 #ifdef HAVE_PCAP_DEBUG
996 extern int pcap_debug
;
1007 zflag
= strdup(optarg
);
1016 username
= strdup(optarg
);
1031 case 0: /* Default */
1032 case 4: /* Default + Date*/
1033 thiszone
= gmt2local(0);
1036 case 1: /* No time stamp */
1037 case 2: /* Unix timeval style */
1038 case 3: /* Microseconds since previous packet */
1039 case 5: /* Microseconds since first packet */
1042 default: /* Not supported */
1043 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1048 /* if run as root, prepare for chrooting */
1049 if (getuid() == 0 || geteuid() == 0) {
1050 /* future extensibility for cmd-line arguments */
1052 chroot_dir
= WITH_CHROOT
;
1057 /* if run as root, prepare for dropping root privileges */
1058 if (getuid() == 0 || geteuid() == 0) {
1059 /* Run with '-Z root' to restore old behaviour */
1061 username
= WITH_USER
;
1065 if (RFileName
!= NULL
) {
1067 const char *dlt_name
;
1071 * We don't need network access, so relinquish any set-UID
1072 * or set-GID privileges we have (if any).
1074 * We do *not* want set-UID privileges when opening a
1075 * trace file, as that might let the user read other
1076 * people's trace files (especially if we're set-UID
1079 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1080 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1082 pd
= pcap_open_offline(RFileName
, ebuf
);
1085 dlt
= pcap_datalink(pd
);
1086 dlt_name
= pcap_datalink_val_to_name(dlt
);
1087 if (dlt_name
== NULL
) {
1088 fprintf(stderr
, "reading from file %s, link-type %u\n",
1092 "reading from file %s, link-type %s (%s)\n",
1093 RFileName
, dlt_name
,
1094 pcap_datalink_val_to_description(dlt
));
1099 error("-f and -r options are incompatible");
1101 if (device
== NULL
) {
1102 device
= pcap_lookupdev(ebuf
);
1107 if(strlen(device
) == 1) //we assume that an ASCII string is always longer than 1 char
1108 { //a Unicode string has a \0 as second byte (so strlen() is 1)
1109 fprintf(stderr
, "%s: listening on %ws\n", program_name
, device
);
1113 fprintf(stderr
, "%s: listening on %s\n", program_name
, device
);
1118 #ifdef HAVE_PCAP_CREATE
1119 pd
= pcap_create(device
, ebuf
);
1122 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1124 show_tstamp_types_and_exit(device
, pd
);
1127 * Is this an interface that supports monitor mode?
1129 if (pcap_can_set_rfmon(pd
) == 1)
1130 supports_monitor_mode
= 1;
1132 supports_monitor_mode
= 0;
1133 status
= pcap_set_snaplen(pd
, snaplen
);
1135 error("%s: Can't set snapshot length: %s",
1136 device
, pcap_statustostr(status
));
1137 status
= pcap_set_promisc(pd
, !pflag
);
1139 error("%s: Can't set promiscuous mode: %s",
1140 device
, pcap_statustostr(status
));
1142 status
= pcap_set_rfmon(pd
, 1);
1144 error("%s: Can't set monitor mode: %s",
1145 device
, pcap_statustostr(status
));
1147 status
= pcap_set_timeout(pd
, 1000);
1149 error("%s: pcap_set_timeout failed: %s",
1150 device
, pcap_statustostr(status
));
1152 status
= pcap_set_buffer_size(pd
, Bflag
);
1154 error("%s: Can't set buffer size: %s",
1155 device
, pcap_statustostr(status
));
1157 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1159 status
= pcap_set_tstamp_type(pd
, jflag
);
1161 error("%s: Can't set time stamp type: %s",
1162 device
, pcap_statustostr(status
));
1165 status
= pcap_activate(pd
);
1168 * pcap_activate() failed.
1170 cp
= pcap_geterr(pd
);
1171 if (status
== PCAP_ERROR
)
1173 else if ((status
== PCAP_ERROR_NO_SUCH_DEVICE
||
1174 status
== PCAP_ERROR_PERM_DENIED
) &&
1176 error("%s: %s\n(%s)", device
,
1177 pcap_statustostr(status
), cp
);
1179 error("%s: %s", device
,
1180 pcap_statustostr(status
));
1181 } else if (status
> 0) {
1183 * pcap_activate() succeeded, but it's warning us
1184 * of a problem it had.
1186 cp
= pcap_geterr(pd
);
1187 if (status
== PCAP_WARNING
)
1189 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1191 warning("%s: %s\n(%s)", device
,
1192 pcap_statustostr(status
), cp
);
1194 warning("%s: %s", device
,
1195 pcap_statustostr(status
));
1199 pd
= pcap_open_live(device
, snaplen
, !pflag
, 1000, ebuf
);
1203 warning("%s", ebuf
);
1204 #endif /* HAVE_PCAP_CREATE */
1206 * Let user own process after socket has been opened.
1209 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1210 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1212 #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
1214 if(pcap_setbuff(pd
, Bflag
)==-1){
1215 error("%s", pcap_geterr(pd
));
1217 #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
1219 show_dlts_and_exit(device
, pd
);
1220 if (gndo
->ndo_dlt
>= 0) {
1221 #ifdef HAVE_PCAP_SET_DATALINK
1222 if (pcap_set_datalink(pd
, gndo
->ndo_dlt
) < 0)
1223 error("%s", pcap_geterr(pd
));
1226 * We don't actually support changing the
1227 * data link type, so we only let them
1228 * set it to what it already is.
1230 if (gndo
->ndo_dlt
!= pcap_datalink(pd
)) {
1231 error("%s is not one of the DLTs supported by this device\n",
1235 (void)fprintf(stderr
, "%s: data link type %s\n",
1236 program_name
, gndo
->ndo_dltname
);
1237 (void)fflush(stderr
);
1239 i
= pcap_snapshot(pd
);
1241 warning("snaplen raised from %d to %d", snaplen
, i
);
1244 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1247 warning("%s", ebuf
);
1251 cmdbuf
= read_infile(infile
);
1253 cmdbuf
= copy_argv(&argv
[optind
]);
1255 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1256 error("%s", pcap_geterr(pd
));
1259 bpf_dump(&fcode
, dflag
);
1263 init_addrtoname(localnet
, netmask
);
1267 (void)setsignal(SIGPIPE
, cleanup
);
1268 (void)setsignal(SIGTERM
, cleanup
);
1269 (void)setsignal(SIGINT
, cleanup
);
1271 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1272 (void)setsignal(SIGCHLD
, child_cleanup
);
1274 /* Cooperate with nohup(1) */
1276 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1277 (void)setsignal(SIGHUP
, oldhandler
);
1282 * If a user name was specified with "-Z", attempt to switch to
1283 * that user's UID. This would probably be used with sudo,
1284 * to allow tcpdump to be run in a special restricted
1285 * account (if you just want to allow users to open capture
1286 * devices, and can't just give users that permission,
1287 * you'd make tcpdump set-UID or set-GID).
1289 * Tcpdump doesn't necessarily write only to one savefile;
1290 * the general only way to allow a -Z instance to write to
1291 * savefiles as the user under whose UID it's run, rather
1292 * than as the user specified with -Z, would thus be to switch
1293 * to the original user ID before opening a capture file and
1294 * then switch back to the -Z user ID after opening the savefile.
1295 * Switching to the -Z user ID only after opening the first
1296 * savefile doesn't handle the general case.
1298 if (getuid() == 0 || geteuid() == 0) {
1299 if (username
|| chroot_dir
)
1300 droproot(username
, chroot_dir
);
1304 if (pcap_setfilter(pd
, &fcode
) < 0)
1305 error("%s", pcap_geterr(pd
));
1308 /* Do not exceed the default NAME_MAX for files. */
1309 dumpinfo
.CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1311 if (dumpinfo
.CurrentFileName
== NULL
)
1312 error("malloc of dumpinfo.CurrentFileName");
1314 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1316 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1318 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1320 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1322 error("%s", pcap_geterr(pd
));
1323 if (Cflag
!= 0 || Gflag
!= 0) {
1324 callback
= dump_packet_and_trunc
;
1325 dumpinfo
.WFileName
= WFileName
;
1328 pcap_userdata
= (u_char
*)&dumpinfo
;
1330 callback
= dump_packet
;
1331 pcap_userdata
= (u_char
*)p
;
1333 #ifdef HAVE_PCAP_DUMP_FLUSH
1338 type
= pcap_datalink(pd
);
1339 printinfo
.ndo_type
= 1;
1340 printinfo
.ndo
= gndo
;
1341 printinfo
.p
.ndo_printer
= lookup_ndo_printer(type
);
1342 if (printinfo
.p
.ndo_printer
== NULL
) {
1343 printinfo
.p
.printer
= lookup_printer(type
);
1344 printinfo
.ndo_type
= 0;
1345 if (printinfo
.p
.printer
== NULL
) {
1346 gndo
->ndo_dltname
= pcap_datalink_val_to_name(type
);
1347 if (gndo
->ndo_dltname
!= NULL
)
1348 error("packet printing is not supported for link type %s: use -w",
1351 error("packet printing is not supported for link type %d: use -w", type
);
1354 callback
= print_packet
;
1355 pcap_userdata
= (u_char
*)&printinfo
;
1358 #ifdef SIGNAL_REQ_INFO
1360 * We can't get statistics when reading from a file rather
1361 * than capturing from a device.
1363 if (RFileName
== NULL
)
1364 (void)setsignal(SIGNAL_REQ_INFO
, requestinfo
);
1367 if (vflag
> 0 && WFileName
) {
1369 * When capturing to a file, "-v" means tcpdump should,
1370 * every 10 secodns, "v"erbosely report the number of
1373 #ifdef USE_WIN32_MM_TIMER
1374 /* call verbose_stats_dump() each 1000 +/-100msec */
1375 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1376 setvbuf(stderr
, NULL
, _IONBF
, 0);
1377 #elif defined(HAVE_ALARM)
1378 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1384 if (RFileName
== NULL
) {
1386 const char *dlt_name
;
1388 if (!vflag
&& !WFileName
) {
1389 (void)fprintf(stderr
,
1390 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1393 (void)fprintf(stderr
, "%s: ", program_name
);
1394 dlt
= pcap_datalink(pd
);
1395 dlt_name
= pcap_datalink_val_to_name(dlt
);
1396 if (dlt_name
== NULL
) {
1397 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1398 device
, dlt
, snaplen
);
1400 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1402 pcap_datalink_val_to_description(dlt
), snaplen
);
1404 (void)fflush(stderr
);
1407 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1408 if (WFileName
== NULL
) {
1410 * We're printing packets. Flush the printed output,
1411 * so it doesn't get intermingled with error output.
1415 * We got interrupted, so perhaps we didn't
1416 * manage to finish a line we were printing.
1417 * Print an extra newline, just in case.
1421 (void)fflush(stdout
);
1427 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
1428 program_name
, pcap_geterr(pd
));
1430 if (RFileName
== NULL
) {
1432 * We're doing a live capture. Report the capture
1438 exit(status
== -1 ? 1 : 0);
1441 /* make a clean exit on interrupts */
1443 cleanup(int signo _U_
)
1445 #ifdef USE_WIN32_MM_TIMER
1447 timeKillEvent(timer_id
);
1449 #elif defined(HAVE_ALARM)
1453 #ifdef HAVE_PCAP_BREAKLOOP
1455 * We have "pcap_breakloop()"; use it, so that we do as little
1456 * as possible in the signal handler (it's probably not safe
1457 * to do anything with standard I/O streams in a signal handler -
1458 * the ANSI C standard doesn't say it is).
1463 * We don't have "pcap_breakloop()"; this isn't safe, but
1464 * it's the best we can do. Print the summary if we're
1465 * not reading from a savefile - i.e., if we're doing a
1466 * live capture - and exit.
1468 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
1470 * We got interrupted, so perhaps we didn't
1471 * manage to finish a line we were printing.
1472 * Print an extra newline, just in case.
1475 (void)fflush(stdout
);
1483 On windows, we do not use a fork, so we do not care less about
1484 waiting a child processes to die
1486 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1488 child_cleanup(int signo _U_
)
1492 #endif /* HAVE_FORK && HAVE_VFORK */
1495 info(register int verbose
)
1497 struct pcap_stat stat
;
1500 * Older versions of libpcap didn't set ps_ifdrop on some
1501 * platforms; initialize it to 0 to handle that.
1504 if (pcap_stats(pd
, &stat
) < 0) {
1505 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
1511 fprintf(stderr
, "%s: ", program_name
);
1513 (void)fprintf(stderr
, "%u packet%s captured", packets_captured
,
1514 PLURAL_SUFFIX(packets_captured
));
1516 fputs(", ", stderr
);
1519 (void)fprintf(stderr
, "%u packet%s received by filter", stat
.ps_recv
,
1520 PLURAL_SUFFIX(stat
.ps_recv
));
1522 fputs(", ", stderr
);
1525 (void)fprintf(stderr
, "%u packet%s dropped by kernel", stat
.ps_drop
,
1526 PLURAL_SUFFIX(stat
.ps_drop
));
1527 if (stat
.ps_ifdrop
!= 0) {
1529 fputs(", ", stderr
);
1532 (void)fprintf(stderr
, "%u packet%s dropped by interface\n",
1533 stat
.ps_ifdrop
, PLURAL_SUFFIX(stat
.ps_ifdrop
));
1539 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1541 compress_savefile(const char *filename
)
1550 * Set to lowest priority so that this doesn't disturb the capture
1553 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
1555 setpriority(PRIO_PROCESS
, 0, 19);
1557 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
1559 "compress_savefile:execlp(%s, %s): %s\n",
1569 #else /* HAVE_FORK && HAVE_VFORK */
1571 compress_savefile(const char *filename
)
1574 "compress_savefile failed. Functionality not implemented under your system\n");
1576 #endif /* HAVE_FORK && HAVE_VFORK */
1579 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1581 struct dump_info
*dump_info
;
1587 dump_info
= (struct dump_info
*)user
;
1590 * XXX - this won't force the file to rotate on the specified time
1591 * boundary, but it will rotate on the first packet received after the
1592 * specified Gflag number of seconds. Note: if a Gflag time boundary
1593 * and a Cflag size boundary coincide, the time rotation will occur
1594 * first thereby cancelling the Cflag boundary (since the file should
1598 /* Check if it is time to rotate */
1601 /* Get the current time */
1602 if ((t
= time(NULL
)) == (time_t)-1) {
1603 error("dump_and_trunc_packet: can't get current_time: %s",
1604 pcap_strerror(errno
));
1608 /* If the time is greater than the specified window, rotate */
1609 if (t
- Gflag_time
>= Gflag
) {
1610 /* Update the Gflag_time */
1612 /* Update Gflag_count */
1615 * Close the current file and open a new one.
1617 pcap_dump_close(dump_info
->p
);
1620 * Compress the file we just closed, if the user asked for it
1623 compress_savefile(dump_info
->CurrentFileName
);
1626 * Check to see if we've exceeded the Wflag (when
1629 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
1630 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
1635 if (dump_info
->CurrentFileName
!= NULL
)
1636 free(dump_info
->CurrentFileName
);
1637 /* Allocate space for max filename + \0. */
1638 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1639 if (dump_info
->CurrentFileName
== NULL
)
1640 error("dump_packet_and_trunc: malloc");
1642 * This is always the first file in the Cflag
1644 * We also don't need numbering if Cflag is not set.
1647 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
1650 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
1652 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1653 if (dump_info
->p
== NULL
)
1654 error("%s", pcap_geterr(pd
));
1659 * XXX - this won't prevent capture files from getting
1660 * larger than Cflag - the last packet written to the
1661 * file could put it over Cflag.
1663 if (Cflag
!= 0 && pcap_dump_ftell(dump_info
->p
) > Cflag
) {
1665 * Close the current file and open a new one.
1667 pcap_dump_close(dump_info
->p
);
1670 * Compress the file we just closed, if the user asked for it
1673 compress_savefile(dump_info
->CurrentFileName
);
1677 if (Cflag_count
>= Wflag
)
1680 if (dump_info
->CurrentFileName
!= NULL
)
1681 free(dump_info
->CurrentFileName
);
1682 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1683 if (dump_info
->CurrentFileName
== NULL
)
1684 error("dump_packet_and_trunc: malloc");
1685 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
1686 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1687 if (dump_info
->p
== NULL
)
1688 error("%s", pcap_geterr(pd
));
1691 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
1692 #ifdef HAVE_PCAP_DUMP_FLUSH
1694 pcap_dump_flush(dump_info
->p
);
1703 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1709 pcap_dump(user
, h
, sp
);
1710 #ifdef HAVE_PCAP_DUMP_FLUSH
1712 pcap_dump_flush((pcap_dumper_t
*)user
);
1721 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1723 struct print_info
*print_info
;
1731 print_info
= (struct print_info
*)user
;
1734 * Some printers want to check that they're not walking off the
1735 * end of the packet.
1736 * Rather than pass it all the way down, we set this global.
1738 snapend
= sp
+ h
->caplen
;
1740 if(print_info
->ndo_type
) {
1741 hdrlen
= (*print_info
->p
.ndo_printer
)(print_info
->ndo
, h
, sp
);
1743 hdrlen
= (*print_info
->p
.printer
)(h
, sp
);
1748 * Print the raw packet data in hex and ASCII.
1752 * Include the link-layer header.
1754 hex_and_ascii_print("\n\t", sp
, h
->caplen
);
1757 * Don't include the link-layer header - and if
1758 * we have nothing past the link-layer header,
1761 if (h
->caplen
> hdrlen
)
1762 hex_and_ascii_print("\n\t", sp
+ hdrlen
,
1763 h
->caplen
- hdrlen
);
1767 * Print the raw packet data in hex.
1771 * Include the link-layer header.
1773 hex_print("\n\t", sp
, h
->caplen
);
1776 * Don't include the link-layer header - and if
1777 * we have nothing past the link-layer header,
1780 if (h
->caplen
> hdrlen
)
1781 hex_print("\n\t", sp
+ hdrlen
,
1782 h
->caplen
- hdrlen
);
1786 * Print the raw packet data in ASCII.
1790 * Include the link-layer header.
1792 ascii_print(sp
, h
->caplen
);
1795 * Don't include the link-layer header - and if
1796 * we have nothing past the link-layer header,
1799 if (h
->caplen
> hdrlen
)
1800 ascii_print(sp
+ hdrlen
, h
->caplen
- hdrlen
);
1813 * XXX - there should really be libpcap calls to get the version
1814 * number as a string (the string would be generated from #defines
1815 * at run time, so that it's not generated from string constants
1816 * in the library, as, on many UNIX systems, those constants would
1817 * be statically linked into the application executable image, and
1818 * would thus reflect the version of libpcap on the system on
1819 * which the application was *linked*, not the system on which it's
1822 * That routine should be documented, unlike the "version[]"
1823 * string, so that UNIX vendors providing their own libpcaps
1824 * don't omit it (as a couple of vendors have...).
1826 * Packet.dll should perhaps also export a routine to return the
1827 * version number of the Packet.dll code, to supply the
1828 * "Wpcap_version" information on Windows.
1830 char WDversion
[]="current-cvs.tcpdump.org";
1831 #if !defined(HAVE_GENERATED_VERSION)
1832 char version
[]="current-cvs.tcpdump.org";
1834 char pcap_version
[]="current-cvs.tcpdump.org";
1835 char Wpcap_version
[]="3.1";
1839 * By default, print the specified data out in hex and ASCII.
1842 ndo_default_print(netdissect_options
*ndo _U_
, const u_char
*bp
, u_int length
)
1844 hex_and_ascii_print("\n\t", bp
, length
); /* pass on lf and identation string */
1848 default_print(const u_char
*bp
, u_int length
)
1850 ndo_default_print(gndo
, bp
, length
);
1853 #ifdef SIGNAL_REQ_INFO
1854 RETSIGTYPE
requestinfo(int signo _U_
)
1864 * Called once each second in verbose mode while dumping to file
1866 #ifdef USE_WIN32_MM_TIMER
1867 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
1868 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
1870 struct pcap_stat stat
;
1872 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1873 fprintf(stderr
, "Got %u\r", packets_captured
);
1875 #elif defined(HAVE_ALARM)
1876 static void verbose_stats_dump(int sig _U_
)
1878 struct pcap_stat stat
;
1880 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1881 fprintf(stderr
, "Got %u\r", packets_captured
);
1889 extern char version
[];
1890 #ifndef HAVE_PCAP_LIB_VERSION
1891 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
1892 extern char pcap_version
[];
1893 #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1894 static char pcap_version
[] = "unknown";
1895 #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1896 #endif /* HAVE_PCAP_LIB_VERSION */
1898 #ifdef HAVE_PCAP_LIB_VERSION
1900 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1902 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1904 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
1905 #else /* HAVE_PCAP_LIB_VERSION */
1907 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1908 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
1910 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1911 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
1913 #endif /* HAVE_PCAP_LIB_VERSION */
1914 (void)fprintf(stderr
,
1915 "Usage: %s [-aAbd" D_FLAG
"efhH" I_FLAG J_FLAG
"KlLnNOpqRStu" U_FLAG
"vxX]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
1916 (void)fprintf(stderr
,
1917 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
1918 (void)fprintf(stderr
,
1919 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ]\n");
1920 (void)fprintf(stderr
,
1921 "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
1922 (void)fprintf(stderr
,
1923 "\t\t[ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
1924 (void)fprintf(stderr
,
1925 "\t\t[ -Z user ] [ expression ]\n");
1933 ndo_error(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1937 (void)fprintf(stderr
, "%s: ", program_name
);
1939 (void)vfprintf(stderr
, fmt
, ap
);
1943 if (fmt
[-1] != '\n')
1944 (void)fputc('\n', stderr
);
1952 ndo_warning(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1956 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
1958 (void)vfprintf(stderr
, fmt
, ap
);
1962 if (fmt
[-1] != '\n')
1963 (void)fputc('\n', stderr
);