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