]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Print packets for unsupported link-layer protocols in hexadecimal/ASCII 851/head
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 9 May 2020 17:32:05 +0000 (19:32 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 10 May 2020 09:05:59 +0000 (11:05 +0200)
This avoids to get only:
tcpdump: packet printing is not supported for link type XYZ: use -w

The default printing is like:
18:45:52.723872 UNSUPPORTED
        0x0000:  001f 0000 0540 6078 725d 586d 4d66 4671  .....@`xr]XmMfFq
        0x0010:  6d58 4d5c 7159 5f71 565c 556c 4e71 7171  mXM\qY_qV\UlNqqq
        0x0020:  7171 7171 7171 7171 7171 7171 7171 5180  qqqqqqqqqqqqqqQ.
        0x0030:  7f7f                                     ..
18:45:52.755995 UNSUPPORTED
        0x0000:  001f 0000 0540 6043 7851 807f 7f         .....@`CxQ...
        [...]

CMakeLists.txt
Makefile.in
netdissect.h
print-unsupported.c [new file with mode: 0644]
print.c

index 832f20c7b0886a934116a5ef4c36a33e52e3c40f..4ea6deca91f042db68e805bcd3bfe0db61adc997 100644 (file)
@@ -1077,6 +1077,7 @@ set(NETDISSECT_SOURCE_LIST_C
     print-token.c
     print-udld.c
     print-udp.c
+    print-unsupported.c
     print-usb.c
     print-vjc.c
     print-vqp.c
index 0fe4d7297db328fea0663701733d5449ecbfbaac..25e43ab691fd7051f8890c71df67cd3c48e9b97e 100644 (file)
@@ -233,6 +233,7 @@ LIBNETDISSECT_SRC=\
        print-token.c \
        print-udld.c \
        print-udp.c \
+       print-unsupported.c \
        print-usb.c \
        print-vjc.c \
        print-vqp.c \
index 65a0d9878785eabd04eb1189d8b0116663034702..1c83361e029bb34dfc79be0c1453f4be1a7b1803 100644 (file)
@@ -524,6 +524,7 @@ extern u_int sll2_if_print IF_PRINTER_ARGS;
 extern void sunatm_if_print IF_PRINTER_ARGS;
 extern void symantec_if_print IF_PRINTER_ARGS;
 extern u_int token_if_print IF_PRINTER_ARGS;
+extern void unsupported_if_print IF_PRINTER_ARGS;
 extern void usb_linux_48_byte_if_print IF_PRINTER_ARGS;
 extern void usb_linux_64_byte_if_print IF_PRINTER_ARGS;
 extern u_int vsock_if_print IF_PRINTER_ARGS;
diff --git a/print-unsupported.c b/print-unsupported.c
new file mode 100644 (file)
index 0000000..009cf6f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 The TCPDUMP project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code
+ * distributions retain the above copyright notice and this paragraph
+ * in its entirety, and (2) distributions including binary code include
+ * the above copyright notice and this paragraph in its entirety in
+ * the documentation or other materials provided with the distribution.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
+ * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
+ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE.
+ */
+
+/* \summary: unsupported link-layer protocols printer */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "netdissect-stdinc.h"
+
+#include "netdissect.h"
+
+void
+unsupported_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
+                    const u_char *p)
+{
+       ndo->ndo_protocol = "unsupported";
+       nd_print_protocol_caps(ndo);
+       hex_and_ascii_print(ndo, "\n\t", p, h->caplen);
+}
diff --git a/print.c b/print.c
index 7224e2e6e28c8f054995a63a52dd068feda0edb8..a7f006f965e6eae64e44ef747caec438db1e9638 100644 (file)
--- a/print.c
+++ b/print.c
@@ -379,20 +379,11 @@ has_printer(int type)
 if_printer_t
 get_if_printer(netdissect_options *ndo, int type)
 {
-       const char *dltname;
        if_printer_t printer;
 
        printer = lookup_printer(ndo, type);
-       if (printer.printer == NULL) {
-               dltname = pcap_datalink_val_to_name(type);
-               if (dltname != NULL)
-                       (*ndo->ndo_error)(ndo, S_ERR_ND_NO_PRINTER,
-                                         "packet printing is not supported for link type %s: use -w",
-                                         dltname);
-               else
-                       (*ndo->ndo_error)(ndo, S_ERR_ND_NO_PRINTER,
-                                         "packet printing is not supported for link type %d: use -w", type);
-       }
+       if (printer.printer == NULL)
+               printer.void_printer = unsupported_if_print;
        return printer;
 }