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
;
136 typedef u_int (*if_printer
)(const struct pcap_pkthdr
*, const u_char
*);
137 typedef u_int (*if_ndo_printer
)(struct netdissect_options
*ndo
,
138 const struct pcap_pkthdr
*, const u_char
*);
152 static struct printer printers
[] = {
153 { arcnet_if_print
, DLT_ARCNET
},
154 #ifdef DLT_ARCNET_LINUX
155 { arcnet_linux_if_print
, DLT_ARCNET_LINUX
},
157 { ether_if_print
, DLT_EN10MB
},
158 { token_if_print
, DLT_IEEE802
},
160 { lane_if_print
, DLT_LANE8023
},
163 { cip_if_print
, DLT_CIP
},
166 { cip_if_print
, DLT_ATM_CLIP
},
168 { sl_if_print
, DLT_SLIP
},
169 #ifdef DLT_SLIP_BSDOS
170 { sl_bsdos_if_print
, DLT_SLIP_BSDOS
},
172 { ppp_if_print
, DLT_PPP
},
173 #ifdef DLT_PPP_WITHDIRECTION
174 { ppp_if_print
, DLT_PPP_WITHDIRECTION
},
177 { ppp_bsdos_if_print
, DLT_PPP_BSDOS
},
179 { fddi_if_print
, DLT_FDDI
},
180 { null_if_print
, DLT_NULL
},
182 { null_if_print
, DLT_LOOP
},
184 { raw_if_print
, DLT_RAW
},
185 { atm_if_print
, DLT_ATM_RFC1483
},
187 { chdlc_if_print
, DLT_C_HDLC
},
190 { chdlc_if_print
, DLT_HDLC
},
192 #ifdef DLT_PPP_SERIAL
193 { ppp_hdlc_if_print
, DLT_PPP_SERIAL
},
196 { pppoe_if_print
, DLT_PPP_ETHER
},
199 { sll_if_print
, DLT_LINUX_SLL
},
201 #ifdef DLT_IEEE802_11
202 { ieee802_11_if_print
, DLT_IEEE802_11
},
205 { ltalk_if_print
, DLT_LTALK
},
207 #if defined(DLT_PFLOG) && defined(HAVE_NET_PFVAR_H)
208 { pflog_if_print
, DLT_PFLOG
},
211 { fr_if_print
, DLT_FR
},
214 { fr_if_print
, DLT_FRELAY
},
217 { sunatm_if_print
, DLT_SUNATM
},
219 #ifdef DLT_IP_OVER_FC
220 { ipfc_if_print
, DLT_IP_OVER_FC
},
222 #ifdef DLT_PRISM_HEADER
223 { prism_if_print
, DLT_PRISM_HEADER
},
225 #ifdef DLT_IEEE802_11_RADIO
226 { ieee802_11_radio_if_print
, DLT_IEEE802_11_RADIO
},
229 { enc_if_print
, DLT_ENC
},
231 #ifdef DLT_SYMANTEC_FIREWALL
232 { symantec_if_print
, DLT_SYMANTEC_FIREWALL
},
234 #ifdef DLT_APPLE_IP_OVER_IEEE1394
235 { ap1394_if_print
, DLT_APPLE_IP_OVER_IEEE1394
},
237 #ifdef DLT_IEEE802_11_RADIO_AVS
238 { ieee802_11_radio_avs_if_print
, DLT_IEEE802_11_RADIO_AVS
},
240 #ifdef DLT_JUNIPER_ATM1
241 { juniper_atm1_print
, DLT_JUNIPER_ATM1
},
243 #ifdef DLT_JUNIPER_ATM2
244 { juniper_atm2_print
, DLT_JUNIPER_ATM2
},
246 #ifdef DLT_JUNIPER_MFR
247 { juniper_mfr_print
, DLT_JUNIPER_MFR
},
249 #ifdef DLT_JUNIPER_MLFR
250 { juniper_mlfr_print
, DLT_JUNIPER_MLFR
},
252 #ifdef DLT_JUNIPER_MLPPP
253 { juniper_mlppp_print
, DLT_JUNIPER_MLPPP
},
255 #ifdef DLT_JUNIPER_PPPOE
256 { juniper_pppoe_print
, DLT_JUNIPER_PPPOE
},
258 #ifdef DLT_JUNIPER_PPPOE_ATM
259 { juniper_pppoe_atm_print
, DLT_JUNIPER_PPPOE_ATM
},
261 #ifdef DLT_JUNIPER_GGSN
262 { juniper_ggsn_print
, DLT_JUNIPER_GGSN
},
264 #ifdef DLT_JUNIPER_ES
265 { juniper_es_print
, DLT_JUNIPER_ES
},
267 #ifdef DLT_JUNIPER_MONITOR
268 { juniper_monitor_print
, DLT_JUNIPER_MONITOR
},
270 #ifdef DLT_JUNIPER_SERVICES
271 { juniper_services_print
, DLT_JUNIPER_SERVICES
},
273 #ifdef DLT_JUNIPER_ETHER
274 { juniper_ether_print
, DLT_JUNIPER_ETHER
},
276 #ifdef DLT_JUNIPER_PPP
277 { juniper_ppp_print
, DLT_JUNIPER_PPP
},
279 #ifdef DLT_JUNIPER_FRELAY
280 { juniper_frelay_print
, DLT_JUNIPER_FRELAY
},
282 #ifdef DLT_JUNIPER_CHDLC
283 { juniper_chdlc_print
, DLT_JUNIPER_CHDLC
},
286 { mfr_if_print
, DLT_MFR
},
288 #if defined(DLT_BLUETOOTH_HCI_H4_WITH_PHDR) && defined(HAVE_PCAP_BLUETOOTH_H)
289 { bt_if_print
, DLT_BLUETOOTH_HCI_H4_WITH_PHDR
},
291 #ifdef HAVE_PCAP_USB_H
293 { usb_linux_48_byte_print
, DLT_USB_LINUX
},
294 #endif /* DLT_USB_LINUX */
295 #ifdef DLT_USB_LINUX_MMAPPED
296 { usb_linux_64_byte_print
, DLT_USB_LINUX_MMAPPED
},
297 #endif /* DLT_USB_LINUX_MMAPPED */
298 #endif /* HAVE_PCAP_USB_H */
300 { raw_if_print
, DLT_IPV4
},
303 { raw_if_print
, DLT_IPV6
},
308 static struct ndo_printer ndo_printers
[] = {
310 { ipnet_if_print
, DLT_IPNET
},
316 lookup_printer(int type
)
320 for (p
= printers
; p
->f
; ++p
)
328 static if_ndo_printer
329 lookup_ndo_printer(int type
)
331 struct ndo_printer
*p
;
333 for (p
= ndo_printers
; p
->f
; ++p
)
343 static int supports_monitor_mode
;
350 netdissect_options
*ndo
;
353 if_ndo_printer ndo_printer
;
360 char *CurrentFileName
;
365 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
367 show_tstamp_types_and_exit(const char *device
, pcap_t
*pd
)
370 int *tstamp_types
= 0;
371 const char *tstamp_type_name
;
374 n_tstamp_types
= pcap_list_tstamp_types(pd
, &tstamp_types
);
375 if (n_tstamp_types
< 0)
376 error("%s", pcap_geterr(pd
));
378 if (n_tstamp_types
== 0) {
379 fprintf(stderr
, "Time stamp type cannot be set for %s\n",
383 fprintf(stderr
, "Time stamp types for %s (use option -j to set):\n",
385 for (i
= 0; i
< n_tstamp_types
; i
++) {
386 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
387 if (tstamp_type_name
!= NULL
) {
388 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
389 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
391 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
394 pcap_free_tstamp_types(tstamp_types
);
400 show_dlts_and_exit(const char *device
, pcap_t
*pd
)
404 const char *dlt_name
;
406 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
408 error("%s", pcap_geterr(pd
));
409 else if (n_dlts
== 0 || !dlts
)
410 error("No data link types.");
413 * If the interface is known to support monitor mode, indicate
414 * whether these are the data link types available when not in
415 * monitor mode, if -I wasn't specified, or when in monitor mode,
416 * when -I was specified (the link-layer types available in
417 * monitor mode might be different from the ones available when
418 * not in monitor mode).
420 if (supports_monitor_mode
)
421 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
423 Iflag
? "when in monitor mode" : "when not in monitor mode");
425 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
428 while (--n_dlts
>= 0) {
429 dlt_name
= pcap_datalink_val_to_name(dlts
[n_dlts
]);
430 if (dlt_name
!= NULL
) {
431 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
432 pcap_datalink_val_to_description(dlts
[n_dlts
]));
435 * OK, does tcpdump handle that type?
437 if (lookup_printer(dlts
[n_dlts
]) == NULL
438 && lookup_ndo_printer(dlts
[n_dlts
]) == NULL
)
439 (void) fprintf(stderr
, " (printing not supported)");
440 fprintf(stderr
, "\n");
442 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
446 pcap_free_datalinks(dlts
);
451 * Set up flags that might or might not be supported depending on the
452 * version of libpcap we're using.
454 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
456 #define B_FLAG_USAGE " [ -B size ]"
457 #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
460 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
462 #ifdef HAVE_PCAP_CREATE
464 #else /* HAVE_PCAP_CREATE */
466 #endif /* HAVE_PCAP_CREATE */
468 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
470 #define j_FLAG_USAGE " [ -j tstamptype ]"
472 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
476 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
478 #ifdef HAVE_PCAP_FINDALLDEVS
479 #ifndef HAVE_PCAP_IF_T
480 #undef HAVE_PCAP_FINDALLDEVS
484 #ifdef HAVE_PCAP_FINDALLDEVS
490 #ifdef HAVE_PCAP_DUMP_FLUSH
497 /* Drop root privileges and chroot if necessary */
499 droproot(const char *username
, const char *chroot_dir
)
501 struct passwd
*pw
= NULL
;
503 if (chroot_dir
&& !username
) {
504 fprintf(stderr
, "tcpdump: Chroot without dropping root is insecure\n");
508 pw
= getpwnam(username
);
511 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
512 fprintf(stderr
, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
513 chroot_dir
, pcap_strerror(errno
));
517 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
518 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
519 fprintf(stderr
, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
521 (unsigned long)pw
->pw_uid
,
522 (unsigned long)pw
->pw_gid
,
523 pcap_strerror(errno
));
528 fprintf(stderr
, "tcpdump: Couldn't find user '%.32s'\n",
551 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
553 char *filename
= malloc(NAME_MAX
+ 1);
555 /* Process with strftime if Gflag is set. */
559 /* Convert Gflag_time to a usable format */
560 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
561 error("MakeTimedFilename: localtime");
564 /* There's no good way to detect an error in strftime since a return
565 * value of 0 isn't necessarily failure.
567 strftime(filename
, NAME_MAX
, orig_name
, local_tm
);
569 strncpy(filename
, orig_name
, NAME_MAX
);
572 if (cnt
== 0 && max_chars
== 0)
573 strncpy(buffer
, filename
, NAME_MAX
+ 1);
575 if (snprintf(buffer
, NAME_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > NAME_MAX
)
576 /* Report an error if the filename is too large */
577 error("too many output files or filename is too long (> %d)", NAME_MAX
);
581 static int tcpdump_printf(netdissect_options
*ndo _U_
,
582 const char *fmt
, ...)
589 ret
=vfprintf(stdout
, fmt
, args
);
596 main(int argc
, char **argv
)
598 register int cnt
, op
, i
;
599 bpf_u_int32 localnet
, netmask
;
600 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *WFileName
;
601 pcap_handler callback
;
603 struct bpf_program fcode
;
605 RETSIGTYPE (*oldhandler
)(int);
607 struct print_info printinfo
;
608 struct dump_info dumpinfo
;
609 u_char
*pcap_userdata
;
610 char ebuf
[PCAP_ERRBUF_SIZE
];
611 char *username
= NULL
;
612 char *chroot_dir
= NULL
;
613 #ifdef HAVE_PCAP_FINDALLDEVS
614 pcap_if_t
*devpointer
;
619 if(wsockinit() != 0) return 1;
622 jflag
=-1; /* not set */
626 gndo
->ndo_default_print
=ndo_default_print
;
627 gndo
->ndo_printf
=tcpdump_printf
;
628 gndo
->ndo_error
=ndo_error
;
629 gndo
->ndo_warning
=ndo_warning
;
630 gndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
637 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
638 program_name
= cp
+ 1;
640 program_name
= argv
[0];
642 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
651 (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)
655 /* compatibility for old -a */
666 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
668 Bflag
= atoi(optarg
)*1024;
670 error("invalid packet buffer size %s", optarg
);
672 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
677 error("invalid packet count %s", optarg
);
681 Cflag
= atoi(optarg
) * 1000000;
683 error("invalid file size %s", optarg
);
690 #ifdef HAVE_PCAP_FINDALLDEVS
692 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
695 for (i
= 0; devpointer
!= 0; i
++) {
696 printf("%d.%s", i
+1, devpointer
->name
);
697 if (devpointer
->description
!= NULL
)
698 printf(" (%s)", devpointer
->description
);
700 devpointer
= devpointer
->next
;
704 #endif /* HAVE_PCAP_FINDALLDEVS */
715 #ifndef HAVE_LIBCRYPTO
716 warning("crypto code not compiled in");
718 gndo
->ndo_espsecret
= optarg
;
730 Gflag
= atoi(optarg
);
732 error("invalid number of seconds %s", optarg
);
734 /* We will create one file initially. */
737 /* Grab the current time for rotation use. */
738 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
739 error("main: can't get current time: %s",
740 pcap_strerror(errno
));
749 if (optarg
[0] == '0' && optarg
[1] == 0)
750 error("Invalid adapter index");
752 #ifdef HAVE_PCAP_FINDALLDEVS
754 * If the argument is a number, treat it as
755 * an index into the list of adapters, as
756 * printed by "tcpdump -D".
758 * This should be OK on UNIX systems, as interfaces
759 * shouldn't have names that begin with digits.
760 * It can be useful on Windows, where more than
761 * one interface can have the same name.
763 if ((devnum
= atoi(optarg
)) != 0) {
765 error("Invalid adapter index");
767 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
771 * Look for the devnum-th entry
772 * in the list of devices
776 i
< devnum
-1 && devpointer
!= NULL
;
777 i
++, devpointer
= devpointer
->next
)
779 if (devpointer
== NULL
)
780 error("Invalid adapter index");
782 device
= devpointer
->name
;
785 #endif /* HAVE_PCAP_FINDALLDEVS */
789 #ifdef HAVE_PCAP_CREATE
793 #endif /* HAVE_PCAP_CREATE */
795 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
797 jflag
= pcap_tstamp_type_name_to_val(optarg
);
799 error("invalid time stamp type %s", optarg
);
810 * _IOLBF is the same as _IOFBF in Microsoft's C
811 * libraries; the only alternative they offer
814 * XXX - this should really be checking for MSVC++,
815 * not WIN32, if, for example, MinGW has its own
816 * C library that is more UNIX-compatible.
818 setvbuf(stdout
, NULL
, _IONBF
, 0);
820 #ifdef HAVE_SETLINEBUF
823 setvbuf(stdout
, NULL
, _IOLBF
, 0);
834 if (smiLoadModule(optarg
) == 0) {
835 error("could not load MIB module %s", optarg
);
839 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
840 program_name
, optarg
);
841 (void)fprintf(stderr
, "(no libsmi support)\n");
846 /* TCP-MD5 shared secret */
847 #ifndef HAVE_LIBCRYPTO
848 warning("crypto code not compiled in");
871 ++suppress_default_print
;
885 snaplen
= strtol(optarg
, &end
, 0);
886 if (optarg
== end
|| *end
!= '\0'
887 || snaplen
< 0 || snaplen
> MAXIMUM_SNAPLEN
)
888 error("invalid snaplen %s", optarg
);
889 else if (snaplen
== 0)
890 snaplen
= MAXIMUM_SNAPLEN
;
903 if (strcasecmp(optarg
, "vat") == 0)
905 else if (strcasecmp(optarg
, "wb") == 0)
907 else if (strcasecmp(optarg
, "rpc") == 0)
909 else if (strcasecmp(optarg
, "rtp") == 0)
911 else if (strcasecmp(optarg
, "rtcp") == 0)
912 packettype
= PT_RTCP
;
913 else if (strcasecmp(optarg
, "snmp") == 0)
914 packettype
= PT_SNMP
;
915 else if (strcasecmp(optarg
, "cnfp") == 0)
916 packettype
= PT_CNFP
;
917 else if (strcasecmp(optarg
, "tftp") == 0)
918 packettype
= PT_TFTP
;
919 else if (strcasecmp(optarg
, "aodv") == 0)
920 packettype
= PT_AODV
;
922 error("unknown packet type `%s'", optarg
);
929 #ifdef HAVE_PCAP_DUMP_FLUSH
944 Wflag
= atoi(optarg
);
946 error("invalid number of output files %s", optarg
);
947 WflagChars
= getWflagChars(Wflag
);
952 ++suppress_default_print
;
957 ++suppress_default_print
;
961 gndo
->ndo_dltname
= optarg
;
963 pcap_datalink_name_to_val(gndo
->ndo_dltname
);
964 if (gndo
->ndo_dlt
< 0)
965 error("invalid data link type %s", gndo
->ndo_dltname
);
968 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
971 /* Undocumented flag */
972 #ifdef HAVE_PCAP_DEBUG
973 extern int pcap_debug
;
984 zflag
= strdup(optarg
);
993 username
= strdup(optarg
);
1008 case 0: /* Default */
1009 case 4: /* Default + Date*/
1010 thiszone
= gmt2local(0);
1013 case 1: /* No time stamp */
1014 case 2: /* Unix timeval style */
1015 case 3: /* Microseconds since previous packet */
1016 case 5: /* Microseconds since first packet */
1019 default: /* Not supported */
1020 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1025 /* if run as root, prepare for chrooting */
1026 if (getuid() == 0 || geteuid() == 0) {
1027 /* future extensibility for cmd-line arguments */
1029 chroot_dir
= WITH_CHROOT
;
1034 /* if run as root, prepare for dropping root privileges */
1035 if (getuid() == 0 || geteuid() == 0) {
1036 /* Run with '-Z root' to restore old behaviour */
1038 username
= WITH_USER
;
1042 if (RFileName
!= NULL
) {
1044 const char *dlt_name
;
1048 * We don't need network access, so relinquish any set-UID
1049 * or set-GID privileges we have (if any).
1051 * We do *not* want set-UID privileges when opening a
1052 * trace file, as that might let the user read other
1053 * people's trace files (especially if we're set-UID
1056 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1057 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1059 pd
= pcap_open_offline(RFileName
, ebuf
);
1062 dlt
= pcap_datalink(pd
);
1063 dlt_name
= pcap_datalink_val_to_name(dlt
);
1064 if (dlt_name
== NULL
) {
1065 fprintf(stderr
, "reading from file %s, link-type %u\n",
1069 "reading from file %s, link-type %s (%s)\n",
1070 RFileName
, dlt_name
,
1071 pcap_datalink_val_to_description(dlt
));
1076 error("-f and -r options are incompatible");
1078 if (device
== NULL
) {
1079 device
= pcap_lookupdev(ebuf
);
1084 if(strlen(device
) == 1) //we assume that an ASCII string is always longer than 1 char
1085 { //a Unicode string has a \0 as second byte (so strlen() is 1)
1086 fprintf(stderr
, "%s: listening on %ws\n", program_name
, device
);
1090 fprintf(stderr
, "%s: listening on %s\n", program_name
, device
);
1095 #ifdef HAVE_PCAP_CREATE
1096 pd
= pcap_create(device
, ebuf
);
1099 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1101 show_tstamp_types_and_exit(device
, pd
);
1104 * Is this an interface that supports monitor mode?
1106 if (pcap_can_set_rfmon(pd
) == 1)
1107 supports_monitor_mode
= 1;
1109 supports_monitor_mode
= 0;
1110 status
= pcap_set_snaplen(pd
, snaplen
);
1112 error("%s: Can't set snapshot length: %s",
1113 device
, pcap_statustostr(status
));
1114 status
= pcap_set_promisc(pd
, !pflag
);
1116 error("%s: Can't set promiscuous mode: %s",
1117 device
, pcap_statustostr(status
));
1119 status
= pcap_set_rfmon(pd
, 1);
1121 error("%s: Can't set monitor mode: %s",
1122 device
, pcap_statustostr(status
));
1124 status
= pcap_set_timeout(pd
, 1000);
1126 error("%s: pcap_set_timeout failed: %s",
1127 device
, pcap_statustostr(status
));
1129 status
= pcap_set_buffer_size(pd
, Bflag
);
1131 error("%s: Can't set buffer size: %s",
1132 device
, pcap_statustostr(status
));
1134 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1136 status
= pcap_set_tstamp_type(pd
, jflag
);
1138 error("%s: Can't set time stamp type: %s",
1139 device
, pcap_statustostr(status
));
1142 status
= pcap_activate(pd
);
1145 * pcap_activate() failed.
1147 cp
= pcap_geterr(pd
);
1148 if (status
== PCAP_ERROR
)
1150 else if ((status
== PCAP_ERROR_NO_SUCH_DEVICE
||
1151 status
== PCAP_ERROR_PERM_DENIED
) &&
1153 error("%s: %s\n(%s)", device
,
1154 pcap_statustostr(status
), cp
);
1156 error("%s: %s", device
,
1157 pcap_statustostr(status
));
1158 } else if (status
> 0) {
1160 * pcap_activate() succeeded, but it's warning us
1161 * of a problem it had.
1163 cp
= pcap_geterr(pd
);
1164 if (status
== PCAP_WARNING
)
1166 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1168 warning("%s: %s\n(%s)", device
,
1169 pcap_statustostr(status
), cp
);
1171 warning("%s: %s", device
,
1172 pcap_statustostr(status
));
1176 pd
= pcap_open_live(device
, snaplen
, !pflag
, 1000, ebuf
);
1180 warning("%s", ebuf
);
1181 #endif /* HAVE_PCAP_CREATE */
1183 * Let user own process after socket has been opened.
1186 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1187 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1189 #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
1191 if(pcap_setbuff(pd
, Bflag
)==-1){
1192 error("%s", pcap_geterr(pd
));
1194 #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
1196 show_dlts_and_exit(device
, pd
);
1197 if (gndo
->ndo_dlt
>= 0) {
1198 #ifdef HAVE_PCAP_SET_DATALINK
1199 if (pcap_set_datalink(pd
, gndo
->ndo_dlt
) < 0)
1200 error("%s", pcap_geterr(pd
));
1203 * We don't actually support changing the
1204 * data link type, so we only let them
1205 * set it to what it already is.
1207 if (gndo
->ndo_dlt
!= pcap_datalink(pd
)) {
1208 error("%s is not one of the DLTs supported by this device\n",
1212 (void)fprintf(stderr
, "%s: data link type %s\n",
1213 program_name
, gndo
->ndo_dltname
);
1214 (void)fflush(stderr
);
1216 i
= pcap_snapshot(pd
);
1218 warning("snaplen raised from %d to %d", snaplen
, i
);
1221 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1224 warning("%s", ebuf
);
1228 cmdbuf
= read_infile(infile
);
1230 cmdbuf
= copy_argv(&argv
[optind
]);
1232 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1233 error("%s", pcap_geterr(pd
));
1236 bpf_dump(&fcode
, dflag
);
1240 init_addrtoname(localnet
, netmask
);
1244 (void)setsignal(SIGPIPE
, cleanup
);
1245 (void)setsignal(SIGTERM
, cleanup
);
1246 (void)setsignal(SIGINT
, cleanup
);
1248 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1249 (void)setsignal(SIGCHLD
, child_cleanup
);
1251 /* Cooperate with nohup(1) */
1253 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1254 (void)setsignal(SIGHUP
, oldhandler
);
1259 * If a user name was specified with "-Z", attempt to switch to
1260 * that user's UID. This would probably be used with sudo,
1261 * to allow tcpdump to be run in a special restricted
1262 * account (if you just want to allow users to open capture
1263 * devices, and can't just give users that permission,
1264 * you'd make tcpdump set-UID or set-GID).
1266 * Tcpdump doesn't necessarily write only to one savefile;
1267 * the general only way to allow a -Z instance to write to
1268 * savefiles as the user under whose UID it's run, rather
1269 * than as the user specified with -Z, would thus be to switch
1270 * to the original user ID before opening a capture file and
1271 * then switch back to the -Z user ID after opening the savefile.
1272 * Switching to the -Z user ID only after opening the first
1273 * savefile doesn't handle the general case.
1275 if (getuid() == 0 || geteuid() == 0) {
1276 if (username
|| chroot_dir
)
1277 droproot(username
, chroot_dir
);
1281 if (pcap_setfilter(pd
, &fcode
) < 0)
1282 error("%s", pcap_geterr(pd
));
1285 /* Do not exceed the default NAME_MAX for files. */
1286 dumpinfo
.CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1288 if (dumpinfo
.CurrentFileName
== NULL
)
1289 error("malloc of dumpinfo.CurrentFileName");
1291 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1293 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1295 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1297 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1299 error("%s", pcap_geterr(pd
));
1300 if (Cflag
!= 0 || Gflag
!= 0) {
1301 callback
= dump_packet_and_trunc
;
1302 dumpinfo
.WFileName
= WFileName
;
1305 pcap_userdata
= (u_char
*)&dumpinfo
;
1307 callback
= dump_packet
;
1308 pcap_userdata
= (u_char
*)p
;
1310 #ifdef HAVE_PCAP_DUMP_FLUSH
1315 type
= pcap_datalink(pd
);
1316 printinfo
.ndo_type
= 1;
1317 printinfo
.ndo
= gndo
;
1318 printinfo
.p
.ndo_printer
= lookup_ndo_printer(type
);
1319 if (printinfo
.p
.ndo_printer
== NULL
) {
1320 printinfo
.p
.printer
= lookup_printer(type
);
1321 printinfo
.ndo_type
= 0;
1322 if (printinfo
.p
.printer
== NULL
) {
1323 gndo
->ndo_dltname
= pcap_datalink_val_to_name(type
);
1324 if (gndo
->ndo_dltname
!= NULL
)
1325 error("packet printing is not supported for link type %s: use -w",
1328 error("packet printing is not supported for link type %d: use -w", type
);
1331 callback
= print_packet
;
1332 pcap_userdata
= (u_char
*)&printinfo
;
1337 * We can't get statistics when reading from a file rather
1338 * than capturing from a device.
1340 if (RFileName
== NULL
)
1341 (void)setsignal(SIGINFO
, requestinfo
);
1344 if (vflag
> 0 && WFileName
) {
1346 * When capturing to a file, "-v" means tcpdump should,
1347 * every 10 secodns, "v"erbosely report the number of
1350 #ifdef USE_WIN32_MM_TIMER
1351 /* call verbose_stats_dump() each 1000 +/-100msec */
1352 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1353 setvbuf(stderr
, NULL
, _IONBF
, 0);
1354 #elif defined(HAVE_ALARM)
1355 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1361 if (RFileName
== NULL
) {
1363 const char *dlt_name
;
1365 if (!vflag
&& !WFileName
) {
1366 (void)fprintf(stderr
,
1367 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1370 (void)fprintf(stderr
, "%s: ", program_name
);
1371 dlt
= pcap_datalink(pd
);
1372 dlt_name
= pcap_datalink_val_to_name(dlt
);
1373 if (dlt_name
== NULL
) {
1374 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1375 device
, dlt
, snaplen
);
1377 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1379 pcap_datalink_val_to_description(dlt
), snaplen
);
1381 (void)fflush(stderr
);
1384 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1385 if (WFileName
== NULL
) {
1387 * We're printing packets. Flush the printed output,
1388 * so it doesn't get intermingled with error output.
1392 * We got interrupted, so perhaps we didn't
1393 * manage to finish a line we were printing.
1394 * Print an extra newline, just in case.
1398 (void)fflush(stdout
);
1404 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
1405 program_name
, pcap_geterr(pd
));
1407 if (RFileName
== NULL
) {
1409 * We're doing a live capture. Report the capture
1415 exit(status
== -1 ? 1 : 0);
1418 /* make a clean exit on interrupts */
1420 cleanup(int signo _U_
)
1422 #ifdef USE_WIN32_MM_TIMER
1424 timeKillEvent(timer_id
);
1426 #elif defined(HAVE_ALARM)
1430 #ifdef HAVE_PCAP_BREAKLOOP
1432 * We have "pcap_breakloop()"; use it, so that we do as little
1433 * as possible in the signal handler (it's probably not safe
1434 * to do anything with standard I/O streams in a signal handler -
1435 * the ANSI C standard doesn't say it is).
1440 * We don't have "pcap_breakloop()"; this isn't safe, but
1441 * it's the best we can do. Print the summary if we're
1442 * not reading from a savefile - i.e., if we're doing a
1443 * live capture - and exit.
1445 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
1447 * We got interrupted, so perhaps we didn't
1448 * manage to finish a line we were printing.
1449 * Print an extra newline, just in case.
1452 (void)fflush(stdout
);
1460 On windows, we do not use a fork, so we do not care less about
1461 waiting a child processes to die
1463 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1465 child_cleanup(int signo _U_
)
1469 #endif /* HAVE_FORK && HAVE_VFORK */
1472 info(register int verbose
)
1474 struct pcap_stat stat
;
1477 * Older versions of libpcap didn't set ps_ifdrop on some
1478 * platforms; initialize it to 0 to handle that.
1481 if (pcap_stats(pd
, &stat
) < 0) {
1482 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
1488 fprintf(stderr
, "%s: ", program_name
);
1490 (void)fprintf(stderr
, "%u packet%s captured", packets_captured
,
1491 PLURAL_SUFFIX(packets_captured
));
1493 fputs(", ", stderr
);
1496 (void)fprintf(stderr
, "%u packet%s received by filter", stat
.ps_recv
,
1497 PLURAL_SUFFIX(stat
.ps_recv
));
1499 fputs(", ", stderr
);
1502 (void)fprintf(stderr
, "%u packet%s dropped by kernel", stat
.ps_drop
,
1503 PLURAL_SUFFIX(stat
.ps_drop
));
1504 if (stat
.ps_ifdrop
!= 0) {
1506 fputs(", ", stderr
);
1509 (void)fprintf(stderr
, "%u packet%s dropped by interface\n",
1510 stat
.ps_ifdrop
, PLURAL_SUFFIX(stat
.ps_ifdrop
));
1516 #if defined(HAVE_FORK) || defined(HAVE_VFORK)
1518 compress_savefile(const char *filename
)
1527 * Set to lowest priority so that this doesn't disturb the capture
1530 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
1532 setpriority(PRIO_PROCESS
, 0, 19);
1534 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
1536 "compress_savefile:execlp(%s, %s): %s\n",
1546 #else /* HAVE_FORK && HAVE_VFORK */
1548 compress_savefile(const char *filename
)
1551 "compress_savefile failed. Functionality not implemented under your system\n");
1553 #endif /* HAVE_FORK && HAVE_VFORK */
1556 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1558 struct dump_info
*dump_info
;
1564 dump_info
= (struct dump_info
*)user
;
1567 * XXX - this won't force the file to rotate on the specified time
1568 * boundary, but it will rotate on the first packet received after the
1569 * specified Gflag number of seconds. Note: if a Gflag time boundary
1570 * and a Cflag size boundary coincide, the time rotation will occur
1571 * first thereby cancelling the Cflag boundary (since the file should
1575 /* Check if it is time to rotate */
1578 /* Get the current time */
1579 if ((t
= time(NULL
)) == (time_t)-1) {
1580 error("dump_and_trunc_packet: can't get current_time: %s",
1581 pcap_strerror(errno
));
1585 /* If the time is greater than the specified window, rotate */
1586 if (t
- Gflag_time
>= Gflag
) {
1587 /* Update the Gflag_time */
1589 /* Update Gflag_count */
1592 * Close the current file and open a new one.
1594 pcap_dump_close(dump_info
->p
);
1597 * Compress the file we just closed, if the user asked for it
1600 compress_savefile(dump_info
->CurrentFileName
);
1603 * Check to see if we've exceeded the Wflag (when
1606 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
1607 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
1612 if (dump_info
->CurrentFileName
!= NULL
)
1613 free(dump_info
->CurrentFileName
);
1614 /* Allocate space for max filename + \0. */
1615 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1616 if (dump_info
->CurrentFileName
== NULL
)
1617 error("dump_packet_and_trunc: malloc");
1619 * This is always the first file in the Cflag
1621 * We also don't need numbering if Cflag is not set.
1624 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
1627 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
1629 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1630 if (dump_info
->p
== NULL
)
1631 error("%s", pcap_geterr(pd
));
1636 * XXX - this won't prevent capture files from getting
1637 * larger than Cflag - the last packet written to the
1638 * file could put it over Cflag.
1640 if (Cflag
!= 0 && pcap_dump_ftell(dump_info
->p
) > Cflag
) {
1642 * Close the current file and open a new one.
1644 pcap_dump_close(dump_info
->p
);
1647 * Compress the file we just closed, if the user asked for it
1650 compress_savefile(dump_info
->CurrentFileName
);
1654 if (Cflag_count
>= Wflag
)
1657 if (dump_info
->CurrentFileName
!= NULL
)
1658 free(dump_info
->CurrentFileName
);
1659 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1660 if (dump_info
->CurrentFileName
== NULL
)
1661 error("dump_packet_and_trunc: malloc");
1662 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
1663 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1664 if (dump_info
->p
== NULL
)
1665 error("%s", pcap_geterr(pd
));
1668 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
1669 #ifdef HAVE_PCAP_DUMP_FLUSH
1671 pcap_dump_flush(dump_info
->p
);
1680 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1686 pcap_dump(user
, h
, sp
);
1687 #ifdef HAVE_PCAP_DUMP_FLUSH
1689 pcap_dump_flush((pcap_dumper_t
*)user
);
1698 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1700 struct print_info
*print_info
;
1708 print_info
= (struct print_info
*)user
;
1711 * Some printers want to check that they're not walking off the
1712 * end of the packet.
1713 * Rather than pass it all the way down, we set this global.
1715 snapend
= sp
+ h
->caplen
;
1717 if(print_info
->ndo_type
) {
1718 hdrlen
= (*print_info
->p
.ndo_printer
)(print_info
->ndo
, h
, sp
);
1720 hdrlen
= (*print_info
->p
.printer
)(h
, sp
);
1725 * Print the raw packet data in hex and ASCII.
1729 * Include the link-layer header.
1731 hex_and_ascii_print("\n\t", sp
, h
->caplen
);
1734 * Don't include the link-layer header - and if
1735 * we have nothing past the link-layer header,
1738 if (h
->caplen
> hdrlen
)
1739 hex_and_ascii_print("\n\t", sp
+ hdrlen
,
1740 h
->caplen
- hdrlen
);
1744 * Print the raw packet data in hex.
1748 * Include the link-layer header.
1750 hex_print("\n\t", sp
, h
->caplen
);
1753 * Don't include the link-layer header - and if
1754 * we have nothing past the link-layer header,
1757 if (h
->caplen
> hdrlen
)
1758 hex_print("\n\t", sp
+ hdrlen
,
1759 h
->caplen
- hdrlen
);
1763 * Print the raw packet data in ASCII.
1767 * Include the link-layer header.
1769 ascii_print(sp
, h
->caplen
);
1772 * Don't include the link-layer header - and if
1773 * we have nothing past the link-layer header,
1776 if (h
->caplen
> hdrlen
)
1777 ascii_print(sp
+ hdrlen
, h
->caplen
- hdrlen
);
1790 * XXX - there should really be libpcap calls to get the version
1791 * number as a string (the string would be generated from #defines
1792 * at run time, so that it's not generated from string constants
1793 * in the library, as, on many UNIX systems, those constants would
1794 * be statically linked into the application executable image, and
1795 * would thus reflect the version of libpcap on the system on
1796 * which the application was *linked*, not the system on which it's
1799 * That routine should be documented, unlike the "version[]"
1800 * string, so that UNIX vendors providing their own libpcaps
1801 * don't omit it (as a couple of vendors have...).
1803 * Packet.dll should perhaps also export a routine to return the
1804 * version number of the Packet.dll code, to supply the
1805 * "Wpcap_version" information on Windows.
1807 char WDversion
[]="current-cvs.tcpdump.org";
1808 #if !defined(HAVE_GENERATED_VERSION)
1809 char version
[]="current-cvs.tcpdump.org";
1811 char pcap_version
[]="current-cvs.tcpdump.org";
1812 char Wpcap_version
[]="3.1";
1816 * By default, print the specified data out in hex and ASCII.
1819 ndo_default_print(netdissect_options
*ndo _U_
, const u_char
*bp
, u_int length
)
1821 hex_and_ascii_print("\n\t", bp
, length
); /* pass on lf and identation string */
1825 default_print(const u_char
*bp
, u_int length
)
1827 ndo_default_print(gndo
, bp
, length
);
1831 RETSIGTYPE
requestinfo(int signo _U_
)
1841 * Called once each second in verbose mode while dumping to file
1843 #ifdef USE_WIN32_MM_TIMER
1844 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
1845 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
1847 struct pcap_stat stat
;
1849 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1850 fprintf(stderr
, "Got %u\r", packets_captured
);
1852 #elif defined(HAVE_ALARM)
1853 static void verbose_stats_dump(int sig _U_
)
1855 struct pcap_stat stat
;
1857 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1858 fprintf(stderr
, "Got %u\r", packets_captured
);
1866 extern char version
[];
1867 #ifndef HAVE_PCAP_LIB_VERSION
1868 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
1869 extern char pcap_version
[];
1870 #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1871 static char pcap_version
[] = "unknown";
1872 #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1873 #endif /* HAVE_PCAP_LIB_VERSION */
1875 #ifdef HAVE_PCAP_LIB_VERSION
1877 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1879 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1881 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
1882 #else /* HAVE_PCAP_LIB_VERSION */
1884 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1885 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
1887 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1888 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
1890 #endif /* HAVE_PCAP_LIB_VERSION */
1891 (void)fprintf(stderr
,
1892 "Usage: %s [-aAbd" D_FLAG
"efh" I_FLAG J_FLAG
"KlLnNOpqRStu" U_FLAG
"vxX]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
1893 (void)fprintf(stderr
,
1894 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
1895 (void)fprintf(stderr
,
1896 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ]\n");
1897 (void)fprintf(stderr
,
1898 "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
1899 (void)fprintf(stderr
,
1900 "\t\t[ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
1901 (void)fprintf(stderr
,
1902 "\t\t[ -Z user ] [ expression ]\n");
1910 ndo_error(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1914 (void)fprintf(stderr
, "%s: ", program_name
);
1916 (void)vfprintf(stderr
, fmt
, ap
);
1920 if (fmt
[-1] != '\n')
1921 (void)fputc('\n', stderr
);
1929 ndo_warning(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1933 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
1935 (void)vfprintf(stderr
, fmt
, ap
);
1939 if (fmt
[-1] != '\n')
1940 (void)fputc('\n', stderr
);