]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Set default linktype LINUX_SLL2 when capturing on the "any" device
[tcpdump] / tcpdump.c
index 70cbdedfb8759ce95f5ee58abc1ddfd7c788c76d..06d3d9b9d624758f5ba26703b08a1a61eb589347 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -150,6 +150,8 @@ The Regents of the University of California.  All rights reserved.\n";
 
 #include "print.h"
 
+#include "fptype.h"
+
 #ifndef PATH_MAX
 #define PATH_MAX 1024
 #endif
@@ -218,6 +220,7 @@ static int timeout = 1000;          /* default timeout = 1000 ms = 1 s */
 #ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
 static int immediate_mode;
 #endif
+static int count_mode;
 
 static int infodelay;
 static int infoprint;
@@ -688,6 +691,7 @@ show_remote_devices_and_exit(void)
 #define OPTION_TSTAMP_MICRO            133
 #define OPTION_TSTAMP_NANO             134
 #define OPTION_FP_TYPE                 135
+#define OPTION_COUNT                   136
 
 static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(_WIN32)
@@ -731,6 +735,7 @@ static const struct option longopts[] = {
        { "debug-filter-parser", no_argument, NULL, 'Y' },
 #endif
        { "relinquish-privileges", required_argument, NULL, 'Z' },
+       { "count", no_argument, NULL, OPTION_COUNT },
        { "fp-type", no_argument, NULL, OPTION_FP_TYPE },
        { "number", no_argument, NULL, '#' },
        { "print", no_argument, NULL, OPTION_PRINT },
@@ -936,7 +941,7 @@ tstamp_precision_to_string(int precision)
  * necessary to make the standard I/O library work with an fdopen()ed
  * FILE * from that descriptor.
  *
- * A long time ago, in a galaxy far far away, AT&T decided that, instead
+ * A long time ago in a galaxy far, far away, AT&T decided that, instead
  * of providing separate APIs for getting and setting the FD_ flags on a
  * descriptor, getting and setting the O_ flags on a descriptor, and
  * locking files, they'd throw them all into a kitchen-sink fcntl() call
@@ -1789,6 +1794,10 @@ main(int argc, char **argv)
                                ndo->ndo_packettype = PT_RESP;
                        else if (ascii_strcasecmp(optarg, "ptp") == 0)
                                ndo->ndo_packettype = PT_PTP;
+                       else if (ascii_strcasecmp(optarg, "someip") == 0)
+                               ndo->ndo_packettype = PT_SOMEIP;
+                       else if (ascii_strcasecmp(optarg, "domain") == 0)
+                               ndo->ndo_packettype = PT_DOMAIN;
                        else
                                error("unknown packet type `%s'", optarg);
                        break;
@@ -1901,16 +1910,13 @@ main(int argc, char **argv)
                         * may differ (e.g., it might be 32-bit, 64-bit,
                         * or 80-bit).
                         */
-                       {
-                               union { /* int to float conversion buffer */
-                                       float f;
-                                       uint32_t i;
-                               } f;
-                               f.i = 0x4e93312d;
-                               printf("%.3f\n", f.f*8/1000000);
-                       }
+                       float_type_check(0x4e93312d);
                        return 0;
 
+               case OPTION_COUNT:
+                       count_mode = 1;
+                       break;
+
                default:
                        print_usage();
                        exit_tcpdump(S_ERR_HOST_PROGRAM);
@@ -1926,6 +1932,14 @@ main(int argc, char **argv)
                show_remote_devices_and_exit();
 #endif
 
+#if defined(DLT_LINUX_SLL2) && defined(HAVE_PCAP_SET_DATALINK)
+/* Set default linktype DLT_LINUX_SLL2 when capturing on the "any" device */
+               if (device != NULL &&
+                   strncmp (device, "any", strlen("any")) == 0
+                   && yflag_dlt == -1)
+                       yflag_dlt = DLT_LINUX_SLL2;
+#endif
+
        switch (ndo->ndo_tflag) {
 
        case 0: /* Default */
@@ -2174,7 +2188,8 @@ main(int argc, char **argv)
                        }
 #endif
                        (void)fprintf(stderr, "%s: data link type %s\n",
-                                     program_name, yflag_dlt_name);
+                                     program_name,
+                                     pcap_datalink_val_to_name(yflag_dlt));
                        (void)fflush(stderr);
                }
                i = pcap_snapshot(pd);
@@ -2455,7 +2470,7 @@ DIAG_ON_CLANG(assign-enum)
                 */
                if (!ndo->ndo_vflag && !WFileName) {
                        (void)fprintf(stderr,
-                           "%s: verbose output suppressed, use -v or -vv for full protocol decode\n",
+                           "%s: verbose output suppressed, use -v[v]... for full protocol decode\n",
                            program_name);
                } else
                        (void)fprintf(stderr, "%s: ", program_name);
@@ -2598,6 +2613,10 @@ DIAG_ON_CLANG(assign-enum)
        }
        while (ret != NULL);
 
+       if (count_mode && RFileName != NULL)
+               fprintf(stderr, "%u packet%s\n", packets_captured,
+                       PLURAL_SUFFIX(packets_captured));
+
        free(cmdbuf);
        pcap_freecode(&fcode);
        exit_tcpdump(status == -1 ? 1 : 0);
@@ -3030,7 +3049,8 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
 
        ++infodelay;
 
-       pretty_print_packet((netdissect_options *)user, h, sp, packets_captured);
+       if (!count_mode)
+               pretty_print_packet((netdissect_options *)user, h, sp, packets_captured);
 
        --infodelay;
        if (infoprint)
@@ -3117,7 +3137,9 @@ print_version(void)
        (void)fprintf (stderr, "Compiled with AddressSanitizer/GCC.\n");
 #elif defined(__has_feature)
 #  if __has_feature(address_sanitizer)
-       (void)fprintf (stderr, "Compiled with AddressSanitizer/CLang.\n");
+       (void)fprintf (stderr, "Compiled with AddressSanitizer/Clang.\n");
+#  elif __has_feature(memory_sanitizer)
+       (void)fprintf (stderr, "Compiled with MemorySanitizer/Clang.\n");
 #  endif
 #endif /* __SANITIZE_ADDRESS__ or __has_feature */
 }
@@ -3128,7 +3150,7 @@ print_usage(void)
 {
        print_version();
        (void)fprintf(stderr,
-"Usage: %s [-aAbd" D_FLAG "efhH" I_FLAG J_FLAG "KlLnNOpqStu" U_FLAG "vxX#]" B_FLAG_USAGE " [ -c count ]\n", program_name);
+"Usage: %s [-Abd" D_FLAG "efhH" I_FLAG J_FLAG "KlLnNOpqStu" U_FLAG "vxX#]" B_FLAG_USAGE " [ -c count ] [--count]\n", program_name);
        (void)fprintf(stderr,
 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
        (void)fprintf(stderr,