X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/62082d1b423f111d713a39dd1bb9744bc0110210..464c44fbd1394ac006d8d99f16e80ead423c1c47:/tcpdump.c?ds=inline diff --git a/tcpdump.c b/tcpdump.c index d310eb98..43fad291 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -30,7 +30,7 @@ static const char copyright[] = "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\ The Regents of the University of California. All rights reserved.\n"; static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.171 2001-10-27 08:23:11 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.179 2002-07-11 09:17:25 guy Exp $ (LBL)"; #endif /* @@ -83,6 +83,7 @@ int vflag; /* verbose */ int xflag; /* print packet in hex */ int Xflag; /* print packet in ascii as well as hex */ off_t Cflag = 0; /* rotate dump files after this many bytes */ +int Aflag = 0; /* print packet only in ascii observing LF, CR, TAB, SPACE */ char *espsecret = NULL; /* ESP secret key */ @@ -157,6 +158,18 @@ static struct printer printers[] = { #endif #ifdef DLT_LTALK { ltalk_if_print, DLT_LTALK }, +#endif +#ifdef DLT_PFLOG + { pflog_if_print, DLT_PFLOG }, +#endif +#ifdef DLT_FR + { fr_if_print, DLT_FR }, +#endif +#ifdef DLT_FRELAY + { fr_if_print, DLT_FRELAY }, +#endif +#ifdef DLT_SUNATM + { sunatm_if_print, DLT_SUNATM }, #endif { NULL, 0 }, }; @@ -195,7 +208,7 @@ main(int argc, char **argv) pcap_handler printer; struct bpf_program fcode; RETSIGTYPE (*oldhandler)(int); - struct dump_info info; + struct dump_info dumpinfo; u_char *pcap_userdata; char ebuf[PCAP_ERRBUF_SIZE]; @@ -215,16 +228,22 @@ main(int argc, char **argv) #ifdef LIBSMI smiInit("tcpdump"); #endif - + opterr = 0; while ( - (op = getopt(argc, argv, "ac:C:deE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1) + (op = getopt(argc, argv, "aAc:C:deE:fF:i:lm:nNOpqr:Rs:StT:uvw:xXY")) != -1) switch (op) { case 'a': ++aflag; break; + case 'A': + ++xflag; + ++Xflag; + ++Aflag; + break; + case 'c': cnt = atoi(optarg); if (cnt <= 0) @@ -233,7 +252,7 @@ main(int argc, char **argv) case 'C': Cflag = atoi(optarg) * 1000000; - if (Cflag < 0) + if (Cflag < 0) error("invalid file size %s", optarg); break; @@ -291,7 +310,7 @@ main(int argc, char **argv) program_name, optarg); (void)fprintf(stderr, "(no libsmi support)\n"); #endif - + case 'O': Oflag = 0; break; @@ -354,7 +373,7 @@ main(int argc, char **argv) case 'u': ++uflag; break; - + case 'v': ++vflag; break; @@ -368,7 +387,7 @@ main(int argc, char **argv) break; case 'X': - ++xflag; + ++xflag; ++Xflag; break; @@ -461,10 +480,10 @@ main(int argc, char **argv) error("%s", pcap_geterr(pd)); if (Cflag != 0) { printer = dump_and_trunc; - info.WFileName = WFileName; - info.pd = pd; - info.p = p; - pcap_userdata = (u_char *)&info; + dumpinfo.WFileName = WFileName; + dumpinfo.pd = pd; + dumpinfo.p = p; + pcap_userdata = (u_char *)&dumpinfo; } else { printer = pcap_dump; pcap_userdata = (u_char *)p; @@ -484,8 +503,12 @@ main(int argc, char **argv) if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) { (void)fprintf(stderr, "%s: pcap_loop: %s\n", program_name, pcap_geterr(pd)); + cleanup(0); + pcap_close(pd); exit(1); } + if (RFileName == NULL) + info(1); pcap_close(pd); exit(0); } @@ -501,7 +524,8 @@ cleanup(int signo) putc('\n', stderr); info(1); } - exit(0); + if (signo) + exit(0); } void @@ -559,7 +583,7 @@ dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) char *name; info = (struct dump_info *)user; - + /* * XXX - this won't prevent capture files from getting * larger than Cflag - the last packet written to the @@ -567,6 +591,8 @@ dump_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) */ if (ftell((FILE *)info->p) > Cflag) { name = (char *) malloc(strlen(info->WFileName) + 4); + if (name == NULL) + error("dump_and_trunc: malloc"); strcpy(name, info->WFileName); swebitoa(cnt, name + strlen(info->WFileName)); cnt++; @@ -634,7 +660,7 @@ usage(void) (void)fprintf(stderr, "%s version %s\n", program_name, version); (void)fprintf(stderr, "libpcap version %s\n", pcap_version); (void)fprintf(stderr, -"Usage: %s [-adeflnNOpqRStuvxX] [ -c count ] [ -C file_size ]\n", program_name); +"Usage: %s [-aAdeflnNOpqRStuvxX] [ -c count ] [ -C file_size ]\n", program_name); (void)fprintf(stderr, "\t\t[ -F file ] [ -i interface ] [ -r file ] [ -s snaplen ]\n"); (void)fprintf(stderr,