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 static void ndo_warning(netdissect_options
*ndo
, const char *fmt
, ...);
122 RETSIGTYPE
requestinfo(int);
125 #if defined(USE_WIN32_MM_TIMER)
126 #include <MMsystem.h>
127 static UINT timer_id
;
128 static void CALLBACK
verbose_stats_dump(UINT
, UINT
, DWORD_PTR
, DWORD_PTR
, DWORD_PTR
);
129 #elif defined(HAVE_ALARM)
130 static void verbose_stats_dump(int sig
);
133 static void info(int);
134 static u_int packets_captured
;
148 static struct printer printers
[] = {
149 { arcnet_if_print
, DLT_ARCNET
},
150 #ifdef DLT_ARCNET_LINUX
151 { arcnet_linux_if_print
, DLT_ARCNET_LINUX
},
153 { token_if_print
, DLT_IEEE802
},
155 { lane_if_print
, DLT_LANE8023
},
158 { cip_if_print
, DLT_CIP
},
161 { cip_if_print
, DLT_ATM_CLIP
},
163 { sl_if_print
, DLT_SLIP
},
164 #ifdef DLT_SLIP_BSDOS
165 { sl_bsdos_if_print
, DLT_SLIP_BSDOS
},
167 { ppp_if_print
, DLT_PPP
},
168 #ifdef DLT_PPP_WITHDIRECTION
169 { ppp_if_print
, DLT_PPP_WITHDIRECTION
},
172 { ppp_bsdos_if_print
, DLT_PPP_BSDOS
},
174 { fddi_if_print
, DLT_FDDI
},
175 { null_if_print
, DLT_NULL
},
177 { null_if_print
, DLT_LOOP
},
179 { raw_if_print
, DLT_RAW
},
180 { atm_if_print
, DLT_ATM_RFC1483
},
182 { chdlc_if_print
, DLT_C_HDLC
},
185 { chdlc_if_print
, DLT_HDLC
},
187 #ifdef DLT_PPP_SERIAL
188 { ppp_hdlc_if_print
, DLT_PPP_SERIAL
},
191 { pppoe_if_print
, DLT_PPP_ETHER
},
194 { sll_if_print
, DLT_LINUX_SLL
},
196 #ifdef DLT_IEEE802_11
197 { ieee802_11_if_print
, DLT_IEEE802_11
},
200 { ltalk_if_print
, DLT_LTALK
},
202 #if defined(DLT_PFLOG) && defined(HAVE_NET_PFVAR_H)
203 { pflog_if_print
, DLT_PFLOG
},
206 { fr_if_print
, DLT_FR
},
209 { fr_if_print
, DLT_FRELAY
},
212 { sunatm_if_print
, DLT_SUNATM
},
214 #ifdef DLT_IP_OVER_FC
215 { ipfc_if_print
, DLT_IP_OVER_FC
},
217 #ifdef DLT_PRISM_HEADER
218 { prism_if_print
, DLT_PRISM_HEADER
},
220 #ifdef DLT_IEEE802_11_RADIO
221 { ieee802_11_radio_if_print
, DLT_IEEE802_11_RADIO
},
224 { enc_if_print
, DLT_ENC
},
226 #ifdef DLT_SYMANTEC_FIREWALL
227 { symantec_if_print
, DLT_SYMANTEC_FIREWALL
},
229 #ifdef DLT_APPLE_IP_OVER_IEEE1394
230 { ap1394_if_print
, DLT_APPLE_IP_OVER_IEEE1394
},
232 #ifdef DLT_IEEE802_11_RADIO_AVS
233 { ieee802_11_radio_avs_if_print
, DLT_IEEE802_11_RADIO_AVS
},
235 #ifdef DLT_JUNIPER_ATM1
236 { juniper_atm1_print
, DLT_JUNIPER_ATM1
},
238 #ifdef DLT_JUNIPER_ATM2
239 { juniper_atm2_print
, DLT_JUNIPER_ATM2
},
241 #ifdef DLT_JUNIPER_MFR
242 { juniper_mfr_print
, DLT_JUNIPER_MFR
},
244 #ifdef DLT_JUNIPER_MLFR
245 { juniper_mlfr_print
, DLT_JUNIPER_MLFR
},
247 #ifdef DLT_JUNIPER_MLPPP
248 { juniper_mlppp_print
, DLT_JUNIPER_MLPPP
},
250 #ifdef DLT_JUNIPER_PPPOE
251 { juniper_pppoe_print
, DLT_JUNIPER_PPPOE
},
253 #ifdef DLT_JUNIPER_PPPOE_ATM
254 { juniper_pppoe_atm_print
, DLT_JUNIPER_PPPOE_ATM
},
256 #ifdef DLT_JUNIPER_GGSN
257 { juniper_ggsn_print
, DLT_JUNIPER_GGSN
},
259 #ifdef DLT_JUNIPER_ES
260 { juniper_es_print
, DLT_JUNIPER_ES
},
262 #ifdef DLT_JUNIPER_MONITOR
263 { juniper_monitor_print
, DLT_JUNIPER_MONITOR
},
265 #ifdef DLT_JUNIPER_SERVICES
266 { juniper_services_print
, DLT_JUNIPER_SERVICES
},
268 #ifdef DLT_JUNIPER_ETHER
269 { juniper_ether_print
, DLT_JUNIPER_ETHER
},
271 #ifdef DLT_JUNIPER_PPP
272 { juniper_ppp_print
, DLT_JUNIPER_PPP
},
274 #ifdef DLT_JUNIPER_FRELAY
275 { juniper_frelay_print
, DLT_JUNIPER_FRELAY
},
277 #ifdef DLT_JUNIPER_CHDLC
278 { juniper_chdlc_print
, DLT_JUNIPER_CHDLC
},
281 { mfr_if_print
, DLT_MFR
},
283 #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
284 { bt_if_print
, DLT_BLUETOOTH_HCI_H4_WITH_PHDR
},
286 #ifdef HAVE_PCAP_USB_H
288 { usb_linux_48_byte_print
, DLT_USB_LINUX
},
289 #endif /* DLT_USB_LINUX */
290 #ifdef DLT_USB_LINUX_MMAPPED
291 { usb_linux_64_byte_print
, DLT_USB_LINUX_MMAPPED
},
292 #endif /* DLT_USB_LINUX_MMAPPED */
293 #endif /* HAVE_PCAP_USB_H */
295 { raw_if_print
, DLT_IPV4
},
298 { raw_if_print
, DLT_IPV6
},
303 static struct ndo_printer ndo_printers
[] = {
304 { ether_if_print
, DLT_EN10MB
},
306 { ipnet_if_print
, DLT_IPNET
},
308 #ifdef DLT_IEEE802_15_4
309 { ieee802_15_4_if_print
, DLT_IEEE802_15_4
},
311 #ifdef DLT_IEEE802_15_4_NOFCS
312 { ieee802_15_4_if_print
, DLT_IEEE802_15_4_NOFCS
},
315 { ppi_if_print
, DLT_PPI
},
321 lookup_printer(int type
)
325 for (p
= printers
; p
->f
; ++p
)
334 lookup_ndo_printer(int type
)
336 struct ndo_printer
*p
;
338 for (p
= ndo_printers
; p
->f
; ++p
)
348 static int supports_monitor_mode
;
355 netdissect_options
*ndo
;
358 if_ndo_printer ndo_printer
;
365 char *CurrentFileName
;
370 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
372 show_tstamp_types_and_exit(const char *device
, pcap_t
*pd
)
375 int *tstamp_types
= 0;
376 const char *tstamp_type_name
;
379 n_tstamp_types
= pcap_list_tstamp_types(pd
, &tstamp_types
);
380 if (n_tstamp_types
< 0)
381 error("%s", pcap_geterr(pd
));
383 if (n_tstamp_types
== 0) {
384 fprintf(stderr
, "Time stamp type cannot be set for %s\n",
388 fprintf(stderr
, "Time stamp types for %s (use option -j to set):\n",
390 for (i
= 0; i
< n_tstamp_types
; i
++) {
391 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
392 if (tstamp_type_name
!= NULL
) {
393 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
394 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
396 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
399 pcap_free_tstamp_types(tstamp_types
);
405 show_dlts_and_exit(const char *device
, pcap_t
*pd
)
409 const char *dlt_name
;
411 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
413 error("%s", pcap_geterr(pd
));
414 else if (n_dlts
== 0 || !dlts
)
415 error("No data link types.");
418 * If the interface is known to support monitor mode, indicate
419 * whether these are the data link types available when not in
420 * monitor mode, if -I wasn't specified, or when in monitor mode,
421 * when -I was specified (the link-layer types available in
422 * monitor mode might be different from the ones available when
423 * not in monitor mode).
425 if (supports_monitor_mode
)
426 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
428 Iflag
? "when in monitor mode" : "when not in monitor mode");
430 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
433 while (--n_dlts
>= 0) {
434 dlt_name
= pcap_datalink_val_to_name(dlts
[n_dlts
]);
435 if (dlt_name
!= NULL
) {
436 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
437 pcap_datalink_val_to_description(dlts
[n_dlts
]));
440 * OK, does tcpdump handle that type?
442 if (lookup_printer(dlts
[n_dlts
]) == NULL
443 && lookup_ndo_printer(dlts
[n_dlts
]) == NULL
)
444 (void) fprintf(stderr
, " (printing not supported)");
445 fprintf(stderr
, "\n");
447 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
451 pcap_free_datalinks(dlts
);
456 * Set up flags that might or might not be supported depending on the
457 * version of libpcap we're using.
459 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
461 #define B_FLAG_USAGE " [ -B size ]"
462 #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
465 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
467 #ifdef HAVE_PCAP_CREATE
469 #else /* HAVE_PCAP_CREATE */
471 #endif /* HAVE_PCAP_CREATE */
473 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
475 #define j_FLAG_USAGE " [ -j tstamptype ]"
477 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
481 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
483 #ifdef HAVE_PCAP_FINDALLDEVS
484 #ifndef HAVE_PCAP_IF_T
485 #undef HAVE_PCAP_FINDALLDEVS
489 #ifdef HAVE_PCAP_FINDALLDEVS
495 #ifdef HAVE_PCAP_DUMP_FLUSH
502 /* Drop root privileges and chroot if necessary */
504 droproot(const char *username
, const char *chroot_dir
)
506 struct passwd
*pw
= NULL
;
508 if (chroot_dir
&& !username
) {
509 fprintf(stderr
, "tcpdump: Chroot without dropping root is insecure\n");
513 pw
= getpwnam(username
);
516 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
517 fprintf(stderr
, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
518 chroot_dir
, pcap_strerror(errno
));
522 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
523 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
524 fprintf(stderr
, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
526 (unsigned long)pw
->pw_uid
,
527 (unsigned long)pw
->pw_gid
,
528 pcap_strerror(errno
));
533 fprintf(stderr
, "tcpdump: Couldn't find user '%.32s'\n",
556 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
558 char *filename
= malloc(NAME_MAX
+ 1);
560 /* Process with strftime if Gflag is set. */
564 /* Convert Gflag_time to a usable format */
565 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
566 error("MakeTimedFilename: localtime");
569 /* There's no good way to detect an error in strftime since a return
570 * value of 0 isn't necessarily failure.
572 strftime(filename
, NAME_MAX
, orig_name
, local_tm
);
574 strncpy(filename
, orig_name
, NAME_MAX
);
577 if (cnt
== 0 && max_chars
== 0)
578 strncpy(buffer
, filename
, NAME_MAX
+ 1);
580 if (snprintf(buffer
, NAME_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > NAME_MAX
)
581 /* Report an error if the filename is too large */
582 error("too many output files or filename is too long (> %d)", NAME_MAX
);
586 static int tcpdump_printf(netdissect_options
*ndo _U_
,
587 const char *fmt
, ...)
594 ret
=vfprintf(stdout
, fmt
, args
);
601 main(int argc
, char **argv
)
603 register int cnt
, op
, i
;
604 bpf_u_int32 localnet
, netmask
;
605 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *WFileName
;
606 pcap_handler callback
;
608 struct bpf_program fcode
;
610 RETSIGTYPE (*oldhandler
)(int);
612 struct print_info printinfo
;
613 struct dump_info dumpinfo
;
614 u_char
*pcap_userdata
;
615 char ebuf
[PCAP_ERRBUF_SIZE
];
616 char *username
= NULL
;
617 char *chroot_dir
= NULL
;
618 #ifdef HAVE_PCAP_FINDALLDEVS
619 pcap_if_t
*devpointer
;
624 if(wsockinit() != 0) return 1;
627 jflag
=-1; /* not set */
631 gndo
->ndo_default_print
=ndo_default_print
;
632 gndo
->ndo_printf
=tcpdump_printf
;
633 gndo
->ndo_error
=ndo_error
;
634 gndo
->ndo_warning
=ndo_warning
;
635 gndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
642 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
643 program_name
= cp
+ 1;
645 program_name
= argv
[0];
647 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
656 (op
= getopt(argc
, argv
, "aAb" B_FLAG
"c:C:d" D_FLAG
"eE:fF:G:hi:" I_FLAG j_FLAG J_FLAG
"KlLm:M:nNOpqr:Rs:StT:u" U_FLAG
"vw:W:xXy:Yz:Z:")) != -1)
660 /* compatibility for old -a */
671 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
673 Bflag
= atoi(optarg
)*1024;
675 error("invalid packet buffer size %s", optarg
);
677 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
682 error("invalid packet count %s", optarg
);
686 Cflag
= atoi(optarg
) * 1000000;
688 error("invalid file size %s", optarg
);
695 #ifdef HAVE_PCAP_FINDALLDEVS
697 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
700 for (i
= 0; devpointer
!= 0; i
++) {
701 printf("%d.%s", i
+1, devpointer
->name
);
702 if (devpointer
->description
!= NULL
)
703 printf(" (%s)", devpointer
->description
);
705 devpointer
= devpointer
->next
;
709 #endif /* HAVE_PCAP_FINDALLDEVS */
720 #ifndef HAVE_LIBCRYPTO
721 warning("crypto code not compiled in");
723 gndo
->ndo_espsecret
= optarg
;
735 Gflag
= atoi(optarg
);
737 error("invalid number of seconds %s", optarg
);
739 /* We will create one file initially. */
742 /* Grab the current time for rotation use. */
743 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
744 error("main: can't get current time: %s",
745 pcap_strerror(errno
));
754 if (optarg
[0] == '0' && optarg
[1] == 0)
755 error("Invalid adapter index");
757 #ifdef HAVE_PCAP_FINDALLDEVS
759 * If the argument is a number, treat it as
760 * an index into the list of adapters, as
761 * printed by "tcpdump -D".
763 * This should be OK on UNIX systems, as interfaces
764 * shouldn't have names that begin with digits.
765 * It can be useful on Windows, where more than
766 * one interface can have the same name.
768 if ((devnum
= atoi(optarg
)) != 0) {
770 error("Invalid adapter index");
772 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
776 * Look for the devnum-th entry
777 * in the list of devices
781 i
< devnum
-1 && devpointer
!= NULL
;
782 i
++, devpointer
= devpointer
->next
)
784 if (devpointer
== NULL
)
785 error("Invalid adapter index");
787 device
= devpointer
->name
;
790 #endif /* HAVE_PCAP_FINDALLDEVS */
794 #ifdef HAVE_PCAP_CREATE
798 #endif /* HAVE_PCAP_CREATE */
800 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
802 jflag
= pcap_tstamp_type_name_to_val(optarg
);
804 error("invalid time stamp type %s", optarg
);
815 * _IOLBF is the same as _IOFBF in Microsoft's C
816 * libraries; the only alternative they offer
819 * XXX - this should really be checking for MSVC++,
820 * not WIN32, if, for example, MinGW has its own
821 * C library that is more UNIX-compatible.
823 setvbuf(stdout
, NULL
, _IONBF
, 0);
825 #ifdef HAVE_SETLINEBUF
828 setvbuf(stdout
, NULL
, _IOLBF
, 0);
839 if (smiLoadModule(optarg
) == 0) {
840 error("could not load MIB module %s", optarg
);
844 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
845 program_name
, optarg
);
846 (void)fprintf(stderr
, "(no libsmi support)\n");
851 /* TCP-MD5 shared secret */
852 #ifndef HAVE_LIBCRYPTO
853 warning("crypto code not compiled in");
876 ++suppress_default_print
;
890 snaplen
= strtol(optarg
, &end
, 0);
891 if (optarg
== end
|| *end
!= '\0'
892 || snaplen
< 0 || snaplen
> MAXIMUM_SNAPLEN
)
893 error("invalid snaplen %s", optarg
);
894 else if (snaplen
== 0)
895 snaplen
= MAXIMUM_SNAPLEN
;
908 if (strcasecmp(optarg
, "vat") == 0)
910 else if (strcasecmp(optarg
, "wb") == 0)
912 else if (strcasecmp(optarg
, "rpc") == 0)
914 else if (strcasecmp(optarg
, "rtp") == 0)
916 else if (strcasecmp(optarg
, "rtcp") == 0)
917 packettype
= PT_RTCP
;
918 else if (strcasecmp(optarg
, "snmp") == 0)
919 packettype
= PT_SNMP
;
920 else if (strcasecmp(optarg
, "cnfp") == 0)
921 packettype
= PT_CNFP
;
922 else if (strcasecmp(optarg
, "tftp") == 0)
923 packettype
= PT_TFTP
;
924 else if (strcasecmp(optarg
, "aodv") == 0)
925 packettype
= PT_AODV
;
927 error("unknown packet type `%s'", optarg
);
934 #ifdef HAVE_PCAP_DUMP_FLUSH
949 Wflag
= atoi(optarg
);
951 error("invalid number of output files %s", optarg
);
952 WflagChars
= getWflagChars(Wflag
);
957 ++suppress_default_print
;
962 ++suppress_default_print
;
966 gndo
->ndo_dltname
= optarg
;
968 pcap_datalink_name_to_val(gndo
->ndo_dltname
);
969 if (gndo
->ndo_dlt
< 0)
970 error("invalid data link type %s", gndo
->ndo_dltname
);
973 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
976 /* Undocumented flag */
977 #ifdef HAVE_PCAP_DEBUG
978 extern int pcap_debug
;
989 zflag
= strdup(optarg
);
998 username
= strdup(optarg
);
1013 case 0: /* Default */
1014 case 4: /* Default + Date*/
1015 thiszone
= gmt2local(0);
1018 case 1: /* No time stamp */
1019 case 2: /* Unix timeval style */
1020 case 3: /* Microseconds since previous packet */
1021 case 5: /* Microseconds since first packet */
1024 default: /* Not supported */
1025 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1030 /* if run as root, prepare for chrooting */
1031 if (getuid() == 0 || geteuid() == 0) {
1032 /* future extensibility for cmd-line arguments */
1034 chroot_dir
= WITH_CHROOT
;
1039 /* if run as root, prepare for dropping root privileges */
1040 if (getuid() == 0 || geteuid() == 0) {
1041 /* Run with '-Z root' to restore old behaviour */
1043 username
= WITH_USER
;
1047 if (RFileName
!= NULL
) {
1049 const char *dlt_name
;
1053 * We don't need network access, so relinquish any set-UID
1054 * or set-GID privileges we have (if any).
1056 * We do *not* want set-UID privileges when opening a
1057 * trace file, as that might let the user read other
1058 * people's trace files (especially if we're set-UID
1061 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1062 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1064 pd
= pcap_open_offline(RFileName
, ebuf
);
1067 dlt
= pcap_datalink(pd
);
1068 dlt_name
= pcap_datalink_val_to_name(dlt
);
1069 if (dlt_name
== NULL
) {
1070 fprintf(stderr
, "reading from file %s, link-type %u\n",
1074 "reading from file %s, link-type %s (%s)\n",
1075 RFileName
, dlt_name
,
1076 pcap_datalink_val_to_description(dlt
));
1081 error("-f and -r options are incompatible");
1083 if (device
== NULL
) {
1084 device
= pcap_lookupdev(ebuf
);
1089 if(strlen(device
) == 1) //we assume that an ASCII string is always longer than 1 char
1090 { //a Unicode string has a \0 as second byte (so strlen() is 1)
1091 fprintf(stderr
, "%s: listening on %ws\n", program_name
, device
);
1095 fprintf(stderr
, "%s: listening on %s\n", program_name
, device
);
1100 #ifdef HAVE_PCAP_CREATE
1101 pd
= pcap_create(device
, ebuf
);
1104 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1106 show_tstamp_types_and_exit(device
, pd
);
1109 * Is this an interface that supports monitor mode?
1111 if (pcap_can_set_rfmon(pd
) == 1)
1112 supports_monitor_mode
= 1;
1114 supports_monitor_mode
= 0;
1115 status
= pcap_set_snaplen(pd
, snaplen
);
1117 error("%s: Can't set snapshot length: %s",
1118 device
, pcap_statustostr(status
));
1119 status
= pcap_set_promisc(pd
, !pflag
);
1121 error("%s: Can't set promiscuous mode: %s",
1122 device
, pcap_statustostr(status
));
1124 status
= pcap_set_rfmon(pd
, 1);
1126 error("%s: Can't set monitor mode: %s",
1127 device
, pcap_statustostr(status
));
1129 status
= pcap_set_timeout(pd
, 1000);
1131 error("%s: pcap_set_timeout failed: %s",
1132 device
, pcap_statustostr(status
));
1134 status
= pcap_set_buffer_size(pd
, Bflag
);
1136 error("%s: Can't set buffer size: %s",
1137 device
, pcap_statustostr(status
));
1139 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1141 status
= pcap_set_tstamp_type(pd
, jflag
);
1143 error("%s: Can't set time stamp type: %s",
1144 device
, pcap_statustostr(status
));
1147 status
= pcap_activate(pd
);
1150 * pcap_activate() failed.
1152 cp
= pcap_geterr(pd
);
1153 if (status
== PCAP_ERROR
)
1155 else if ((status
== PCAP_ERROR_NO_SUCH_DEVICE
||
1156 status
== PCAP_ERROR_PERM_DENIED
) &&
1158 error("%s: %s\n(%s)", device
,
1159 pcap_statustostr(status
), cp
);
1161 error("%s: %s", device
,
1162 pcap_statustostr(status
));
1163 } else if (status
> 0) {
1165 * pcap_activate() succeeded, but it's warning us
1166 * of a problem it had.
1168 cp
= pcap_geterr(pd
);
1169 if (status
== PCAP_WARNING
)
1171 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1173 warning("%s: %s\n(%s)", device
,
1174 pcap_statustostr(status
), cp
);
1176 warning("%s: %s", device
,
1177 pcap_statustostr(status
));
1181 pd
= pcap_open_live(device
, snaplen
, !pflag
, 1000, ebuf
);
1185 warning("%s", ebuf
);
1186 #endif /* HAVE_PCAP_CREATE */
1188 * Let user own process after socket has been opened.
1191 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1192 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1194 #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
1196 if(pcap_setbuff(pd
, Bflag
)==-1){
1197 error("%s", pcap_geterr(pd
));
1199 #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
1201 show_dlts_and_exit(device
, pd
);
1202 if (gndo
->ndo_dlt
>= 0) {
1203 #ifdef HAVE_PCAP_SET_DATALINK
1204 if (pcap_set_datalink(pd
, gndo
->ndo_dlt
) < 0)
1205 error("%s", pcap_geterr(pd
));
1208 * We don't actually support changing the
1209 * data link type, so we only let them
1210 * set it to what it already is.
1212 if (gndo
->ndo_dlt
!= pcap_datalink(pd
)) {
1213 error("%s is not one of the DLTs supported by this device\n",
1217 (void)fprintf(stderr
, "%s: data link type %s\n",
1218 program_name
, gndo
->ndo_dltname
);
1219 (void)fflush(stderr
);
1221 i
= pcap_snapshot(pd
);
1223 warning("snaplen raised from %d to %d", snaplen
, i
);
1226 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1229 warning("%s", ebuf
);
1233 cmdbuf
= read_infile(infile
);
1235 cmdbuf
= copy_argv(&argv
[optind
]);
1237 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1238 error("%s", pcap_geterr(pd
));
1241 bpf_dump(&fcode
, dflag
);
1245 init_addrtoname(localnet
, netmask
);
1249 (void)setsignal(SIGPIPE
, cleanup
);
1250 (void)setsignal(SIGTERM
, cleanup
);
1251 (void)setsignal(SIGINT
, cleanup
);
1253 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1254 (void)setsignal(SIGCHLD
, child_cleanup
);
1256 /* Cooperate with nohup(1) */
1258 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1259 (void)setsignal(SIGHUP
, oldhandler
);
1264 * If a user name was specified with "-Z", attempt to switch to
1265 * that user's UID. This would probably be used with sudo,
1266 * to allow tcpdump to be run in a special restricted
1267 * account (if you just want to allow users to open capture
1268 * devices, and can't just give users that permission,
1269 * you'd make tcpdump set-UID or set-GID).
1271 * Tcpdump doesn't necessarily write only to one savefile;
1272 * the general only way to allow a -Z instance to write to
1273 * savefiles as the user under whose UID it's run, rather
1274 * than as the user specified with -Z, would thus be to switch
1275 * to the original user ID before opening a capture file and
1276 * then switch back to the -Z user ID after opening the savefile.
1277 * Switching to the -Z user ID only after opening the first
1278 * savefile doesn't handle the general case.
1280 if (getuid() == 0 || geteuid() == 0) {
1281 if (username
|| chroot_dir
)
1282 droproot(username
, chroot_dir
);
1286 if (pcap_setfilter(pd
, &fcode
) < 0)
1287 error("%s", pcap_geterr(pd
));
1290 /* Do not exceed the default NAME_MAX for files. */
1291 dumpinfo
.CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1293 if (dumpinfo
.CurrentFileName
== NULL
)
1294 error("malloc of dumpinfo.CurrentFileName");
1296 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1298 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1300 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1302 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1304 error("%s", pcap_geterr(pd
));
1305 if (Cflag
!= 0 || Gflag
!= 0) {
1306 callback
= dump_packet_and_trunc
;
1307 dumpinfo
.WFileName
= WFileName
;
1310 pcap_userdata
= (u_char
*)&dumpinfo
;
1312 callback
= dump_packet
;
1313 pcap_userdata
= (u_char
*)p
;
1315 #ifdef HAVE_PCAP_DUMP_FLUSH
1320 type
= pcap_datalink(pd
);
1321 printinfo
.ndo_type
= 1;
1322 printinfo
.ndo
= gndo
;
1323 printinfo
.p
.ndo_printer
= lookup_ndo_printer(type
);
1324 if (printinfo
.p
.ndo_printer
== NULL
) {
1325 printinfo
.p
.printer
= lookup_printer(type
);
1326 printinfo
.ndo_type
= 0;
1327 if (printinfo
.p
.printer
== NULL
) {
1328 gndo
->ndo_dltname
= pcap_datalink_val_to_name(type
);
1329 if (gndo
->ndo_dltname
!= NULL
)
1330 error("packet printing is not supported for link type %s: use -w",
1333 error("packet printing is not supported for link type %d: use -w", type
);
1336 callback
= print_packet
;
1337 pcap_userdata
= (u_char
*)&printinfo
;
1342 * We can't get statistics when reading from a file rather
1343 * than capturing from a device.
1345 if (RFileName
== NULL
)
1346 (void)setsignal(SIGINFO
, requestinfo
);
1349 if (vflag
> 0 && WFileName
) {
1351 * When capturing to a file, "-v" means tcpdump should,
1352 * every 10 secodns, "v"erbosely report the number of
1355 #ifdef USE_WIN32_MM_TIMER
1356 /* call verbose_stats_dump() each 1000 +/-100msec */
1357 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1358 setvbuf(stderr
, NULL
, _IONBF
, 0);
1359 #elif defined(HAVE_ALARM)
1360 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1366 if (RFileName
== NULL
) {
1368 const char *dlt_name
;
1370 if (!vflag
&& !WFileName
) {
1371 (void)fprintf(stderr
,
1372 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1375 (void)fprintf(stderr
, "%s: ", program_name
);
1376 dlt
= pcap_datalink(pd
);
1377 dlt_name
= pcap_datalink_val_to_name(dlt
);
1378 if (dlt_name
== NULL
) {
1379 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1380 device
, dlt
, snaplen
);
1382 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1384 pcap_datalink_val_to_description(dlt
), snaplen
);
1386 (void)fflush(stderr
);
1389 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1390 if (WFileName
== NULL
) {
1392 * We're printing packets. Flush the printed output,
1393 * so it doesn't get intermingled with error output.
1397 * We got interrupted, so perhaps we didn't
1398 * manage to finish a line we were printing.
1399 * Print an extra newline, just in case.
1403 (void)fflush(stdout
);
1409 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
1410 program_name
, pcap_geterr(pd
));
1412 if (RFileName
== NULL
) {
1414 * We're doing a live capture. Report the capture
1420 exit(status
== -1 ? 1 : 0);
1423 /* make a clean exit on interrupts */
1425 cleanup(int signo _U_
)
1427 #ifdef USE_WIN32_MM_TIMER
1429 timeKillEvent(timer_id
);
1431 #elif defined(HAVE_ALARM)
1435 #ifdef HAVE_PCAP_BREAKLOOP
1437 * We have "pcap_breakloop()"; use it, so that we do as little
1438 * as possible in the signal handler (it's probably not safe
1439 * to do anything with standard I/O streams in a signal handler -
1440 * the ANSI C standard doesn't say it is).
1445 * We don't have "pcap_breakloop()"; this isn't safe, but
1446 * it's the best we can do. Print the summary if we're
1447 * not reading from a savefile - i.e., if we're doing a
1448 * live capture - and exit.
1450 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
1452 * We got interrupted, so perhaps we didn't
1453 * manage to finish a line we were printing.
1454 * Print an extra newline, just in case.
1457 (void)fflush(stdout
);
1465 On windows, we do not use a fork, so we do not care less about
1466 waiting a child processes to die
1468 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1470 child_cleanup(int signo _U_
)
1474 #endif /* HAVE_FORK && HAVE_VFORK */
1477 info(register int verbose
)
1479 struct pcap_stat stat
;
1482 * Older versions of libpcap didn't set ps_ifdrop on some
1483 * platforms; initialize it to 0 to handle that.
1486 if (pcap_stats(pd
, &stat
) < 0) {
1487 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
1493 fprintf(stderr
, "%s: ", program_name
);
1495 (void)fprintf(stderr
, "%u packet%s captured", packets_captured
,
1496 PLURAL_SUFFIX(packets_captured
));
1498 fputs(", ", stderr
);
1501 (void)fprintf(stderr
, "%u packet%s received by filter", stat
.ps_recv
,
1502 PLURAL_SUFFIX(stat
.ps_recv
));
1504 fputs(", ", stderr
);
1507 (void)fprintf(stderr
, "%u packet%s dropped by kernel", stat
.ps_drop
,
1508 PLURAL_SUFFIX(stat
.ps_drop
));
1509 if (stat
.ps_ifdrop
!= 0) {
1511 fputs(", ", stderr
);
1514 (void)fprintf(stderr
, "%u packet%s dropped by interface\n",
1515 stat
.ps_ifdrop
, PLURAL_SUFFIX(stat
.ps_ifdrop
));
1521 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1523 compress_savefile(const char *filename
)
1532 * Set to lowest priority so that this doesn't disturb the capture
1535 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
1537 setpriority(PRIO_PROCESS
, 0, 19);
1539 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
1541 "compress_savefile:execlp(%s, %s): %s\n",
1551 #else /* HAVE_FORK && HAVE_VFORK */
1553 compress_savefile(const char *filename
)
1556 "compress_savefile failed. Functionality not implemented under your system\n");
1558 #endif /* HAVE_FORK && HAVE_VFORK */
1561 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1563 struct dump_info
*dump_info
;
1569 dump_info
= (struct dump_info
*)user
;
1572 * XXX - this won't force the file to rotate on the specified time
1573 * boundary, but it will rotate on the first packet received after the
1574 * specified Gflag number of seconds. Note: if a Gflag time boundary
1575 * and a Cflag size boundary coincide, the time rotation will occur
1576 * first thereby cancelling the Cflag boundary (since the file should
1580 /* Check if it is time to rotate */
1583 /* Get the current time */
1584 if ((t
= time(NULL
)) == (time_t)-1) {
1585 error("dump_and_trunc_packet: can't get current_time: %s",
1586 pcap_strerror(errno
));
1590 /* If the time is greater than the specified window, rotate */
1591 if (t
- Gflag_time
>= Gflag
) {
1592 /* Update the Gflag_time */
1594 /* Update Gflag_count */
1597 * Close the current file and open a new one.
1599 pcap_dump_close(dump_info
->p
);
1602 * Compress the file we just closed, if the user asked for it
1605 compress_savefile(dump_info
->CurrentFileName
);
1608 * Check to see if we've exceeded the Wflag (when
1611 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
1612 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
1617 if (dump_info
->CurrentFileName
!= NULL
)
1618 free(dump_info
->CurrentFileName
);
1619 /* Allocate space for max filename + \0. */
1620 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1621 if (dump_info
->CurrentFileName
== NULL
)
1622 error("dump_packet_and_trunc: malloc");
1624 * This is always the first file in the Cflag
1626 * We also don't need numbering if Cflag is not set.
1629 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
1632 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
1634 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1635 if (dump_info
->p
== NULL
)
1636 error("%s", pcap_geterr(pd
));
1641 * XXX - this won't prevent capture files from getting
1642 * larger than Cflag - the last packet written to the
1643 * file could put it over Cflag.
1645 if (Cflag
!= 0 && pcap_dump_ftell(dump_info
->p
) > Cflag
) {
1647 * Close the current file and open a new one.
1649 pcap_dump_close(dump_info
->p
);
1652 * Compress the file we just closed, if the user asked for it
1655 compress_savefile(dump_info
->CurrentFileName
);
1659 if (Cflag_count
>= Wflag
)
1662 if (dump_info
->CurrentFileName
!= NULL
)
1663 free(dump_info
->CurrentFileName
);
1664 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1665 if (dump_info
->CurrentFileName
== NULL
)
1666 error("dump_packet_and_trunc: malloc");
1667 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
1668 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1669 if (dump_info
->p
== NULL
)
1670 error("%s", pcap_geterr(pd
));
1673 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
1674 #ifdef HAVE_PCAP_DUMP_FLUSH
1676 pcap_dump_flush(dump_info
->p
);
1685 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1691 pcap_dump(user
, h
, sp
);
1692 #ifdef HAVE_PCAP_DUMP_FLUSH
1694 pcap_dump_flush((pcap_dumper_t
*)user
);
1703 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1705 struct print_info
*print_info
;
1713 print_info
= (struct print_info
*)user
;
1716 * Some printers want to check that they're not walking off the
1717 * end of the packet.
1718 * Rather than pass it all the way down, we set this global.
1720 snapend
= sp
+ h
->caplen
;
1722 if(print_info
->ndo_type
) {
1723 hdrlen
= (*print_info
->p
.ndo_printer
)(print_info
->ndo
, h
, sp
);
1725 hdrlen
= (*print_info
->p
.printer
)(h
, sp
);
1730 * Print the raw packet data in hex and ASCII.
1734 * Include the link-layer header.
1736 hex_and_ascii_print("\n\t", sp
, h
->caplen
);
1739 * Don't include the link-layer header - and if
1740 * we have nothing past the link-layer header,
1743 if (h
->caplen
> hdrlen
)
1744 hex_and_ascii_print("\n\t", sp
+ hdrlen
,
1745 h
->caplen
- hdrlen
);
1749 * Print the raw packet data in hex.
1753 * Include the link-layer header.
1755 hex_print("\n\t", sp
, h
->caplen
);
1758 * Don't include the link-layer header - and if
1759 * we have nothing past the link-layer header,
1762 if (h
->caplen
> hdrlen
)
1763 hex_print("\n\t", sp
+ hdrlen
,
1764 h
->caplen
- hdrlen
);
1768 * Print the raw packet data in ASCII.
1772 * Include the link-layer header.
1774 ascii_print(sp
, h
->caplen
);
1777 * Don't include the link-layer header - and if
1778 * we have nothing past the link-layer header,
1781 if (h
->caplen
> hdrlen
)
1782 ascii_print(sp
+ hdrlen
, h
->caplen
- hdrlen
);
1795 * XXX - there should really be libpcap calls to get the version
1796 * number as a string (the string would be generated from #defines
1797 * at run time, so that it's not generated from string constants
1798 * in the library, as, on many UNIX systems, those constants would
1799 * be statically linked into the application executable image, and
1800 * would thus reflect the version of libpcap on the system on
1801 * which the application was *linked*, not the system on which it's
1804 * That routine should be documented, unlike the "version[]"
1805 * string, so that UNIX vendors providing their own libpcaps
1806 * don't omit it (as a couple of vendors have...).
1808 * Packet.dll should perhaps also export a routine to return the
1809 * version number of the Packet.dll code, to supply the
1810 * "Wpcap_version" information on Windows.
1812 char WDversion
[]="current-cvs.tcpdump.org";
1813 #if !defined(HAVE_GENERATED_VERSION)
1814 char version
[]="current-cvs.tcpdump.org";
1816 char pcap_version
[]="current-cvs.tcpdump.org";
1817 char Wpcap_version
[]="3.1";
1821 * By default, print the specified data out in hex and ASCII.
1824 ndo_default_print(netdissect_options
*ndo _U_
, const u_char
*bp
, u_int length
)
1826 hex_and_ascii_print("\n\t", bp
, length
); /* pass on lf and identation string */
1830 default_print(const u_char
*bp
, u_int length
)
1832 ndo_default_print(gndo
, bp
, length
);
1836 RETSIGTYPE
requestinfo(int signo _U_
)
1846 * Called once each second in verbose mode while dumping to file
1848 #ifdef USE_WIN32_MM_TIMER
1849 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
1850 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
1852 struct pcap_stat stat
;
1854 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1855 fprintf(stderr
, "Got %u\r", packets_captured
);
1857 #elif defined(HAVE_ALARM)
1858 static void verbose_stats_dump(int sig _U_
)
1860 struct pcap_stat stat
;
1862 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1863 fprintf(stderr
, "Got %u\r", packets_captured
);
1871 extern char version
[];
1872 #ifndef HAVE_PCAP_LIB_VERSION
1873 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
1874 extern char pcap_version
[];
1875 #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1876 static char pcap_version
[] = "unknown";
1877 #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1878 #endif /* HAVE_PCAP_LIB_VERSION */
1880 #ifdef HAVE_PCAP_LIB_VERSION
1882 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1884 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1886 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
1887 #else /* HAVE_PCAP_LIB_VERSION */
1889 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1890 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
1892 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1893 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
1895 #endif /* HAVE_PCAP_LIB_VERSION */
1896 (void)fprintf(stderr
,
1897 "Usage: %s [-aAbd" D_FLAG
"efh" I_FLAG J_FLAG
"KlLnNOpqRStu" U_FLAG
"vxX]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
1898 (void)fprintf(stderr
,
1899 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
1900 (void)fprintf(stderr
,
1901 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ]\n");
1902 (void)fprintf(stderr
,
1903 "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
1904 (void)fprintf(stderr
,
1905 "\t\t[ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
1906 (void)fprintf(stderr
,
1907 "\t\t[ -Z user ] [ expression ]\n");
1915 ndo_error(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1919 (void)fprintf(stderr
, "%s: ", program_name
);
1921 (void)vfprintf(stderr
, fmt
, ap
);
1925 if (fmt
[-1] != '\n')
1926 (void)fputc('\n', stderr
);
1934 ndo_warning(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1938 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
1940 (void)vfprintf(stderr
, fmt
, ap
);
1944 if (fmt
[-1] != '\n')
1945 (void)fputc('\n', stderr
);