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"
90 netdissect_options Gndo
;
91 netdissect_options
*gndo
= &Gndo
;
93 static int dflag
; /* print filter code */
94 static int Lflag
; /* list available data link types and exit */
95 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
96 static int Jflag
; /* list available time stamp types */
98 static char *zflag
= NULL
; /* compress each savefile using a specified command (like gzip or bzip2) */
100 static int infodelay
;
101 static int infoprint
;
105 int32_t thiszone
; /* seconds offset from gmt to local time */
108 static RETSIGTYPE
cleanup(int);
109 static RETSIGTYPE
child_cleanup(int);
110 static void usage(void) __attribute__((noreturn
));
111 static void show_dlts_and_exit(const char *device
, pcap_t
*pd
) __attribute__((noreturn
));
113 static void print_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
114 static void ndo_default_print(netdissect_options
*, const u_char
*, u_int
);
115 static void dump_packet_and_trunc(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
116 static void dump_packet(u_char
*, const struct pcap_pkthdr
*, const u_char
*);
117 static void droproot(const char *, const char *);
118 static void ndo_error(netdissect_options
*ndo
, const char *fmt
, ...)
119 __attribute__ ((noreturn
, format (printf
, 2, 3)));
120 static void ndo_warning(netdissect_options
*ndo
, const char *fmt
, ...);
123 RETSIGTYPE
requestinfo(int);
126 #if defined(USE_WIN32_MM_TIMER)
127 #include <MMsystem.h>
128 static UINT timer_id
;
129 static void CALLBACK
verbose_stats_dump(UINT
, UINT
, DWORD_PTR
, DWORD_PTR
, DWORD_PTR
);
130 #elif defined(HAVE_ALARM)
131 static void verbose_stats_dump(int sig
);
134 static void info(int);
135 static u_int packets_captured
;
149 static struct printer printers
[] = {
150 { arcnet_if_print
, DLT_ARCNET
},
151 #ifdef DLT_ARCNET_LINUX
152 { arcnet_linux_if_print
, DLT_ARCNET_LINUX
},
154 { token_if_print
, DLT_IEEE802
},
156 { lane_if_print
, DLT_LANE8023
},
159 { cip_if_print
, DLT_CIP
},
162 { cip_if_print
, DLT_ATM_CLIP
},
164 { sl_if_print
, DLT_SLIP
},
165 #ifdef DLT_SLIP_BSDOS
166 { sl_bsdos_if_print
, DLT_SLIP_BSDOS
},
168 { ppp_if_print
, DLT_PPP
},
169 #ifdef DLT_PPP_WITHDIRECTION
170 { ppp_if_print
, DLT_PPP_WITHDIRECTION
},
173 { ppp_bsdos_if_print
, DLT_PPP_BSDOS
},
175 { fddi_if_print
, DLT_FDDI
},
176 { null_if_print
, DLT_NULL
},
178 { null_if_print
, DLT_LOOP
},
180 { raw_if_print
, DLT_RAW
},
181 { atm_if_print
, DLT_ATM_RFC1483
},
183 { chdlc_if_print
, DLT_C_HDLC
},
186 { chdlc_if_print
, DLT_HDLC
},
188 #ifdef DLT_PPP_SERIAL
189 { ppp_hdlc_if_print
, DLT_PPP_SERIAL
},
192 { pppoe_if_print
, DLT_PPP_ETHER
},
195 { sll_if_print
, DLT_LINUX_SLL
},
197 #ifdef DLT_IEEE802_11
198 { ieee802_11_if_print
, DLT_IEEE802_11
},
201 { ltalk_if_print
, DLT_LTALK
},
203 #if defined(DLT_PFLOG) && defined(HAVE_NET_PFVAR_H)
204 { pflog_if_print
, DLT_PFLOG
},
207 { fr_if_print
, DLT_FR
},
210 { fr_if_print
, DLT_FRELAY
},
213 { sunatm_if_print
, DLT_SUNATM
},
215 #ifdef DLT_IP_OVER_FC
216 { ipfc_if_print
, DLT_IP_OVER_FC
},
218 #ifdef DLT_PRISM_HEADER
219 { prism_if_print
, DLT_PRISM_HEADER
},
221 #ifdef DLT_IEEE802_11_RADIO
222 { ieee802_11_radio_if_print
, DLT_IEEE802_11_RADIO
},
225 { enc_if_print
, DLT_ENC
},
227 #ifdef DLT_SYMANTEC_FIREWALL
228 { symantec_if_print
, DLT_SYMANTEC_FIREWALL
},
230 #ifdef DLT_APPLE_IP_OVER_IEEE1394
231 { ap1394_if_print
, DLT_APPLE_IP_OVER_IEEE1394
},
233 #ifdef DLT_IEEE802_11_RADIO_AVS
234 { ieee802_11_radio_avs_if_print
, DLT_IEEE802_11_RADIO_AVS
},
236 #ifdef DLT_JUNIPER_ATM1
237 { juniper_atm1_print
, DLT_JUNIPER_ATM1
},
239 #ifdef DLT_JUNIPER_ATM2
240 { juniper_atm2_print
, DLT_JUNIPER_ATM2
},
242 #ifdef DLT_JUNIPER_MFR
243 { juniper_mfr_print
, DLT_JUNIPER_MFR
},
245 #ifdef DLT_JUNIPER_MLFR
246 { juniper_mlfr_print
, DLT_JUNIPER_MLFR
},
248 #ifdef DLT_JUNIPER_MLPPP
249 { juniper_mlppp_print
, DLT_JUNIPER_MLPPP
},
251 #ifdef DLT_JUNIPER_PPPOE
252 { juniper_pppoe_print
, DLT_JUNIPER_PPPOE
},
254 #ifdef DLT_JUNIPER_PPPOE_ATM
255 { juniper_pppoe_atm_print
, DLT_JUNIPER_PPPOE_ATM
},
257 #ifdef DLT_JUNIPER_GGSN
258 { juniper_ggsn_print
, DLT_JUNIPER_GGSN
},
260 #ifdef DLT_JUNIPER_ES
261 { juniper_es_print
, DLT_JUNIPER_ES
},
263 #ifdef DLT_JUNIPER_MONITOR
264 { juniper_monitor_print
, DLT_JUNIPER_MONITOR
},
266 #ifdef DLT_JUNIPER_SERVICES
267 { juniper_services_print
, DLT_JUNIPER_SERVICES
},
269 #ifdef DLT_JUNIPER_ETHER
270 { juniper_ether_print
, DLT_JUNIPER_ETHER
},
272 #ifdef DLT_JUNIPER_PPP
273 { juniper_ppp_print
, DLT_JUNIPER_PPP
},
275 #ifdef DLT_JUNIPER_FRELAY
276 { juniper_frelay_print
, DLT_JUNIPER_FRELAY
},
278 #ifdef DLT_JUNIPER_CHDLC
279 { juniper_chdlc_print
, DLT_JUNIPER_CHDLC
},
282 { mfr_if_print
, DLT_MFR
},
284 #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
285 { bt_if_print
, DLT_BLUETOOTH_HCI_H4_WITH_PHDR
},
287 #ifdef HAVE_PCAP_USB_H
289 { usb_linux_48_byte_print
, DLT_USB_LINUX
},
290 #endif /* DLT_USB_LINUX */
291 #ifdef DLT_USB_LINUX_MMAPPED
292 { usb_linux_64_byte_print
, DLT_USB_LINUX_MMAPPED
},
293 #endif /* DLT_USB_LINUX_MMAPPED */
294 #endif /* HAVE_PCAP_USB_H */
296 { raw_if_print
, DLT_IPV4
},
299 { raw_if_print
, DLT_IPV6
},
304 static struct ndo_printer ndo_printers
[] = {
305 { ether_if_print
, DLT_EN10MB
},
307 { ipnet_if_print
, DLT_IPNET
},
309 #ifdef DLT_IEEE802_15_4
310 { ieee802_15_4_if_print
, DLT_IEEE802_15_4
},
312 #ifdef DLT_IEEE802_15_4_NOFCS
313 { ieee802_15_4_if_print
, DLT_IEEE802_15_4_NOFCS
},
316 { ppi_if_print
, DLT_PPI
},
318 #ifdef DLT_ETHERNET_HILSCHER
319 { ether_hilscher_if_print
, DLT_ETHERNET_HILSCHER
},
321 #ifdef DLT_ETHERNET_HILSCHER_TRANSPARENT
322 { ether_hilscher_transparent_if_print
, DLT_ETHERNET_HILSCHER_TRANSPARENT
},
328 lookup_printer(int type
)
332 for (p
= printers
; p
->f
; ++p
)
341 lookup_ndo_printer(int type
)
343 struct ndo_printer
*p
;
345 for (p
= ndo_printers
; p
->f
; ++p
)
355 static int supports_monitor_mode
;
362 netdissect_options
*ndo
;
365 if_ndo_printer ndo_printer
;
372 char *CurrentFileName
;
377 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
379 show_tstamp_types_and_exit(const char *device
, pcap_t
*pd
)
382 int *tstamp_types
= 0;
383 const char *tstamp_type_name
;
386 n_tstamp_types
= pcap_list_tstamp_types(pd
, &tstamp_types
);
387 if (n_tstamp_types
< 0)
388 error("%s", pcap_geterr(pd
));
390 if (n_tstamp_types
== 0) {
391 fprintf(stderr
, "Time stamp type cannot be set for %s\n",
395 fprintf(stderr
, "Time stamp types for %s (use option -j to set):\n",
397 for (i
= 0; i
< n_tstamp_types
; i
++) {
398 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
399 if (tstamp_type_name
!= NULL
) {
400 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
401 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
403 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
406 pcap_free_tstamp_types(tstamp_types
);
412 show_dlts_and_exit(const char *device
, pcap_t
*pd
)
416 const char *dlt_name
;
418 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
420 error("%s", pcap_geterr(pd
));
421 else if (n_dlts
== 0 || !dlts
)
422 error("No data link types.");
425 * If the interface is known to support monitor mode, indicate
426 * whether these are the data link types available when not in
427 * monitor mode, if -I wasn't specified, or when in monitor mode,
428 * when -I was specified (the link-layer types available in
429 * monitor mode might be different from the ones available when
430 * not in monitor mode).
432 if (supports_monitor_mode
)
433 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
435 Iflag
? "when in monitor mode" : "when not in monitor mode");
437 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
440 while (--n_dlts
>= 0) {
441 dlt_name
= pcap_datalink_val_to_name(dlts
[n_dlts
]);
442 if (dlt_name
!= NULL
) {
443 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
444 pcap_datalink_val_to_description(dlts
[n_dlts
]));
447 * OK, does tcpdump handle that type?
449 if (lookup_printer(dlts
[n_dlts
]) == NULL
450 && lookup_ndo_printer(dlts
[n_dlts
]) == NULL
)
451 (void) fprintf(stderr
, " (printing not supported)");
452 fprintf(stderr
, "\n");
454 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
458 pcap_free_datalinks(dlts
);
463 * Set up flags that might or might not be supported depending on the
464 * version of libpcap we're using.
466 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
468 #define B_FLAG_USAGE " [ -B size ]"
469 #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
472 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
474 #ifdef HAVE_PCAP_CREATE
476 #else /* HAVE_PCAP_CREATE */
478 #endif /* HAVE_PCAP_CREATE */
480 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
482 #define j_FLAG_USAGE " [ -j tstamptype ]"
484 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
488 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
490 #ifdef HAVE_PCAP_FINDALLDEVS
491 #ifndef HAVE_PCAP_IF_T
492 #undef HAVE_PCAP_FINDALLDEVS
496 #ifdef HAVE_PCAP_FINDALLDEVS
502 #ifdef HAVE_PCAP_DUMP_FLUSH
509 /* Drop root privileges and chroot if necessary */
511 droproot(const char *username
, const char *chroot_dir
)
513 struct passwd
*pw
= NULL
;
515 if (chroot_dir
&& !username
) {
516 fprintf(stderr
, "tcpdump: Chroot without dropping root is insecure\n");
520 pw
= getpwnam(username
);
523 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
524 fprintf(stderr
, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
525 chroot_dir
, pcap_strerror(errno
));
529 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
530 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
531 fprintf(stderr
, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
533 (unsigned long)pw
->pw_uid
,
534 (unsigned long)pw
->pw_gid
,
535 pcap_strerror(errno
));
540 fprintf(stderr
, "tcpdump: Couldn't find user '%.32s'\n",
563 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
565 char *filename
= malloc(NAME_MAX
+ 1);
567 /* Process with strftime if Gflag is set. */
571 /* Convert Gflag_time to a usable format */
572 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
573 error("MakeTimedFilename: localtime");
576 /* There's no good way to detect an error in strftime since a return
577 * value of 0 isn't necessarily failure.
579 strftime(filename
, NAME_MAX
, orig_name
, local_tm
);
581 strncpy(filename
, orig_name
, NAME_MAX
);
584 if (cnt
== 0 && max_chars
== 0)
585 strncpy(buffer
, filename
, NAME_MAX
+ 1);
587 if (snprintf(buffer
, NAME_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > NAME_MAX
)
588 /* Report an error if the filename is too large */
589 error("too many output files or filename is too long (> %d)", NAME_MAX
);
593 static int tcpdump_printf(netdissect_options
*ndo _U_
,
594 const char *fmt
, ...)
601 ret
=vfprintf(stdout
, fmt
, args
);
608 main(int argc
, char **argv
)
610 register int cnt
, op
, i
;
611 bpf_u_int32 localnet
, netmask
;
612 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *WFileName
;
613 pcap_handler callback
;
615 struct bpf_program fcode
;
617 RETSIGTYPE (*oldhandler
)(int);
619 struct print_info printinfo
;
620 struct dump_info dumpinfo
;
621 u_char
*pcap_userdata
;
622 char ebuf
[PCAP_ERRBUF_SIZE
];
623 char *username
= NULL
;
624 char *chroot_dir
= NULL
;
625 #ifdef HAVE_PCAP_FINDALLDEVS
626 pcap_if_t
*devpointer
;
631 if(wsockinit() != 0) return 1;
634 jflag
=-1; /* not set */
638 gndo
->ndo_default_print
=ndo_default_print
;
639 gndo
->ndo_printf
=tcpdump_printf
;
640 gndo
->ndo_error
=ndo_error
;
641 gndo
->ndo_warning
=ndo_warning
;
642 gndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
649 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
650 program_name
= cp
+ 1;
652 program_name
= argv
[0];
654 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
662 (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)
666 /* compatibility for old -a */
677 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
679 Bflag
= atoi(optarg
)*1024;
681 error("invalid packet buffer size %s", optarg
);
683 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
688 error("invalid packet count %s", optarg
);
692 Cflag
= atoi(optarg
) * 1000000;
694 error("invalid file size %s", optarg
);
701 #ifdef HAVE_PCAP_FINDALLDEVS
703 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
706 for (i
= 0; devpointer
!= 0; i
++) {
707 printf("%d.%s", i
+1, devpointer
->name
);
708 if (devpointer
->description
!= NULL
)
709 printf(" (%s)", devpointer
->description
);
711 devpointer
= devpointer
->next
;
715 #endif /* HAVE_PCAP_FINDALLDEVS */
726 #ifndef HAVE_LIBCRYPTO
727 warning("crypto code not compiled in");
729 gndo
->ndo_espsecret
= optarg
;
741 Gflag
= atoi(optarg
);
743 error("invalid number of seconds %s", optarg
);
745 /* We will create one file initially. */
748 /* Grab the current time for rotation use. */
749 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
750 error("main: can't get current time: %s",
751 pcap_strerror(errno
));
764 if (optarg
[0] == '0' && optarg
[1] == 0)
765 error("Invalid adapter index");
767 #ifdef HAVE_PCAP_FINDALLDEVS
769 * If the argument is a number, treat it as
770 * an index into the list of adapters, as
771 * printed by "tcpdump -D".
773 * This should be OK on UNIX systems, as interfaces
774 * shouldn't have names that begin with digits.
775 * It can be useful on Windows, where more than
776 * one interface can have the same name.
778 if ((devnum
= atoi(optarg
)) != 0) {
780 error("Invalid adapter index");
782 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
786 * Look for the devnum-th entry
787 * in the list of devices
791 i
< devnum
-1 && devpointer
!= NULL
;
792 i
++, devpointer
= devpointer
->next
)
794 if (devpointer
== NULL
)
795 error("Invalid adapter index");
797 device
= devpointer
->name
;
800 #endif /* HAVE_PCAP_FINDALLDEVS */
804 #ifdef HAVE_PCAP_CREATE
808 #endif /* HAVE_PCAP_CREATE */
810 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
812 jflag
= pcap_tstamp_type_name_to_val(optarg
);
814 error("invalid time stamp type %s", optarg
);
825 * _IOLBF is the same as _IOFBF in Microsoft's C
826 * libraries; the only alternative they offer
829 * XXX - this should really be checking for MSVC++,
830 * not WIN32, if, for example, MinGW has its own
831 * C library that is more UNIX-compatible.
833 setvbuf(stdout
, NULL
, _IONBF
, 0);
835 #ifdef HAVE_SETLINEBUF
838 setvbuf(stdout
, NULL
, _IOLBF
, 0);
849 if (smiLoadModule(optarg
) == 0) {
850 error("could not load MIB module %s", optarg
);
854 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
855 program_name
, optarg
);
856 (void)fprintf(stderr
, "(no libsmi support)\n");
861 /* TCP-MD5 shared secret */
862 #ifndef HAVE_LIBCRYPTO
863 warning("crypto code not compiled in");
886 ++suppress_default_print
;
900 snaplen
= strtol(optarg
, &end
, 0);
901 if (optarg
== end
|| *end
!= '\0'
902 || snaplen
< 0 || snaplen
> MAXIMUM_SNAPLEN
)
903 error("invalid snaplen %s", optarg
);
904 else if (snaplen
== 0)
905 snaplen
= MAXIMUM_SNAPLEN
;
918 if (strcasecmp(optarg
, "vat") == 0)
920 else if (strcasecmp(optarg
, "wb") == 0)
922 else if (strcasecmp(optarg
, "rpc") == 0)
924 else if (strcasecmp(optarg
, "rtp") == 0)
926 else if (strcasecmp(optarg
, "rtcp") == 0)
927 packettype
= PT_RTCP
;
928 else if (strcasecmp(optarg
, "snmp") == 0)
929 packettype
= PT_SNMP
;
930 else if (strcasecmp(optarg
, "cnfp") == 0)
931 packettype
= PT_CNFP
;
932 else if (strcasecmp(optarg
, "tftp") == 0)
933 packettype
= PT_TFTP
;
934 else if (strcasecmp(optarg
, "aodv") == 0)
935 packettype
= PT_AODV
;
937 error("unknown packet type `%s'", optarg
);
944 #ifdef HAVE_PCAP_DUMP_FLUSH
959 Wflag
= atoi(optarg
);
961 error("invalid number of output files %s", optarg
);
962 WflagChars
= getWflagChars(Wflag
);
967 ++suppress_default_print
;
972 ++suppress_default_print
;
976 gndo
->ndo_dltname
= optarg
;
978 pcap_datalink_name_to_val(gndo
->ndo_dltname
);
979 if (gndo
->ndo_dlt
< 0)
980 error("invalid data link type %s", gndo
->ndo_dltname
);
983 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
986 /* Undocumented flag */
987 #ifdef HAVE_PCAP_DEBUG
988 extern int pcap_debug
;
999 zflag
= strdup(optarg
);
1008 username
= strdup(optarg
);
1023 case 0: /* Default */
1024 case 4: /* Default + Date*/
1025 thiszone
= gmt2local(0);
1028 case 1: /* No time stamp */
1029 case 2: /* Unix timeval style */
1030 case 3: /* Microseconds since previous packet */
1031 case 5: /* Microseconds since first packet */
1034 default: /* Not supported */
1035 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1040 /* if run as root, prepare for chrooting */
1041 if (getuid() == 0 || geteuid() == 0) {
1042 /* future extensibility for cmd-line arguments */
1044 chroot_dir
= WITH_CHROOT
;
1049 /* if run as root, prepare for dropping root privileges */
1050 if (getuid() == 0 || geteuid() == 0) {
1051 /* Run with '-Z root' to restore old behaviour */
1053 username
= WITH_USER
;
1057 if (RFileName
!= NULL
) {
1059 const char *dlt_name
;
1063 * We don't need network access, so relinquish any set-UID
1064 * or set-GID privileges we have (if any).
1066 * We do *not* want set-UID privileges when opening a
1067 * trace file, as that might let the user read other
1068 * people's trace files (especially if we're set-UID
1071 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1072 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1074 pd
= pcap_open_offline(RFileName
, ebuf
);
1077 dlt
= pcap_datalink(pd
);
1078 dlt_name
= pcap_datalink_val_to_name(dlt
);
1079 if (dlt_name
== NULL
) {
1080 fprintf(stderr
, "reading from file %s, link-type %u\n",
1084 "reading from file %s, link-type %s (%s)\n",
1085 RFileName
, dlt_name
,
1086 pcap_datalink_val_to_description(dlt
));
1091 error("-f and -r options are incompatible");
1093 if (device
== NULL
) {
1094 device
= pcap_lookupdev(ebuf
);
1099 if(strlen(device
) == 1) //we assume that an ASCII string is always longer than 1 char
1100 { //a Unicode string has a \0 as second byte (so strlen() is 1)
1101 fprintf(stderr
, "%s: listening on %ws\n", program_name
, device
);
1105 fprintf(stderr
, "%s: listening on %s\n", program_name
, device
);
1110 #ifdef HAVE_PCAP_CREATE
1111 pd
= pcap_create(device
, ebuf
);
1114 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1116 show_tstamp_types_and_exit(device
, pd
);
1119 * Is this an interface that supports monitor mode?
1121 if (pcap_can_set_rfmon(pd
) == 1)
1122 supports_monitor_mode
= 1;
1124 supports_monitor_mode
= 0;
1125 status
= pcap_set_snaplen(pd
, snaplen
);
1127 error("%s: Can't set snapshot length: %s",
1128 device
, pcap_statustostr(status
));
1129 status
= pcap_set_promisc(pd
, !pflag
);
1131 error("%s: Can't set promiscuous mode: %s",
1132 device
, pcap_statustostr(status
));
1134 status
= pcap_set_rfmon(pd
, 1);
1136 error("%s: Can't set monitor mode: %s",
1137 device
, pcap_statustostr(status
));
1139 status
= pcap_set_timeout(pd
, 1000);
1141 error("%s: pcap_set_timeout failed: %s",
1142 device
, pcap_statustostr(status
));
1144 status
= pcap_set_buffer_size(pd
, Bflag
);
1146 error("%s: Can't set buffer size: %s",
1147 device
, pcap_statustostr(status
));
1149 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1151 status
= pcap_set_tstamp_type(pd
, jflag
);
1153 error("%s: Can't set time stamp type: %s",
1154 device
, pcap_statustostr(status
));
1157 status
= pcap_activate(pd
);
1160 * pcap_activate() failed.
1162 cp
= pcap_geterr(pd
);
1163 if (status
== PCAP_ERROR
)
1165 else if ((status
== PCAP_ERROR_NO_SUCH_DEVICE
||
1166 status
== PCAP_ERROR_PERM_DENIED
) &&
1168 error("%s: %s\n(%s)", device
,
1169 pcap_statustostr(status
), cp
);
1171 error("%s: %s", device
,
1172 pcap_statustostr(status
));
1173 } else if (status
> 0) {
1175 * pcap_activate() succeeded, but it's warning us
1176 * of a problem it had.
1178 cp
= pcap_geterr(pd
);
1179 if (status
== PCAP_WARNING
)
1181 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1183 warning("%s: %s\n(%s)", device
,
1184 pcap_statustostr(status
), cp
);
1186 warning("%s: %s", device
,
1187 pcap_statustostr(status
));
1191 pd
= pcap_open_live(device
, snaplen
, !pflag
, 1000, ebuf
);
1195 warning("%s", ebuf
);
1196 #endif /* HAVE_PCAP_CREATE */
1198 * Let user own process after socket has been opened.
1201 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1202 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1204 #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
1206 if(pcap_setbuff(pd
, Bflag
)==-1){
1207 error("%s", pcap_geterr(pd
));
1209 #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
1211 show_dlts_and_exit(device
, pd
);
1212 if (gndo
->ndo_dlt
>= 0) {
1213 #ifdef HAVE_PCAP_SET_DATALINK
1214 if (pcap_set_datalink(pd
, gndo
->ndo_dlt
) < 0)
1215 error("%s", pcap_geterr(pd
));
1218 * We don't actually support changing the
1219 * data link type, so we only let them
1220 * set it to what it already is.
1222 if (gndo
->ndo_dlt
!= pcap_datalink(pd
)) {
1223 error("%s is not one of the DLTs supported by this device\n",
1227 (void)fprintf(stderr
, "%s: data link type %s\n",
1228 program_name
, gndo
->ndo_dltname
);
1229 (void)fflush(stderr
);
1231 i
= pcap_snapshot(pd
);
1233 warning("snaplen raised from %d to %d", snaplen
, i
);
1236 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1239 warning("%s", ebuf
);
1243 cmdbuf
= read_infile(infile
);
1245 cmdbuf
= copy_argv(&argv
[optind
]);
1247 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1248 error("%s", pcap_geterr(pd
));
1251 bpf_dump(&fcode
, dflag
);
1255 init_addrtoname(localnet
, netmask
);
1259 (void)setsignal(SIGPIPE
, cleanup
);
1260 (void)setsignal(SIGTERM
, cleanup
);
1261 (void)setsignal(SIGINT
, cleanup
);
1263 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1264 (void)setsignal(SIGCHLD
, child_cleanup
);
1266 /* Cooperate with nohup(1) */
1268 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1269 (void)setsignal(SIGHUP
, oldhandler
);
1274 * If a user name was specified with "-Z", attempt to switch to
1275 * that user's UID. This would probably be used with sudo,
1276 * to allow tcpdump to be run in a special restricted
1277 * account (if you just want to allow users to open capture
1278 * devices, and can't just give users that permission,
1279 * you'd make tcpdump set-UID or set-GID).
1281 * Tcpdump doesn't necessarily write only to one savefile;
1282 * the general only way to allow a -Z instance to write to
1283 * savefiles as the user under whose UID it's run, rather
1284 * than as the user specified with -Z, would thus be to switch
1285 * to the original user ID before opening a capture file and
1286 * then switch back to the -Z user ID after opening the savefile.
1287 * Switching to the -Z user ID only after opening the first
1288 * savefile doesn't handle the general case.
1290 if (getuid() == 0 || geteuid() == 0) {
1291 if (username
|| chroot_dir
)
1292 droproot(username
, chroot_dir
);
1296 if (pcap_setfilter(pd
, &fcode
) < 0)
1297 error("%s", pcap_geterr(pd
));
1300 /* Do not exceed the default NAME_MAX for files. */
1301 dumpinfo
.CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1303 if (dumpinfo
.CurrentFileName
== NULL
)
1304 error("malloc of dumpinfo.CurrentFileName");
1306 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1308 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1310 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1312 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1314 error("%s", pcap_geterr(pd
));
1315 if (Cflag
!= 0 || Gflag
!= 0) {
1316 callback
= dump_packet_and_trunc
;
1317 dumpinfo
.WFileName
= WFileName
;
1320 pcap_userdata
= (u_char
*)&dumpinfo
;
1322 callback
= dump_packet
;
1323 pcap_userdata
= (u_char
*)p
;
1325 #ifdef HAVE_PCAP_DUMP_FLUSH
1330 type
= pcap_datalink(pd
);
1331 printinfo
.ndo_type
= 1;
1332 printinfo
.ndo
= gndo
;
1333 printinfo
.p
.ndo_printer
= lookup_ndo_printer(type
);
1334 if (printinfo
.p
.ndo_printer
== NULL
) {
1335 printinfo
.p
.printer
= lookup_printer(type
);
1336 printinfo
.ndo_type
= 0;
1337 if (printinfo
.p
.printer
== NULL
) {
1338 gndo
->ndo_dltname
= pcap_datalink_val_to_name(type
);
1339 if (gndo
->ndo_dltname
!= NULL
)
1340 error("packet printing is not supported for link type %s: use -w",
1343 error("packet printing is not supported for link type %d: use -w", type
);
1346 callback
= print_packet
;
1347 pcap_userdata
= (u_char
*)&printinfo
;
1352 * We can't get statistics when reading from a file rather
1353 * than capturing from a device.
1355 if (RFileName
== NULL
)
1356 (void)setsignal(SIGINFO
, requestinfo
);
1359 if (vflag
> 0 && WFileName
) {
1361 * When capturing to a file, "-v" means tcpdump should,
1362 * every 10 secodns, "v"erbosely report the number of
1365 #ifdef USE_WIN32_MM_TIMER
1366 /* call verbose_stats_dump() each 1000 +/-100msec */
1367 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1368 setvbuf(stderr
, NULL
, _IONBF
, 0);
1369 #elif defined(HAVE_ALARM)
1370 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1376 if (RFileName
== NULL
) {
1378 const char *dlt_name
;
1380 if (!vflag
&& !WFileName
) {
1381 (void)fprintf(stderr
,
1382 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1385 (void)fprintf(stderr
, "%s: ", program_name
);
1386 dlt
= pcap_datalink(pd
);
1387 dlt_name
= pcap_datalink_val_to_name(dlt
);
1388 if (dlt_name
== NULL
) {
1389 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1390 device
, dlt
, snaplen
);
1392 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1394 pcap_datalink_val_to_description(dlt
), snaplen
);
1396 (void)fflush(stderr
);
1399 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1400 if (WFileName
== NULL
) {
1402 * We're printing packets. Flush the printed output,
1403 * so it doesn't get intermingled with error output.
1407 * We got interrupted, so perhaps we didn't
1408 * manage to finish a line we were printing.
1409 * Print an extra newline, just in case.
1413 (void)fflush(stdout
);
1419 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
1420 program_name
, pcap_geterr(pd
));
1422 if (RFileName
== NULL
) {
1424 * We're doing a live capture. Report the capture
1430 exit(status
== -1 ? 1 : 0);
1433 /* make a clean exit on interrupts */
1435 cleanup(int signo _U_
)
1437 #ifdef USE_WIN32_MM_TIMER
1439 timeKillEvent(timer_id
);
1441 #elif defined(HAVE_ALARM)
1445 #ifdef HAVE_PCAP_BREAKLOOP
1447 * We have "pcap_breakloop()"; use it, so that we do as little
1448 * as possible in the signal handler (it's probably not safe
1449 * to do anything with standard I/O streams in a signal handler -
1450 * the ANSI C standard doesn't say it is).
1455 * We don't have "pcap_breakloop()"; this isn't safe, but
1456 * it's the best we can do. Print the summary if we're
1457 * not reading from a savefile - i.e., if we're doing a
1458 * live capture - and exit.
1460 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
1462 * We got interrupted, so perhaps we didn't
1463 * manage to finish a line we were printing.
1464 * Print an extra newline, just in case.
1467 (void)fflush(stdout
);
1475 On windows, we do not use a fork, so we do not care less about
1476 waiting a child processes to die
1478 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1480 child_cleanup(int signo _U_
)
1484 #endif /* HAVE_FORK && HAVE_VFORK */
1487 info(register int verbose
)
1489 struct pcap_stat stat
;
1492 * Older versions of libpcap didn't set ps_ifdrop on some
1493 * platforms; initialize it to 0 to handle that.
1496 if (pcap_stats(pd
, &stat
) < 0) {
1497 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
1503 fprintf(stderr
, "%s: ", program_name
);
1505 (void)fprintf(stderr
, "%u packet%s captured", packets_captured
,
1506 PLURAL_SUFFIX(packets_captured
));
1508 fputs(", ", stderr
);
1511 (void)fprintf(stderr
, "%u packet%s received by filter", stat
.ps_recv
,
1512 PLURAL_SUFFIX(stat
.ps_recv
));
1514 fputs(", ", stderr
);
1517 (void)fprintf(stderr
, "%u packet%s dropped by kernel", stat
.ps_drop
,
1518 PLURAL_SUFFIX(stat
.ps_drop
));
1519 if (stat
.ps_ifdrop
!= 0) {
1521 fputs(", ", stderr
);
1524 (void)fprintf(stderr
, "%u packet%s dropped by interface\n",
1525 stat
.ps_ifdrop
, PLURAL_SUFFIX(stat
.ps_ifdrop
));
1531 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1533 compress_savefile(const char *filename
)
1542 * Set to lowest priority so that this doesn't disturb the capture
1545 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
1547 setpriority(PRIO_PROCESS
, 0, 19);
1549 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
1551 "compress_savefile:execlp(%s, %s): %s\n",
1561 #else /* HAVE_FORK && HAVE_VFORK */
1563 compress_savefile(const char *filename
)
1566 "compress_savefile failed. Functionality not implemented under your system\n");
1568 #endif /* HAVE_FORK && HAVE_VFORK */
1571 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1573 struct dump_info
*dump_info
;
1579 dump_info
= (struct dump_info
*)user
;
1582 * XXX - this won't force the file to rotate on the specified time
1583 * boundary, but it will rotate on the first packet received after the
1584 * specified Gflag number of seconds. Note: if a Gflag time boundary
1585 * and a Cflag size boundary coincide, the time rotation will occur
1586 * first thereby cancelling the Cflag boundary (since the file should
1590 /* Check if it is time to rotate */
1593 /* Get the current time */
1594 if ((t
= time(NULL
)) == (time_t)-1) {
1595 error("dump_and_trunc_packet: can't get current_time: %s",
1596 pcap_strerror(errno
));
1600 /* If the time is greater than the specified window, rotate */
1601 if (t
- Gflag_time
>= Gflag
) {
1602 /* Update the Gflag_time */
1604 /* Update Gflag_count */
1607 * Close the current file and open a new one.
1609 pcap_dump_close(dump_info
->p
);
1612 * Compress the file we just closed, if the user asked for it
1615 compress_savefile(dump_info
->CurrentFileName
);
1618 * Check to see if we've exceeded the Wflag (when
1621 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
1622 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
1627 if (dump_info
->CurrentFileName
!= NULL
)
1628 free(dump_info
->CurrentFileName
);
1629 /* Allocate space for max filename + \0. */
1630 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1631 if (dump_info
->CurrentFileName
== NULL
)
1632 error("dump_packet_and_trunc: malloc");
1634 * This is always the first file in the Cflag
1636 * We also don't need numbering if Cflag is not set.
1639 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
1642 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
1644 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1645 if (dump_info
->p
== NULL
)
1646 error("%s", pcap_geterr(pd
));
1651 * XXX - this won't prevent capture files from getting
1652 * larger than Cflag - the last packet written to the
1653 * file could put it over Cflag.
1655 if (Cflag
!= 0 && pcap_dump_ftell(dump_info
->p
) > Cflag
) {
1657 * Close the current file and open a new one.
1659 pcap_dump_close(dump_info
->p
);
1662 * Compress the file we just closed, if the user asked for it
1665 compress_savefile(dump_info
->CurrentFileName
);
1669 if (Cflag_count
>= Wflag
)
1672 if (dump_info
->CurrentFileName
!= NULL
)
1673 free(dump_info
->CurrentFileName
);
1674 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1675 if (dump_info
->CurrentFileName
== NULL
)
1676 error("dump_packet_and_trunc: malloc");
1677 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
1678 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1679 if (dump_info
->p
== NULL
)
1680 error("%s", pcap_geterr(pd
));
1683 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
1684 #ifdef HAVE_PCAP_DUMP_FLUSH
1686 pcap_dump_flush(dump_info
->p
);
1695 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1701 pcap_dump(user
, h
, sp
);
1702 #ifdef HAVE_PCAP_DUMP_FLUSH
1704 pcap_dump_flush((pcap_dumper_t
*)user
);
1713 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1715 struct print_info
*print_info
;
1723 print_info
= (struct print_info
*)user
;
1726 * Some printers want to check that they're not walking off the
1727 * end of the packet.
1728 * Rather than pass it all the way down, we set this global.
1730 snapend
= sp
+ h
->caplen
;
1732 if(print_info
->ndo_type
) {
1733 hdrlen
= (*print_info
->p
.ndo_printer
)(print_info
->ndo
, h
, sp
);
1735 hdrlen
= (*print_info
->p
.printer
)(h
, sp
);
1740 * Print the raw packet data in hex and ASCII.
1744 * Include the link-layer header.
1746 hex_and_ascii_print("\n\t", sp
, h
->caplen
);
1749 * Don't include the link-layer header - and if
1750 * we have nothing past the link-layer header,
1753 if (h
->caplen
> hdrlen
)
1754 hex_and_ascii_print("\n\t", sp
+ hdrlen
,
1755 h
->caplen
- hdrlen
);
1759 * Print the raw packet data in hex.
1763 * Include the link-layer header.
1765 hex_print("\n\t", sp
, h
->caplen
);
1768 * Don't include the link-layer header - and if
1769 * we have nothing past the link-layer header,
1772 if (h
->caplen
> hdrlen
)
1773 hex_print("\n\t", sp
+ hdrlen
,
1774 h
->caplen
- hdrlen
);
1778 * Print the raw packet data in ASCII.
1782 * Include the link-layer header.
1784 ascii_print(sp
, h
->caplen
);
1787 * Don't include the link-layer header - and if
1788 * we have nothing past the link-layer header,
1791 if (h
->caplen
> hdrlen
)
1792 ascii_print(sp
+ hdrlen
, h
->caplen
- hdrlen
);
1805 * XXX - there should really be libpcap calls to get the version
1806 * number as a string (the string would be generated from #defines
1807 * at run time, so that it's not generated from string constants
1808 * in the library, as, on many UNIX systems, those constants would
1809 * be statically linked into the application executable image, and
1810 * would thus reflect the version of libpcap on the system on
1811 * which the application was *linked*, not the system on which it's
1814 * That routine should be documented, unlike the "version[]"
1815 * string, so that UNIX vendors providing their own libpcaps
1816 * don't omit it (as a couple of vendors have...).
1818 * Packet.dll should perhaps also export a routine to return the
1819 * version number of the Packet.dll code, to supply the
1820 * "Wpcap_version" information on Windows.
1822 char WDversion
[]="current-cvs.tcpdump.org";
1823 #if !defined(HAVE_GENERATED_VERSION)
1824 char version
[]="current-cvs.tcpdump.org";
1826 char pcap_version
[]="current-cvs.tcpdump.org";
1827 char Wpcap_version
[]="3.1";
1831 * By default, print the specified data out in hex and ASCII.
1834 ndo_default_print(netdissect_options
*ndo _U_
, const u_char
*bp
, u_int length
)
1836 hex_and_ascii_print("\n\t", bp
, length
); /* pass on lf and identation string */
1840 default_print(const u_char
*bp
, u_int length
)
1842 ndo_default_print(gndo
, bp
, length
);
1846 RETSIGTYPE
requestinfo(int signo _U_
)
1856 * Called once each second in verbose mode while dumping to file
1858 #ifdef USE_WIN32_MM_TIMER
1859 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
1860 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
1862 struct pcap_stat stat
;
1864 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1865 fprintf(stderr
, "Got %u\r", packets_captured
);
1867 #elif defined(HAVE_ALARM)
1868 static void verbose_stats_dump(int sig _U_
)
1870 struct pcap_stat stat
;
1872 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1873 fprintf(stderr
, "Got %u\r", packets_captured
);
1881 extern char version
[];
1882 #ifndef HAVE_PCAP_LIB_VERSION
1883 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
1884 extern char pcap_version
[];
1885 #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1886 static char pcap_version
[] = "unknown";
1887 #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1888 #endif /* HAVE_PCAP_LIB_VERSION */
1890 #ifdef HAVE_PCAP_LIB_VERSION
1892 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1894 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1896 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
1897 #else /* HAVE_PCAP_LIB_VERSION */
1899 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1900 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
1902 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1903 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
1905 #endif /* HAVE_PCAP_LIB_VERSION */
1906 (void)fprintf(stderr
,
1907 "Usage: %s [-aAbd" D_FLAG
"efhH" I_FLAG J_FLAG
"KlLnNOpqRStu" U_FLAG
"vxX]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
1908 (void)fprintf(stderr
,
1909 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
1910 (void)fprintf(stderr
,
1911 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ]\n");
1912 (void)fprintf(stderr
,
1913 "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
1914 (void)fprintf(stderr
,
1915 "\t\t[ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
1916 (void)fprintf(stderr
,
1917 "\t\t[ -Z user ] [ expression ]\n");
1925 ndo_error(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1929 (void)fprintf(stderr
, "%s: ", program_name
);
1931 (void)vfprintf(stderr
, fmt
, ap
);
1935 if (fmt
[-1] != '\n')
1936 (void)fputc('\n', stderr
);
1944 ndo_warning(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1948 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
1950 (void)vfprintf(stderr
, fmt
, ap
);
1954 if (fmt
[-1] != '\n')
1955 (void)fputc('\n', stderr
);