]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ppi.c
Autosar SOME/IP protocol support
[tcpdump] / print-ppi.c
index d7110d12de91cf4f12cea645a67a6db33f3a0059..fe85fa51e699136d760f8bf131686ee0ec9c6606 100644 (file)
@@ -5,26 +5,27 @@
 /* \summary: Oracle DLT_PPI printer */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #include "netdissect.h"
 #include "extract.h"
 
+
 typedef struct ppi_header {
-       uint8_t         ppi_ver;
-       uint8_t         ppi_flags;
-       uint16_t        ppi_len;
-       uint32_t        ppi_dlt;
+       nd_uint8_t      ppi_ver;
+       nd_uint8_t      ppi_flags;
+       nd_uint16_t     ppi_len;
+       nd_uint32_t     ppi_dlt;
 } ppi_header_t;
 
 #define        PPI_HDRLEN      8
 
 #ifdef DLT_PPI
 
-static inline void
+static void
 ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
 {
        const ppi_header_t *hdr;
@@ -34,12 +35,12 @@ ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
        hdr = (const ppi_header_t *)bp;
 
-       len = EXTRACT_LE_U_2(&hdr->ppi_len);
-       dlt = EXTRACT_LE_U_4(&hdr->ppi_dlt);
+       len = GET_LE_U_2(hdr->ppi_len);
+       dlt = GET_LE_U_4(hdr->ppi_dlt);
        dltname = pcap_datalink_val_to_name(dlt);
 
        if (!ndo->ndo_qflag) {
-               ND_PRINT("V.%u DLT %s (%u) len %u", hdr->ppi_ver,
+               ND_PRINT("V.%u DLT %s (%u) len %u", GET_U_1(hdr->ppi_ver),
                          (dltname != NULL ? dltname : "UNKNOWN"), dlt,
                           len);
         } else {
@@ -51,9 +52,9 @@ ppi_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
 
 static u_int
 ppi_print(netdissect_options *ndo,
-               const struct pcap_pkthdr *h, const u_char *p)
+         const struct pcap_pkthdr *h, const u_char *p)
 {
-       if_printer printer;
+       if_printer_t printer;
        const ppi_header_t *hdr;
        u_int caplen = h->caplen;
        u_int length = h->len;
@@ -62,26 +63,29 @@ ppi_print(netdissect_options *ndo,
        uint32_t hdrlen;
        struct pcap_pkthdr nhdr;
 
+       ndo->ndo_protocol = "ppi";
        if (caplen < sizeof(ppi_header_t)) {
-               ND_PRINT("[|ppi]");
+               nd_print_trunc(ndo);
                return (caplen);
        }
 
        hdr = (const ppi_header_t *)p;
-       len = EXTRACT_LE_U_2(&hdr->ppi_len);
+       ND_TCHECK_2(hdr->ppi_len);
+       len = GET_LE_U_2(hdr->ppi_len);
        if (caplen < len) {
                /*
                 * If we don't have the entire PPI header, don't
                 * bother.
                 */
-               ND_PRINT("[|ppi]");
+               nd_print_trunc(ndo);
                return (caplen);
        }
        if (len < sizeof(ppi_header_t)) {
-               ND_PRINT("[|ppi]");
+               nd_print_trunc(ndo);
                return (len);
        }
-       dlt = EXTRACT_LE_U_4(&hdr->ppi_dlt);
+       ND_TCHECK_4(hdr->ppi_dlt);
+       dlt = GET_LE_U_4(hdr->ppi_dlt);
 
        if (ndo->ndo_eflag)
                ppi_header_print(ndo, p, length);
@@ -90,11 +94,16 @@ ppi_print(netdissect_options *ndo,
        caplen -= len;
        p += len;
 
-       if ((printer = lookup_printer(dlt)) != NULL) {
+       printer = lookup_printer(ndo, dlt);
+       if (printer.printer != NULL) {
                nhdr = *h;
                nhdr.caplen = caplen;
                nhdr.len = length;
-               hdrlen = printer(ndo, &nhdr, p);
+               if (ndo->ndo_void_printer == TRUE) {
+                       printer.void_printer(ndo, &nhdr, p);
+                       hdrlen = ndo->ndo_ll_header_length;
+               } else
+                       hdrlen = printer.uint_printer(ndo, &nhdr, p);
        } else {
                if (!ndo->ndo_eflag)
                        ppi_header_print(ndo, (const u_char *)hdr, length + len);
@@ -104,6 +113,8 @@ ppi_print(netdissect_options *ndo,
                hdrlen = 0;
        }
        return (len + hdrlen);
+trunc:
+       return (caplen);
 }
 
 /*
@@ -114,16 +125,9 @@ ppi_print(netdissect_options *ndo,
  */
 u_int
 ppi_if_print(netdissect_options *ndo,
-               const struct pcap_pkthdr *h, const u_char *p)
+            const struct pcap_pkthdr *h, const u_char *p)
 {
+       ndo->ndo_protocol = "ppi_if";
        return (ppi_print(ndo, h, p));
 }
-
-/*
- * Local Variables:
- * c-style: whitesmith
- * c-basic-offset: 8
- * End:
- */
-
 #endif /* DLT_PPI */