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 for (i
= 0; i
< n_tstamp_types
; i
++) {
379 tstamp_type_name
= pcap_tstamp_type_val_to_name(tstamp_types
[i
]);
380 if (tstamp_type_name
!= NULL
) {
381 (void) fprintf(stderr
, " %s (%s)\n", tstamp_type_name
,
382 pcap_tstamp_type_val_to_description(tstamp_types
[i
]));
384 (void) fprintf(stderr
, " %d\n", tstamp_types
[i
]);
387 pcap_free_tstamp_types(tstamp_types
);
393 show_dlts_and_exit(const char *device
, pcap_t
*pd
)
397 const char *dlt_name
;
399 n_dlts
= pcap_list_datalinks(pd
, &dlts
);
401 error("%s", pcap_geterr(pd
));
402 else if (n_dlts
== 0 || !dlts
)
403 error("No data link types.");
406 * If the interface is known to support monitor mode, indicate
407 * whether these are the data link types available when not in
408 * monitor mode, if -I wasn't specified, or when in monitor mode,
409 * when -I was specified (the link-layer types available in
410 * monitor mode might be different from the ones available when
411 * not in monitor mode).
413 if (supports_monitor_mode
)
414 (void) fprintf(stderr
, "Data link types for %s %s (use option -y to set):\n",
416 Iflag
? "when in monitor mode" : "when not in monitor mode");
418 (void) fprintf(stderr
, "Data link types for %s (use option -y to set):\n",
421 while (--n_dlts
>= 0) {
422 dlt_name
= pcap_datalink_val_to_name(dlts
[n_dlts
]);
423 if (dlt_name
!= NULL
) {
424 (void) fprintf(stderr
, " %s (%s)", dlt_name
,
425 pcap_datalink_val_to_description(dlts
[n_dlts
]));
428 * OK, does tcpdump handle that type?
430 if (lookup_printer(dlts
[n_dlts
]) == NULL
431 && lookup_ndo_printer(dlts
[n_dlts
]) == NULL
)
432 (void) fprintf(stderr
, " (printing not supported)");
433 fprintf(stderr
, "\n");
435 (void) fprintf(stderr
, " DLT %d (printing not supported)\n",
439 pcap_free_datalinks(dlts
);
444 * Set up flags that might or might not be supported depending on the
445 * version of libpcap we're using.
447 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
449 #define B_FLAG_USAGE " [ -B size ]"
450 #else /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
453 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
455 #ifdef HAVE_PCAP_CREATE
457 #else /* HAVE_PCAP_CREATE */
459 #endif /* HAVE_PCAP_CREATE */
461 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
463 #define j_FLAG_USAGE " [ -j tstamptype ]"
465 #else /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
469 #endif /* PCAP_ERROR_TSTAMP_TYPE_NOTSUP */
471 #ifdef HAVE_PCAP_FINDALLDEVS
472 #ifndef HAVE_PCAP_IF_T
473 #undef HAVE_PCAP_FINDALLDEVS
477 #ifdef HAVE_PCAP_FINDALLDEVS
483 #ifdef HAVE_PCAP_DUMP_FLUSH
490 /* Drop root privileges and chroot if necessary */
492 droproot(const char *username
, const char *chroot_dir
)
494 struct passwd
*pw
= NULL
;
496 if (chroot_dir
&& !username
) {
497 fprintf(stderr
, "tcpdump: Chroot without dropping root is insecure\n");
501 pw
= getpwnam(username
);
504 if (chroot(chroot_dir
) != 0 || chdir ("/") != 0) {
505 fprintf(stderr
, "tcpdump: Couldn't chroot/chdir to '%.64s': %s\n",
506 chroot_dir
, pcap_strerror(errno
));
510 if (initgroups(pw
->pw_name
, pw
->pw_gid
) != 0 ||
511 setgid(pw
->pw_gid
) != 0 || setuid(pw
->pw_uid
) != 0) {
512 fprintf(stderr
, "tcpdump: Couldn't change to '%.32s' uid=%lu gid=%lu: %s\n",
514 (unsigned long)pw
->pw_uid
,
515 (unsigned long)pw
->pw_gid
,
516 pcap_strerror(errno
));
521 fprintf(stderr
, "tcpdump: Couldn't find user '%.32s'\n",
544 MakeFilename(char *buffer
, char *orig_name
, int cnt
, int max_chars
)
546 char *filename
= malloc(NAME_MAX
+ 1);
548 /* Process with strftime if Gflag is set. */
552 /* Convert Gflag_time to a usable format */
553 if ((local_tm
= localtime(&Gflag_time
)) == NULL
) {
554 error("MakeTimedFilename: localtime");
557 /* There's no good way to detect an error in strftime since a return
558 * value of 0 isn't necessarily failure.
560 strftime(filename
, NAME_MAX
, orig_name
, local_tm
);
562 strncpy(filename
, orig_name
, NAME_MAX
);
565 if (cnt
== 0 && max_chars
== 0)
566 strncpy(buffer
, filename
, NAME_MAX
+ 1);
568 if (snprintf(buffer
, NAME_MAX
+ 1, "%s%0*d", filename
, max_chars
, cnt
) > NAME_MAX
)
569 /* Report an error if the filename is too large */
570 error("too many output files or filename is too long (> %d)", NAME_MAX
);
574 static int tcpdump_printf(netdissect_options
*ndo _U_
,
575 const char *fmt
, ...)
582 ret
=vfprintf(stdout
, fmt
, args
);
589 main(int argc
, char **argv
)
591 register int cnt
, op
, i
;
592 bpf_u_int32 localnet
, netmask
;
593 register char *cp
, *infile
, *cmdbuf
, *device
, *RFileName
, *WFileName
;
594 pcap_handler callback
;
596 struct bpf_program fcode
;
598 RETSIGTYPE (*oldhandler
)(int);
600 struct print_info printinfo
;
601 struct dump_info dumpinfo
;
602 u_char
*pcap_userdata
;
603 char ebuf
[PCAP_ERRBUF_SIZE
];
604 char *username
= NULL
;
605 char *chroot_dir
= NULL
;
606 #ifdef HAVE_PCAP_FINDALLDEVS
607 pcap_if_t
*devpointer
;
612 if(wsockinit() != 0) return 1;
615 jflag
=-1; /* not set */
619 gndo
->ndo_default_print
=ndo_default_print
;
620 gndo
->ndo_printf
=tcpdump_printf
;
621 gndo
->ndo_error
=ndo_error
;
622 gndo
->ndo_warning
=ndo_warning
;
623 gndo
->ndo_snaplen
= DEFAULT_SNAPLEN
;
630 if ((cp
= strrchr(argv
[0], '/')) != NULL
)
631 program_name
= cp
+ 1;
633 program_name
= argv
[0];
635 if (abort_on_misalignment(ebuf
, sizeof(ebuf
)) < 0)
644 (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)
648 /* compatibility for old -a */
659 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
661 Bflag
= atoi(optarg
)*1024;
663 error("invalid packet buffer size %s", optarg
);
665 #endif /* defined(HAVE_PCAP_CREATE) || defined(WIN32) */
670 error("invalid packet count %s", optarg
);
674 Cflag
= atoi(optarg
) * 1000000;
676 error("invalid file size %s", optarg
);
683 #ifdef HAVE_PCAP_FINDALLDEVS
685 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
688 for (i
= 0; devpointer
!= 0; i
++) {
689 printf("%d.%s", i
+1, devpointer
->name
);
690 if (devpointer
->description
!= NULL
)
691 printf(" (%s)", devpointer
->description
);
693 devpointer
= devpointer
->next
;
697 #endif /* HAVE_PCAP_FINDALLDEVS */
708 #ifndef HAVE_LIBCRYPTO
709 warning("crypto code not compiled in");
711 gndo
->ndo_espsecret
= optarg
;
723 Gflag
= atoi(optarg
);
725 error("invalid number of seconds %s", optarg
);
727 /* We will create one file initially. */
730 /* Grab the current time for rotation use. */
731 if ((Gflag_time
= time(NULL
)) == (time_t)-1) {
732 error("main: can't get current time: %s",
733 pcap_strerror(errno
));
742 if (optarg
[0] == '0' && optarg
[1] == 0)
743 error("Invalid adapter index");
745 #ifdef HAVE_PCAP_FINDALLDEVS
747 * If the argument is a number, treat it as
748 * an index into the list of adapters, as
749 * printed by "tcpdump -D".
751 * This should be OK on UNIX systems, as interfaces
752 * shouldn't have names that begin with digits.
753 * It can be useful on Windows, where more than
754 * one interface can have the same name.
756 if ((devnum
= atoi(optarg
)) != 0) {
758 error("Invalid adapter index");
760 if (pcap_findalldevs(&devpointer
, ebuf
) < 0)
764 * Look for the devnum-th entry
765 * in the list of devices
769 i
< devnum
-1 && devpointer
!= NULL
;
770 i
++, devpointer
= devpointer
->next
)
772 if (devpointer
== NULL
)
773 error("Invalid adapter index");
775 device
= devpointer
->name
;
778 #endif /* HAVE_PCAP_FINDALLDEVS */
782 #ifdef HAVE_PCAP_CREATE
786 #endif /* HAVE_PCAP_CREATE */
788 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
790 jflag
= pcap_tstamp_type_name_to_val(optarg
);
792 error("invalid time stamp type %s", optarg
);
803 * _IOLBF is the same as _IOFBF in Microsoft's C
804 * libraries; the only alternative they offer
807 * XXX - this should really be checking for MSVC++,
808 * not WIN32, if, for example, MinGW has its own
809 * C library that is more UNIX-compatible.
811 setvbuf(stdout
, NULL
, _IONBF
, 0);
813 #ifdef HAVE_SETLINEBUF
816 setvbuf(stdout
, NULL
, _IOLBF
, 0);
827 if (smiLoadModule(optarg
) == 0) {
828 error("could not load MIB module %s", optarg
);
832 (void)fprintf(stderr
, "%s: ignoring option `-m %s' ",
833 program_name
, optarg
);
834 (void)fprintf(stderr
, "(no libsmi support)\n");
839 /* TCP-MD5 shared secret */
840 #ifndef HAVE_LIBCRYPTO
841 warning("crypto code not compiled in");
864 ++suppress_default_print
;
878 snaplen
= strtol(optarg
, &end
, 0);
879 if (optarg
== end
|| *end
!= '\0'
880 || snaplen
< 0 || snaplen
> MAXIMUM_SNAPLEN
)
881 error("invalid snaplen %s", optarg
);
882 else if (snaplen
== 0)
883 snaplen
= MAXIMUM_SNAPLEN
;
896 if (strcasecmp(optarg
, "vat") == 0)
898 else if (strcasecmp(optarg
, "wb") == 0)
900 else if (strcasecmp(optarg
, "rpc") == 0)
902 else if (strcasecmp(optarg
, "rtp") == 0)
904 else if (strcasecmp(optarg
, "rtcp") == 0)
905 packettype
= PT_RTCP
;
906 else if (strcasecmp(optarg
, "snmp") == 0)
907 packettype
= PT_SNMP
;
908 else if (strcasecmp(optarg
, "cnfp") == 0)
909 packettype
= PT_CNFP
;
910 else if (strcasecmp(optarg
, "tftp") == 0)
911 packettype
= PT_TFTP
;
912 else if (strcasecmp(optarg
, "aodv") == 0)
913 packettype
= PT_AODV
;
915 error("unknown packet type `%s'", optarg
);
922 #ifdef HAVE_PCAP_DUMP_FLUSH
937 Wflag
= atoi(optarg
);
939 error("invalid number of output files %s", optarg
);
940 WflagChars
= getWflagChars(Wflag
);
945 ++suppress_default_print
;
950 ++suppress_default_print
;
954 gndo
->ndo_dltname
= optarg
;
956 pcap_datalink_name_to_val(gndo
->ndo_dltname
);
957 if (gndo
->ndo_dlt
< 0)
958 error("invalid data link type %s", gndo
->ndo_dltname
);
961 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
964 /* Undocumented flag */
965 #ifdef HAVE_PCAP_DEBUG
966 extern int pcap_debug
;
977 zflag
= strdup(optarg
);
986 username
= strdup(optarg
);
1001 case 0: /* Default */
1002 case 4: /* Default + Date*/
1003 thiszone
= gmt2local(0);
1006 case 1: /* No time stamp */
1007 case 2: /* Unix timeval style */
1008 case 3: /* Microseconds since previous packet */
1009 case 5: /* Microseconds since first packet */
1012 default: /* Not supported */
1013 error("only -t, -tt, -ttt, -tttt and -ttttt are supported");
1018 /* if run as root, prepare for chrooting */
1019 if (getuid() == 0 || geteuid() == 0) {
1020 /* future extensibility for cmd-line arguments */
1022 chroot_dir
= WITH_CHROOT
;
1027 /* if run as root, prepare for dropping root privileges */
1028 if (getuid() == 0 || geteuid() == 0) {
1029 /* Run with '-Z root' to restore old behaviour */
1031 username
= WITH_USER
;
1035 if (RFileName
!= NULL
) {
1037 const char *dlt_name
;
1041 * We don't need network access, so relinquish any set-UID
1042 * or set-GID privileges we have (if any).
1044 * We do *not* want set-UID privileges when opening a
1045 * trace file, as that might let the user read other
1046 * people's trace files (especially if we're set-UID
1049 if (setgid(getgid()) != 0 || setuid(getuid()) != 0 )
1050 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1052 pd
= pcap_open_offline(RFileName
, ebuf
);
1055 dlt
= pcap_datalink(pd
);
1056 dlt_name
= pcap_datalink_val_to_name(dlt
);
1057 if (dlt_name
== NULL
) {
1058 fprintf(stderr
, "reading from file %s, link-type %u\n",
1062 "reading from file %s, link-type %s (%s)\n",
1063 RFileName
, dlt_name
,
1064 pcap_datalink_val_to_description(dlt
));
1069 error("-f and -r options are incompatible");
1071 if (device
== NULL
) {
1072 device
= pcap_lookupdev(ebuf
);
1077 if(strlen(device
) == 1) //we assume that an ASCII string is always longer than 1 char
1078 { //a Unicode string has a \0 as second byte (so strlen() is 1)
1079 fprintf(stderr
, "%s: listening on %ws\n", program_name
, device
);
1083 fprintf(stderr
, "%s: listening on %s\n", program_name
, device
);
1088 #ifdef HAVE_PCAP_CREATE
1089 pd
= pcap_create(device
, ebuf
);
1092 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1094 show_tstamp_types_and_exit(device
, pd
);
1097 * Is this an interface that supports monitor mode?
1099 if (pcap_can_set_rfmon(pd
) == 1)
1100 supports_monitor_mode
= 1;
1102 supports_monitor_mode
= 0;
1103 status
= pcap_set_snaplen(pd
, snaplen
);
1105 error("%s: Can't set snapshot length: %s",
1106 device
, pcap_statustostr(status
));
1107 status
= pcap_set_promisc(pd
, !pflag
);
1109 error("%s: Can't set promiscuous mode: %s",
1110 device
, pcap_statustostr(status
));
1112 status
= pcap_set_rfmon(pd
, 1);
1114 error("%s: Can't set monitor mode: %s",
1115 device
, pcap_statustostr(status
));
1117 status
= pcap_set_timeout(pd
, 1000);
1119 error("%s: pcap_set_timeout failed: %s",
1120 device
, pcap_statustostr(status
));
1122 status
= pcap_set_buffer_size(pd
, Bflag
);
1124 error("%s: Can't set buffer size: %s",
1125 device
, pcap_statustostr(status
));
1127 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
1129 status
= pcap_set_tstamp_type(pd
, jflag
);
1131 error("%s: Can't set time stamp type: %s",
1132 device
, pcap_statustostr(status
));
1135 status
= pcap_activate(pd
);
1138 * pcap_activate() failed.
1140 cp
= pcap_geterr(pd
);
1141 if (status
== PCAP_ERROR
)
1143 else if ((status
== PCAP_ERROR_NO_SUCH_DEVICE
||
1144 status
== PCAP_ERROR_PERM_DENIED
) &&
1146 error("%s: %s\n(%s)", device
,
1147 pcap_statustostr(status
), cp
);
1149 error("%s: %s", device
,
1150 pcap_statustostr(status
));
1151 } else if (status
> 0) {
1153 * pcap_activate() succeeded, but it's warning us
1154 * of a problem it had.
1156 cp
= pcap_geterr(pd
);
1157 if (status
== PCAP_WARNING
)
1159 else if (status
== PCAP_WARNING_PROMISC_NOTSUP
&&
1161 warning("%s: %s\n(%s)", device
,
1162 pcap_statustostr(status
), cp
);
1164 warning("%s: %s", device
,
1165 pcap_statustostr(status
));
1169 pd
= pcap_open_live(device
, snaplen
, !pflag
, 1000, ebuf
);
1173 warning("%s", ebuf
);
1174 #endif /* HAVE_PCAP_CREATE */
1176 * Let user own process after socket has been opened.
1179 if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
1180 fprintf(stderr
, "Warning: setgid/setuid failed !\n");
1182 #if !defined(HAVE_PCAP_CREATE) && defined(WIN32)
1184 if(pcap_setbuff(pd
, Bflag
)==-1){
1185 error("%s", pcap_geterr(pd
));
1187 #endif /* !defined(HAVE_PCAP_CREATE) && defined(WIN32) */
1189 show_dlts_and_exit(device
, pd
);
1190 if (gndo
->ndo_dlt
>= 0) {
1191 #ifdef HAVE_PCAP_SET_DATALINK
1192 if (pcap_set_datalink(pd
, gndo
->ndo_dlt
) < 0)
1193 error("%s", pcap_geterr(pd
));
1196 * We don't actually support changing the
1197 * data link type, so we only let them
1198 * set it to what it already is.
1200 if (gndo
->ndo_dlt
!= pcap_datalink(pd
)) {
1201 error("%s is not one of the DLTs supported by this device\n",
1205 (void)fprintf(stderr
, "%s: data link type %s\n",
1206 program_name
, gndo
->ndo_dltname
);
1207 (void)fflush(stderr
);
1209 i
= pcap_snapshot(pd
);
1211 warning("snaplen raised from %d to %d", snaplen
, i
);
1214 if (pcap_lookupnet(device
, &localnet
, &netmask
, ebuf
) < 0) {
1217 warning("%s", ebuf
);
1221 cmdbuf
= read_infile(infile
);
1223 cmdbuf
= copy_argv(&argv
[optind
]);
1225 if (pcap_compile(pd
, &fcode
, cmdbuf
, Oflag
, netmask
) < 0)
1226 error("%s", pcap_geterr(pd
));
1229 bpf_dump(&fcode
, dflag
);
1233 init_addrtoname(localnet
, netmask
);
1237 (void)setsignal(SIGPIPE
, cleanup
);
1238 (void)setsignal(SIGTERM
, cleanup
);
1239 (void)setsignal(SIGINT
, cleanup
);
1240 (void)setsignal(SIGCHLD
, child_cleanup
);
1242 /* Cooperate with nohup(1) */
1244 if ((oldhandler
= setsignal(SIGHUP
, cleanup
)) != SIG_DFL
)
1245 (void)setsignal(SIGHUP
, oldhandler
);
1248 if (pcap_setfilter(pd
, &fcode
) < 0)
1249 error("%s", pcap_geterr(pd
));
1252 /* Do not exceed the default NAME_MAX for files. */
1253 dumpinfo
.CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1255 if (dumpinfo
.CurrentFileName
== NULL
)
1256 error("malloc of dumpinfo.CurrentFileName");
1258 /* We do not need numbering for dumpfiles if Cflag isn't set. */
1260 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, WflagChars
);
1262 MakeFilename(dumpinfo
.CurrentFileName
, WFileName
, 0, 0);
1264 p
= pcap_dump_open(pd
, dumpinfo
.CurrentFileName
);
1266 error("%s", pcap_geterr(pd
));
1267 if (Cflag
!= 0 || Gflag
!= 0) {
1268 callback
= dump_packet_and_trunc
;
1269 dumpinfo
.WFileName
= WFileName
;
1272 pcap_userdata
= (u_char
*)&dumpinfo
;
1274 callback
= dump_packet
;
1275 pcap_userdata
= (u_char
*)p
;
1277 #ifdef HAVE_PCAP_DUMP_FLUSH
1282 type
= pcap_datalink(pd
);
1283 printinfo
.ndo_type
= 1;
1284 printinfo
.ndo
= gndo
;
1285 printinfo
.p
.ndo_printer
= lookup_ndo_printer(type
);
1286 if (printinfo
.p
.ndo_printer
== NULL
) {
1287 printinfo
.p
.printer
= lookup_printer(type
);
1288 printinfo
.ndo_type
= 0;
1289 if (printinfo
.p
.printer
== NULL
) {
1290 gndo
->ndo_dltname
= pcap_datalink_val_to_name(type
);
1291 if (gndo
->ndo_dltname
!= NULL
)
1292 error("packet printing is not supported for link type %s: use -w",
1295 error("packet printing is not supported for link type %d: use -w", type
);
1298 callback
= print_packet
;
1299 pcap_userdata
= (u_char
*)&printinfo
;
1303 * We cannot do this earlier, because we want to be able to open
1304 * the file (if done) for writing before giving up permissions.
1306 if (getuid() == 0 || geteuid() == 0) {
1307 if (username
|| chroot_dir
)
1308 droproot(username
, chroot_dir
);
1313 * We can't get statistics when reading from a file rather
1314 * than capturing from a device.
1316 if (RFileName
== NULL
)
1317 (void)setsignal(SIGINFO
, requestinfo
);
1320 if (vflag
> 0 && WFileName
) {
1322 * When capturing to a file, "-v" means tcpdump should,
1323 * every 10 secodns, "v"erbosely report the number of
1326 #ifdef USE_WIN32_MM_TIMER
1327 /* call verbose_stats_dump() each 1000 +/-100msec */
1328 timer_id
= timeSetEvent(1000, 100, verbose_stats_dump
, 0, TIME_PERIODIC
);
1329 setvbuf(stderr
, NULL
, _IONBF
, 0);
1330 #elif defined(HAVE_ALARM)
1331 (void)setsignal(SIGALRM
, verbose_stats_dump
);
1337 if (RFileName
== NULL
) {
1339 const char *dlt_name
;
1341 if (!vflag
&& !WFileName
) {
1342 (void)fprintf(stderr
,
1343 "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
1346 (void)fprintf(stderr
, "%s: ", program_name
);
1347 dlt
= pcap_datalink(pd
);
1348 dlt_name
= pcap_datalink_val_to_name(dlt
);
1349 if (dlt_name
== NULL
) {
1350 (void)fprintf(stderr
, "listening on %s, link-type %u, capture size %u bytes\n",
1351 device
, dlt
, snaplen
);
1353 (void)fprintf(stderr
, "listening on %s, link-type %s (%s), capture size %u bytes\n",
1355 pcap_datalink_val_to_description(dlt
), snaplen
);
1357 (void)fflush(stderr
);
1360 status
= pcap_loop(pd
, cnt
, callback
, pcap_userdata
);
1361 if (WFileName
== NULL
) {
1363 * We're printing packets. Flush the printed output,
1364 * so it doesn't get intermingled with error output.
1368 * We got interrupted, so perhaps we didn't
1369 * manage to finish a line we were printing.
1370 * Print an extra newline, just in case.
1374 (void)fflush(stdout
);
1380 (void)fprintf(stderr
, "%s: pcap_loop: %s\n",
1381 program_name
, pcap_geterr(pd
));
1383 if (RFileName
== NULL
) {
1385 * We're doing a live capture. Report the capture
1391 exit(status
== -1 ? 1 : 0);
1394 /* make a clean exit on interrupts */
1396 cleanup(int signo _U_
)
1398 #ifdef USE_WIN32_MM_TIMER
1400 timeKillEvent(timer_id
);
1402 #elif defined(HAVE_ALARM)
1406 #ifdef HAVE_PCAP_BREAKLOOP
1408 * We have "pcap_breakloop()"; use it, so that we do as little
1409 * as possible in the signal handler (it's probably not safe
1410 * to do anything with standard I/O streams in a signal handler -
1411 * the ANSI C standard doesn't say it is).
1416 * We don't have "pcap_breakloop()"; this isn't safe, but
1417 * it's the best we can do. Print the summary if we're
1418 * not reading from a savefile - i.e., if we're doing a
1419 * live capture - and exit.
1421 if (pd
!= NULL
&& pcap_file(pd
) == NULL
) {
1423 * We got interrupted, so perhaps we didn't
1424 * manage to finish a line we were printing.
1425 * Print an extra newline, just in case.
1428 (void)fflush(stdout
);
1436 On windows, we do not use a fork, so we do not care less about
1437 waiting a child processes to die
1441 child_cleanup(int signo _U_
)
1448 info(register int verbose
)
1450 struct pcap_stat stat
;
1453 * Older versions of libpcap didn't set ps_ifdrop on some
1454 * platforms; initialize it to 0 to handle that.
1457 if (pcap_stats(pd
, &stat
) < 0) {
1458 (void)fprintf(stderr
, "pcap_stats: %s\n", pcap_geterr(pd
));
1464 fprintf(stderr
, "%s: ", program_name
);
1466 (void)fprintf(stderr
, "%u packets captured", packets_captured
);
1468 fputs(", ", stderr
);
1471 (void)fprintf(stderr
, "%u packets received by filter", stat
.ps_recv
);
1473 fputs(", ", stderr
);
1476 (void)fprintf(stderr
, "%u packets dropped by kernel", stat
.ps_drop
);
1477 if (stat
.ps_ifdrop
!= 0) {
1479 fputs(", ", stderr
);
1482 (void)fprintf(stderr
, "%u packets dropped by interface\n",
1491 compress_savefile(const char *filename
)
1496 * Set to lowest priority so that this doesn't disturb the capture
1499 setpriority(PRIO_PROCESS
, 0, NZERO
- 1);
1501 setpriority(PRIO_PROCESS
, 0, 19);
1503 if (execlp(zflag
, zflag
, filename
, (char *)NULL
) == -1)
1505 "compress_savefile:execlp(%s, %s): %s\n",
1512 compress_savefile(const char *filename
)
1515 "compress_savefile failed. Functionality not implemented under windows\n");
1520 dump_packet_and_trunc(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1522 struct dump_info
*dump_info
;
1528 dump_info
= (struct dump_info
*)user
;
1531 * XXX - this won't force the file to rotate on the specified time
1532 * boundary, but it will rotate on the first packet received after the
1533 * specified Gflag number of seconds. Note: if a Gflag time boundary
1534 * and a Cflag size boundary coincide, the time rotation will occur
1535 * first thereby cancelling the Cflag boundary (since the file should
1539 /* Check if it is time to rotate */
1542 /* Get the current time */
1543 if ((t
= time(NULL
)) == (time_t)-1) {
1544 error("dump_and_trunc_packet: can't get current_time: %s",
1545 pcap_strerror(errno
));
1549 /* If the time is greater than the specified window, rotate */
1550 if (t
- Gflag_time
>= Gflag
) {
1551 /* Update the Gflag_time */
1553 /* Update Gflag_count */
1556 * Close the current file and open a new one.
1558 pcap_dump_close(dump_info
->p
);
1561 * Compress the file we just closed, if the user asked for it
1564 compress_savefile(dump_info
->CurrentFileName
);
1567 * Check to see if we've exceeded the Wflag (when
1570 if (Cflag
== 0 && Wflag
> 0 && Gflag_count
>= Wflag
) {
1571 (void)fprintf(stderr
, "Maximum file limit reached: %d\n",
1576 if (dump_info
->CurrentFileName
!= NULL
)
1577 free(dump_info
->CurrentFileName
);
1578 /* Allocate space for max filename + \0. */
1579 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1580 if (dump_info
->CurrentFileName
== NULL
)
1581 error("dump_packet_and_trunc: malloc");
1583 * This is always the first file in the Cflag
1585 * We also don't need numbering if Cflag is not set.
1588 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0,
1591 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, 0, 0);
1593 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1594 if (dump_info
->p
== NULL
)
1595 error("%s", pcap_geterr(pd
));
1600 * XXX - this won't prevent capture files from getting
1601 * larger than Cflag - the last packet written to the
1602 * file could put it over Cflag.
1604 if (Cflag
!= 0 && pcap_dump_ftell(dump_info
->p
) > Cflag
) {
1606 * Close the current file and open a new one.
1608 pcap_dump_close(dump_info
->p
);
1611 * Compress the file we just closed, if the user asked for it
1614 compress_savefile(dump_info
->CurrentFileName
);
1618 if (Cflag_count
>= Wflag
)
1621 if (dump_info
->CurrentFileName
!= NULL
)
1622 free(dump_info
->CurrentFileName
);
1623 dump_info
->CurrentFileName
= (char *)malloc(NAME_MAX
+ 1);
1624 if (dump_info
->CurrentFileName
== NULL
)
1625 error("dump_packet_and_trunc: malloc");
1626 MakeFilename(dump_info
->CurrentFileName
, dump_info
->WFileName
, Cflag_count
, WflagChars
);
1627 dump_info
->p
= pcap_dump_open(dump_info
->pd
, dump_info
->CurrentFileName
);
1628 if (dump_info
->p
== NULL
)
1629 error("%s", pcap_geterr(pd
));
1632 pcap_dump((u_char
*)dump_info
->p
, h
, sp
);
1633 #ifdef HAVE_PCAP_DUMP_FLUSH
1635 pcap_dump_flush(dump_info
->p
);
1644 dump_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1650 pcap_dump(user
, h
, sp
);
1651 #ifdef HAVE_PCAP_DUMP_FLUSH
1653 pcap_dump_flush((pcap_dumper_t
*)user
);
1662 print_packet(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*sp
)
1664 struct print_info
*print_info
;
1672 print_info
= (struct print_info
*)user
;
1675 * Some printers want to check that they're not walking off the
1676 * end of the packet.
1677 * Rather than pass it all the way down, we set this global.
1679 snapend
= sp
+ h
->caplen
;
1681 if(print_info
->ndo_type
) {
1682 hdrlen
= (*print_info
->p
.ndo_printer
)(print_info
->ndo
, h
, sp
);
1684 hdrlen
= (*print_info
->p
.printer
)(h
, sp
);
1689 * Print the raw packet data in hex and ASCII.
1693 * Include the link-layer header.
1695 hex_and_ascii_print("\n\t", sp
, h
->caplen
);
1698 * Don't include the link-layer header - and if
1699 * we have nothing past the link-layer header,
1702 if (h
->caplen
> hdrlen
)
1703 hex_and_ascii_print("\n\t", sp
+ hdrlen
,
1704 h
->caplen
- hdrlen
);
1708 * Print the raw packet data in hex.
1712 * Include the link-layer header.
1714 hex_print("\n\t", sp
, h
->caplen
);
1717 * Don't include the link-layer header - and if
1718 * we have nothing past the link-layer header,
1721 if (h
->caplen
> hdrlen
)
1722 hex_print("\n\t", sp
+ hdrlen
,
1723 h
->caplen
- hdrlen
);
1727 * Print the raw packet data in ASCII.
1731 * Include the link-layer header.
1733 ascii_print(sp
, h
->caplen
);
1736 * Don't include the link-layer header - and if
1737 * we have nothing past the link-layer header,
1740 if (h
->caplen
> hdrlen
)
1741 ascii_print(sp
+ hdrlen
, h
->caplen
- hdrlen
);
1754 * XXX - there should really be libpcap calls to get the version
1755 * number as a string (the string would be generated from #defines
1756 * at run time, so that it's not generated from string constants
1757 * in the library, as, on many UNIX systems, those constants would
1758 * be statically linked into the application executable image, and
1759 * would thus reflect the version of libpcap on the system on
1760 * which the application was *linked*, not the system on which it's
1763 * That routine should be documented, unlike the "version[]"
1764 * string, so that UNIX vendors providing their own libpcaps
1765 * don't omit it (as a couple of vendors have...).
1767 * Packet.dll should perhaps also export a routine to return the
1768 * version number of the Packet.dll code, to supply the
1769 * "Wpcap_version" information on Windows.
1771 char WDversion
[]="current-cvs.tcpdump.org";
1772 #if !defined(HAVE_GENERATED_VERSION)
1773 char version
[]="current-cvs.tcpdump.org";
1775 char pcap_version
[]="current-cvs.tcpdump.org";
1776 char Wpcap_version
[]="3.1";
1780 * By default, print the specified data out in hex and ASCII.
1783 ndo_default_print(netdissect_options
*ndo _U_
, const u_char
*bp
, u_int length
)
1785 hex_and_ascii_print("\n\t", bp
, length
); /* pass on lf and identation string */
1789 default_print(const u_char
*bp
, u_int length
)
1791 ndo_default_print(gndo
, bp
, length
);
1795 RETSIGTYPE
requestinfo(int signo _U_
)
1805 * Called once each second in verbose mode while dumping to file
1807 #ifdef USE_WIN32_MM_TIMER
1808 void CALLBACK
verbose_stats_dump (UINT timer_id _U_
, UINT msg _U_
, DWORD_PTR arg _U_
,
1809 DWORD_PTR dw1 _U_
, DWORD_PTR dw2 _U_
)
1811 struct pcap_stat stat
;
1813 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1814 fprintf(stderr
, "Got %u\r", packets_captured
);
1816 #elif defined(HAVE_ALARM)
1817 static void verbose_stats_dump(int sig _U_
)
1819 struct pcap_stat stat
;
1821 if (infodelay
== 0 && pcap_stats(pd
, &stat
) >= 0)
1822 fprintf(stderr
, "Got %u\r", packets_captured
);
1830 extern char version
[];
1831 #ifndef HAVE_PCAP_LIB_VERSION
1832 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
1833 extern char pcap_version
[];
1834 #else /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1835 static char pcap_version
[] = "unknown";
1836 #endif /* defined(WIN32) || defined(HAVE_PCAP_VERSION) */
1837 #endif /* HAVE_PCAP_LIB_VERSION */
1839 #ifdef HAVE_PCAP_LIB_VERSION
1841 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1843 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1845 (void)fprintf(stderr
, "%s\n",pcap_lib_version());
1846 #else /* HAVE_PCAP_LIB_VERSION */
1848 (void)fprintf(stderr
, "%s version %s, based on tcpdump version %s\n", program_name
, WDversion
, version
);
1849 (void)fprintf(stderr
, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version
, pcap_version
);
1851 (void)fprintf(stderr
, "%s version %s\n", program_name
, version
);
1852 (void)fprintf(stderr
, "libpcap version %s\n", pcap_version
);
1854 #endif /* HAVE_PCAP_LIB_VERSION */
1855 (void)fprintf(stderr
,
1856 "Usage: %s [-aAbd" D_FLAG
"ef" I_FLAG J_FLAG
"KlLnNOpqRStu" U_FLAG
"vxX]" B_FLAG_USAGE
" [ -c count ]\n", program_name
);
1857 (void)fprintf(stderr
,
1858 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
1859 (void)fprintf(stderr
,
1860 "\t\t[ -i interface ]" j_FLAG_USAGE
" [ -M secret ]\n");
1861 (void)fprintf(stderr
,
1862 "\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]\n");
1863 (void)fprintf(stderr
,
1864 "\t\t[ -W filecount ] [ -y datalinktype ] [ -z command ]\n");
1865 (void)fprintf(stderr
,
1866 "\t\t[ -Z user ] [ expression ]\n");
1874 ndo_error(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1878 (void)fprintf(stderr
, "%s: ", program_name
);
1880 (void)vfprintf(stderr
, fmt
, ap
);
1884 if (fmt
[-1] != '\n')
1885 (void)fputc('\n', stderr
);
1893 ndo_warning(netdissect_options
*ndo _U_
, const char *fmt
, ...)
1897 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
1899 (void)vfprintf(stderr
, fmt
, ap
);
1903 if (fmt
[-1] != '\n')
1904 (void)fputc('\n', stderr
);