]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Add SunATM support, based on code from Yen Yen Lim at North Dakota State
[tcpdump] / tcpdump.c
index 785dce7aa444e0f3927ac8c899d5cddf2b675639..43fad291cfd1e2be244ad34eb126027e055e9722 100644 (file)
--- 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.174 2002-02-05 10:07:40 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 */
 
@@ -160,6 +161,15 @@ static struct printer printers[] = {
 #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 },
 };
@@ -218,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)
@@ -236,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;
 
@@ -294,7 +310,7 @@ main(int argc, char **argv)
                                      program_name, optarg);
                        (void)fprintf(stderr, "(no libsmi support)\n");
 #endif
-                       
+
                case 'O':
                        Oflag = 0;
                        break;
@@ -357,7 +373,7 @@ main(int argc, char **argv)
                case 'u':
                        ++uflag;
                        break;
-                       
+
                case 'v':
                        ++vflag;
                        break;
@@ -371,7 +387,7 @@ main(int argc, char **argv)
                        break;
 
                case 'X':
-                       ++xflag;
+                       ++xflag;
                        ++Xflag;
                        break;
 
@@ -487,6 +503,8 @@ 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)
@@ -506,7 +524,8 @@ cleanup(int signo)
                putc('\n', stderr);
                info(1);
        }
-       exit(0);
+       if (signo)
+               exit(0);
 }
 
 void
@@ -564,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
@@ -641,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,