]> The Tcpdump Group git mirrors - tcpdump/blob - tcpdump.c
Add support for RFC 2625 IP-over-Fibre Channel.
[tcpdump] / tcpdump.c
1 /*
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.
4 *
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
16 * written permission.
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.
20 *
21 * Support for splitting captures into multiple files with a maximum
22 * file size:
23 *
24 * Copyright (c) 2001
25 * Seth Webster <swebster@sst.ll.mit.edu>
26 */
27
28 #ifndef lint
29 static const char copyright[] =
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[] =
33 "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.187 2002-10-18 09:17:48 guy Exp $ (LBL)";
34 #endif
35
36 /*
37 * tcpdump - monitor tcp/ip traffic on an ethernet.
38 *
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.
42 */
43
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47
48 #include <tcpdump-stdinc.h>
49
50 #ifdef WIN32
51 #include "getopt.h"
52 #include "w32_fzs.h"
53 extern int strcasecmp (const char *__s1, const char *__s2);
54 extern int SIZE_BUF;
55 #define off_t long
56 #define uint UINT
57 #endif /* WIN32 */
58
59 #include <pcap.h>
60 #include <signal.h>
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <string.h>
64
65
66 #include "interface.h"
67 #include "addrtoname.h"
68 #include "machdep.h"
69 #include "setsignal.h"
70 #include "gmt2local.h"
71
72 int aflag; /* translate network and broadcast addresses */
73 int dflag; /* print filter code */
74 int eflag; /* print ethernet header */
75 int fflag; /* don't translate "foreign" IP address */
76 int nflag; /* leave addresses as numbers */
77 int Nflag; /* remove domains from printed host names */
78 int Oflag = 1; /* run filter code optimizer */
79 int pflag; /* don't go promiscuous */
80 int qflag; /* quick (shorter) output */
81 int Rflag = 1; /* print sequence # field in AH/ESP*/
82 int sflag = 0; /* use the libsmi to translate OIDs */
83 int Sflag; /* print raw TCP sequence numbers */
84 int tflag = 1; /* print packet arrival time */
85 int uflag = 0; /* Print undecoded NFS handles */
86 int vflag; /* verbose */
87 int xflag; /* print packet in hex */
88 int Xflag; /* print packet in ascii as well as hex */
89 off_t Cflag = 0; /* rotate dump files after this many bytes */
90 int Aflag = 0; /* print packet only in ascii observing LF, CR, TAB, SPACE */
91
92 char *espsecret = NULL; /* ESP secret key */
93
94 int packettype;
95
96 int infodelay;
97 int infoprint;
98
99 char *program_name;
100
101 int32_t thiszone; /* seconds offset from gmt to local time */
102
103 /* Forwards */
104 static RETSIGTYPE cleanup(int);
105 static void usage(void) __attribute__((noreturn));
106
107 static void dump_and_trunc(u_char *, const struct pcap_pkthdr *, const u_char *);
108
109 #ifdef SIGINFO
110 RETSIGTYPE requestinfo(int);
111 #endif
112
113 /* Length of saved portion of packet. */
114 int snaplen = DEFAULT_SNAPLEN;
115
116 struct printer {
117 pcap_handler f;
118 int type;
119 };
120
121 static struct printer printers[] = {
122 { arcnet_if_print, DLT_ARCNET },
123 { ether_if_print, DLT_EN10MB },
124 { token_if_print, DLT_IEEE802 },
125 #ifdef DLT_LANE8023
126 { lane_if_print, DLT_LANE8023 },
127 #endif
128 #ifdef DLT_CIP
129 { cip_if_print, DLT_CIP },
130 #endif
131 #ifdef DLT_ATM_CLIP
132 { cip_if_print, DLT_ATM_CLIP },
133 #endif
134 { sl_if_print, DLT_SLIP },
135 { sl_bsdos_if_print, DLT_SLIP_BSDOS },
136 { ppp_if_print, DLT_PPP },
137 { ppp_bsdos_if_print, DLT_PPP_BSDOS },
138 { fddi_if_print, DLT_FDDI },
139 { null_if_print, DLT_NULL },
140 #ifdef DLT_LOOP
141 { null_if_print, DLT_LOOP },
142 #endif
143 { raw_if_print, DLT_RAW },
144 { atm_if_print, DLT_ATM_RFC1483 },
145 #ifdef DLT_C_HDLC
146 { chdlc_if_print, DLT_C_HDLC },
147 #endif
148 #ifdef DLT_HDLC
149 { chdlc_if_print, DLT_HDLC },
150 #endif
151 #ifdef DLT_PPP_SERIAL
152 { ppp_hdlc_if_print, DLT_PPP_SERIAL },
153 #endif
154 #ifdef DLT_PPP_ETHER
155 { pppoe_if_print, DLT_PPP_ETHER },
156 #endif
157 #ifdef DLT_LINUX_SLL
158 { sll_if_print, DLT_LINUX_SLL },
159 #endif
160 #ifdef DLT_IEEE802_11
161 { ieee802_11_if_print, DLT_IEEE802_11},
162 #endif
163 #ifdef DLT_LTALK
164 { ltalk_if_print, DLT_LTALK },
165 #endif
166 #ifdef DLT_PFLOG
167 { pflog_if_print, DLT_PFLOG },
168 #endif
169 #ifdef DLT_FR
170 { fr_if_print, DLT_FR },
171 #endif
172 #ifdef DLT_FRELAY
173 { fr_if_print, DLT_FRELAY },
174 #endif
175 #ifdef DLT_SUNATM
176 { sunatm_if_print, DLT_SUNATM },
177 #endif
178 #ifdef DLT_IP_OVER_FC
179 { ipfc_if_print, DLT_IP_OVER_FC },
180 #endif
181 { NULL, 0 },
182 };
183
184 static pcap_handler
185 lookup_printer(int type)
186 {
187 struct printer *p;
188
189 for (p = printers; p->f; ++p)
190 if (type == p->type)
191 return p->f;
192
193 error("unknown data link type %d", type);
194 /* NOTREACHED */
195 }
196
197 static pcap_t *pd;
198
199 extern int optind;
200 extern int opterr;
201 extern char *optarg;
202
203 struct dump_info {
204 char *WFileName;
205 pcap_t *pd;
206 pcap_dumper_t *p;
207 };
208
209 int
210 main(int argc, char **argv)
211 {
212 register int cnt, op, i;
213 bpf_u_int32 localnet, netmask;
214 register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName;
215 pcap_handler printer;
216 struct bpf_program fcode;
217 #ifndef WIN32
218 RETSIGTYPE (*oldhandler)(int);
219 #endif
220 struct dump_info dumpinfo;
221 u_char *pcap_userdata;
222 char ebuf[PCAP_ERRBUF_SIZE];
223 #ifdef HAVE_PCAP_FINDALLDEVS
224 pcap_if_t *devpointer;
225 int devnum;
226 #endif
227 #ifdef WIN32
228 DWORD dwVersion;
229 DWORD dwWindowsMajorVersion;
230 u_int UserBufferSize=1000000;
231 #endif
232
233 #ifdef WIN32
234 dwVersion=GetVersion(); /* get the OS version */
235 dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
236 if(wsockinit()!=0) return 1;
237 #endif /* WIN32 */
238
239 cnt = -1;
240 device = NULL;
241 infile = NULL;
242 RFileName = NULL;
243 WFileName = NULL;
244 if ((cp = strrchr(argv[0], '/')) != NULL)
245 program_name = cp + 1;
246 else
247 program_name = argv[0];
248
249 if (abort_on_misalignment(ebuf, sizeof(ebuf)) < 0)
250 error("%s", ebuf);
251
252 #ifdef LIBSMI
253 smiInit("tcpdump");
254 #endif
255
256 opterr = 0;
257 while (
258 #ifdef WIN32
259 (op = getopt(argc, argv, "aAB:c:C:dDeE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1)
260 #else /* WIN32 */
261 #ifdef HAVE_PCAP_FINDALLDEVS
262 (op = getopt(argc, argv, "aAc:C:dDeE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1)
263 #else /* HAVE_PCAP_FINDALLDEVS */
264 (op = getopt(argc, argv, "aAc:C:deE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1)
265 #endif /* HAVE_PCAP_FINDALLDEVS */
266 #endif /* WIN32 */
267 switch (op) {
268
269 case 'a':
270 ++aflag;
271 break;
272
273 case 'A':
274 ++xflag;
275 ++Xflag;
276 ++Aflag;
277 break;
278
279 #ifdef WIN32
280 case 'B':
281 UserBufferSize = atoi(optarg)*1024;
282 if (UserBufferSize < 0)
283 error("invalid packet buffer size %s", optarg);
284 break;
285 #endif /* WIN32 */
286
287 case 'c':
288 cnt = atoi(optarg);
289 if (cnt <= 0)
290 error("invalid packet count %s", optarg);
291 break;
292
293 case 'C':
294 Cflag = atoi(optarg) * 1000000;
295 if (Cflag < 0)
296 error("invalid file size %s", optarg);
297 break;
298
299 case 'd':
300 ++dflag;
301 break;
302
303 #ifdef HAVE_PCAP_FINDALLDEVS
304 case 'D':
305 if (pcap_findalldevs(&devpointer, ebuf) < 0)
306 error("%s", ebuf);
307 else {
308 for (i = 0; devpointer != 0; i++) {
309 printf("%d.%s", i+1, devpointer->name);
310 if (devpointer->description != NULL)
311 printf(" (%s)", devpointer->description);
312 printf("\n");
313 devpointer = devpointer->next;
314 }
315 }
316 return 0;
317 #endif /* HAVE_PCAP_FINDALLDEVS */
318
319 case 'e':
320 ++eflag;
321 break;
322
323 case 'E':
324 #ifndef HAVE_LIBCRYPTO
325 warning("crypto code not compiled in");
326 #endif
327 espsecret = optarg;
328 break;
329
330 case 'f':
331 ++fflag;
332 break;
333
334 case 'F':
335 infile = optarg;
336 break;
337
338 case 'i':
339 if (optarg[0] == '0' && optarg[1] == 0)
340 error("Invalid adapter index");
341
342 #ifdef HAVE_PCAP_FINDALLDEVS
343 /*
344 * If the argument is a number, treat it as
345 * an index into the list of adapters, as
346 * printed by "tcpdump -D".
347 *
348 * This should be OK on UNIX systems, as interfaces
349 * shouldn't have names that begin with digits.
350 * It can be useful on Windows, where more than
351 * one interface can have the same name.
352 */
353 if ((devnum = atoi(optarg)) != 0) {
354 if (devnum < 0)
355 error("Invalid adapter index");
356
357 if (pcap_findalldevs(&devpointer, ebuf) < 0)
358 error("%s", ebuf);
359 else {
360 for (i = 0; i < devnum-1; i++){
361 devpointer = devpointer->next;
362 if (devpointer == NULL)
363 error("Invalid adapter index");
364 }
365 }
366 device = devpointer->name;
367 break;
368 }
369 #endif /* HAVE_PCAP_FINDALLDEVS */
370 device = optarg;
371 break;
372
373 case 'l':
374 #ifdef HAVE_SETLINEBUF
375 setlinebuf(stdout);
376 #else
377 setvbuf(stdout, NULL, _IOLBF, 0);
378 #endif
379 break;
380
381 case 'n':
382 ++nflag;
383 break;
384
385 case 'N':
386 ++Nflag;
387 break;
388
389 case 'm':
390 #ifdef LIBSMI
391 if (smiLoadModule(optarg) == 0) {
392 error("could not load MIB module %s", optarg);
393 }
394 sflag = 1;
395 #else
396 (void)fprintf(stderr, "%s: ignoring option `-m %s' ",
397 program_name, optarg);
398 (void)fprintf(stderr, "(no libsmi support)\n");
399 #endif
400
401 case 'O':
402 Oflag = 0;
403 break;
404
405 case 'p':
406 ++pflag;
407 break;
408
409 case 'q':
410 ++qflag;
411 break;
412
413 case 'r':
414 RFileName = optarg;
415 break;
416
417 case 'R':
418 Rflag = 0;
419 break;
420
421 case 's': {
422 char *end;
423
424 snaplen = strtol(optarg, &end, 0);
425 if (optarg == end || *end != '\0'
426 || snaplen < 0 || snaplen > 65535)
427 error("invalid snaplen %s", optarg);
428 else if (snaplen == 0)
429 snaplen = 65535;
430 break;
431 }
432
433 case 'S':
434 ++Sflag;
435 break;
436
437 case 't':
438 --tflag;
439 break;
440
441 case 'T':
442 if (strcasecmp(optarg, "vat") == 0)
443 packettype = PT_VAT;
444 else if (strcasecmp(optarg, "wb") == 0)
445 packettype = PT_WB;
446 else if (strcasecmp(optarg, "rpc") == 0)
447 packettype = PT_RPC;
448 else if (strcasecmp(optarg, "rtp") == 0)
449 packettype = PT_RTP;
450 else if (strcasecmp(optarg, "rtcp") == 0)
451 packettype = PT_RTCP;
452 else if (strcasecmp(optarg, "snmp") == 0)
453 packettype = PT_SNMP;
454 else if (strcasecmp(optarg, "cnfp") == 0)
455 packettype = PT_CNFP;
456 else
457 error("unknown packet type `%s'", optarg);
458 break;
459
460 case 'u':
461 ++uflag;
462 break;
463
464 case 'v':
465 ++vflag;
466 break;
467
468 case 'w':
469 WFileName = optarg;
470 break;
471
472 case 'x':
473 ++xflag;
474 break;
475
476 case 'X':
477 ++xflag;
478 ++Xflag;
479 break;
480
481 #if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
482 case 'Y':
483 {
484 /* Undocumented flag */
485 #ifdef HAVE_PCAP_DEBUG
486 extern int pcap_debug;
487 pcap_debug = 1;
488 #else
489 extern int yydebug;
490 yydebug = 1;
491 #endif
492 }
493 break;
494 #endif
495 default:
496 usage();
497 /* NOTREACHED */
498 }
499
500 if (aflag && nflag)
501 error("-a and -n options are incompatible");
502
503 if (tflag > 0)
504 thiszone = gmt2local(0);
505
506 if (RFileName != NULL) {
507 /*
508 * We don't need network access, so set it back to the user id.
509 * Also, this prevents the user from reading anyone's
510 * trace file.
511 */
512 #ifndef WIN32
513 setuid(getuid());
514 #endif /* WIN32 */
515
516 pd = pcap_open_offline(RFileName, ebuf);
517 if (pd == NULL)
518 error("%s", ebuf);
519 localnet = 0;
520 netmask = 0;
521 if (fflag != 0)
522 error("-f and -r options are incompatible");
523 } else {
524 if (device == NULL) {
525 device = pcap_lookupdev(ebuf);
526 if (device == NULL)
527 error("%s", ebuf);
528 }
529 #ifdef WIN32
530 PrintCapBegins(program_name,device);
531 #endif /* WIN32 */
532 *ebuf = '\0';
533 pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf);
534 if (pd == NULL)
535 error("%s", ebuf);
536 else if (*ebuf)
537 warning("%s", ebuf);
538 #ifdef WIN32
539 if(UserBufferSize != 1000000)
540 if(pcap_setbuff(pd, UserBufferSize)==-1){
541 error("%s", pcap_geterr(pd));
542 }
543 #endif /* WIN32 */
544 i = pcap_snapshot(pd);
545 if (snaplen < i) {
546 warning("snaplen raised from %d to %d", snaplen, i);
547 snaplen = i;
548 }
549 if (pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) {
550 localnet = 0;
551 netmask = 0;
552 warning("%s", ebuf);
553 }
554 /*
555 * Let user own process after socket has been opened.
556 */
557 #ifndef WIN32
558 setuid(getuid());
559 #endif /* WIN32 */
560 }
561 if (infile)
562 cmdbuf = read_infile(infile);
563 else
564 cmdbuf = copy_argv(&argv[optind]);
565
566 if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0)
567 error("%s", pcap_geterr(pd));
568 if (dflag) {
569 bpf_dump(&fcode, dflag);
570 pcap_close(pd);
571 exit(0);
572 }
573 init_addrtoname(localnet, netmask);
574
575 (void)setsignal(SIGTERM, cleanup);
576 (void)setsignal(SIGINT, cleanup);
577 /* Cooperate with nohup(1) */
578 #ifndef WIN32
579 if ((oldhandler = setsignal(SIGHUP, cleanup)) != SIG_DFL)
580 (void)setsignal(SIGHUP, oldhandler);
581 #endif /* WIN32 */
582
583 if (pcap_setfilter(pd, &fcode) < 0)
584 error("%s", pcap_geterr(pd));
585 if (WFileName) {
586 pcap_dumper_t *p = pcap_dump_open(pd, WFileName);
587 if (p == NULL)
588 error("%s", pcap_geterr(pd));
589 if (Cflag != 0) {
590 printer = dump_and_trunc;
591 dumpinfo.WFileName = WFileName;
592 dumpinfo.pd = pd;
593 dumpinfo.p = p;
594 pcap_userdata = (u_char *)&dumpinfo;
595 } else {
596 printer = pcap_dump;
597 pcap_userdata = (u_char *)p;
598 }
599 } else {
600 printer = lookup_printer(pcap_datalink(pd));
601 pcap_userdata = 0;
602 #ifdef SIGINFO
603 (void)setsignal(SIGINFO, requestinfo);
604 #endif
605 }
606 #ifndef WIN32
607 if (RFileName == NULL) {
608 (void)fprintf(stderr, "%s: listening on %s\n",
609 program_name, device);
610 (void)fflush(stderr);
611 }
612 #endif /* WIN32 */
613 if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) {
614 (void)fprintf(stderr, "%s: pcap_loop: %s\n",
615 program_name, pcap_geterr(pd));
616 cleanup(0);
617 pcap_close(pd);
618 exit(1);
619 }
620 if (RFileName == NULL)
621 info(1);
622 pcap_close(pd);
623 exit(0);
624 }
625
626 /* make a clean exit on interrupts */
627 static RETSIGTYPE
628 cleanup(int signo)
629 {
630
631 /* Can't print the summary if reading from a savefile */
632 if (pd != NULL && pcap_file(pd) == NULL) {
633 (void)fflush(stdout);
634 putc('\n', stderr);
635 info(1);
636 }
637 if (signo)
638 exit(0);
639 }
640
641 void
642 info(register int verbose)
643 {
644 struct pcap_stat stat;
645
646 if (pcap_stats(pd, &stat) < 0) {
647 (void)fprintf(stderr, "pcap_stats: %s\n", pcap_geterr(pd));
648 return;
649 }
650
651 if (!verbose)
652 fprintf(stderr, "%s: ", program_name);
653
654 (void)fprintf(stderr, "%d packets received by filter", stat.ps_recv);
655 if (!verbose)
656 fputs(", ", stderr);
657 else
658 putc('\n', stderr);
659 (void)fprintf(stderr, "%d packets dropped by kernel\n", stat.ps_drop);
660 infoprint = 0;
661 }
662
663 static void
664 reverse(char *s)
665 {
666 int i, j, c;
667
668 for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
669 c = s[i];
670 s[i] = s[j];
671 s[j] = c;
672 }
673 }
674
675
676 static void
677 swebitoa(unsigned int n, char *s)
678 {
679 unsigned int i;
680
681 i = 0;
682 do {
683 s[i++] = n % 10 + '0';
684 } while ((n /= 10) > 0);
685
686 s[i] = '\0';
687 reverse(s);
688 }
689
690 static void
691 dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
692 {
693 struct dump_info *info;
694 static uint cnt = 2;
695 char *name;
696
697 info = (struct dump_info *)user;
698
699 /*
700 * XXX - this won't prevent capture files from getting
701 * larger than Cflag - the last packet written to the
702 * file could put it over Cflag.
703 */
704 if (ftell((FILE *)info->p) > Cflag) {
705 name = (char *) malloc(strlen(info->WFileName) + 4);
706 if (name == NULL)
707 error("dump_and_trunc: malloc");
708 strcpy(name, info->WFileName);
709 swebitoa(cnt, name + strlen(info->WFileName));
710 cnt++;
711 pcap_dump_close(info->p);
712 info->p = pcap_dump_open(info->pd, name);
713 free(name);
714 if (info->p == NULL)
715 error("%s", pcap_geterr(pd));
716 }
717
718 pcap_dump((u_char *)info->p, h, sp);
719 }
720
721 /* Like default_print() but data need not be aligned */
722 void
723 default_print_unaligned(register const u_char *cp, register u_int length)
724 {
725 register u_int i, s;
726 register int nshorts;
727
728 if (Xflag) {
729 ascii_print(cp, length);
730 return;
731 }
732 nshorts = (u_int) length / sizeof(u_short);
733 i = 0;
734 while (--nshorts >= 0) {
735 if ((i++ % 8) == 0)
736 (void)printf("\n\t\t\t");
737 s = *cp++;
738 (void)printf(" %02x%02x", s, *cp++);
739 }
740 if (length & 1) {
741 if ((i % 8) == 0)
742 (void)printf("\n\t\t\t");
743 (void)printf(" %02x", *cp);
744 }
745 }
746
747 #ifdef WIN32
748 /*
749 * XXX - there should really be libpcap calls to get the version
750 * number as a string (the string would be generated from #defines
751 * at run time, so that it's not generated from string constants
752 * in the library, as, on many UNIX systems, those constants would
753 * be statically linked into the application executable image, and
754 * would thus reflect the version of libpcap on the system on
755 * which the application was *linked*, not the system on which it's
756 * *running*.
757 *
758 * That routine should be documented, unlike the "version[]"
759 * string, so that UNIX vendors providing their own libpcaps
760 * don't omit it (as a couple of vendors have...).
761 *
762 * Packet.dll should perhaps also export a routine to return the
763 * version number of the Packet.dll code, to supply the
764 * "Wpcap_version" information on Windows.
765 */
766 char WDversion[]="current-cvs.tcpdump.org";
767 char version[]="current-cvs.tcpdump.org";
768 char pcap_version[]="current-cvs.tcpdump.org";
769 char Wpcap_version[]="3.0 alpha";
770 #endif
771
772 /*
773 * By default, print the packet out in hex.
774 */
775 void
776 default_print(register const u_char *bp, register u_int length)
777 {
778 default_print_unaligned(bp, length);
779 }
780
781 #ifdef SIGINFO
782 RETSIGTYPE requestinfo(int signo _U_)
783 {
784 if (infodelay)
785 ++infoprint;
786 else
787 info(0);
788 }
789 #endif
790
791 static void
792 usage(void)
793 {
794 extern char version[];
795 #if defined(WIN32) || defined(HAVE_PCAP_VERSION)
796 extern char pcap_version[];
797 #else
798 static char pcap_version[] = "unknown";
799 #endif
800
801 #ifdef WIN32
802 (void)fprintf(stderr, "%s version %s, based on tcpdump version %s\n", program_name, WDversion, version);
803 (void)fprintf(stderr, "WinPcap version %s, based on libpcap version %s\n",Wpcap_version, pcap_version);
804 #else
805 (void)fprintf(stderr, "%s version %s\n", program_name, version);
806 (void)fprintf(stderr, "libpcap version %s\n", pcap_version);
807 #endif /* WIN32 */
808 (void)fprintf(stderr,
809 #ifdef WIN32
810 "Usage: %s [-aAdDeflnNOpqRStuvxX] [-B size] [-c count] [ -C file_size ]\n", program_name);
811 #else /* WIN32 */
812 #ifdef HAVE_PCAP_FINDALLDEVS
813 "Usage: %s [-aAdDeflnNOpqRStuvxX] [-c count] [ -C file_size ]\n", program_name);
814 #else /* HAVE_PCAP_FINDALLDEVS */
815 "Usage: %s [-aAdeflnNOpqRStuvxX] [-c count] [ -C file_size ]\n", program_name);
816 #endif /* HAVE_PCAP_FINDALLDEVS */
817 #endif /* WIN32 */
818 (void)fprintf(stderr,
819 "\t\t[ -F file ] [ -i interface ] [ -r file ] [ -s snaplen ]\n");
820 (void)fprintf(stderr,
821 "\t\t[ -T type ] [ -w file ] [ -E algo:secret ] [ expression ]\n");
822 exit(1);
823 }