]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pktap.c
CI: Add warning exemptions for Sun C (suncc-5.15) on Solaris 10
[tcpdump] / print-pktap.c
index 182378ef775882b6264d764076fd72958a9352e2..d1c391d5ce1b21adef3bb814c671f2b3c1f48237 100644 (file)
 
 /* \summary: Apple's DLT_PKTAP printer */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "extract.h"
 
@@ -95,21 +94,22 @@ pktap_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  * is the number of bytes actually captured.
  */
-u_int
+void
 pktap_if_print(netdissect_options *ndo,
                const struct pcap_pkthdr *h, const u_char *p)
 {
        uint32_t dlt, hdrlen, rectype;
        u_int caplen = h->caplen;
        u_int length = h->len;
-       if_printer_t printer;
+       if_printer printer;
        const pktap_header_t *hdr;
        struct pcap_pkthdr nhdr;
 
-       ndo->ndo_protocol = "pktap_if";
-       if (caplen < sizeof(pktap_header_t)) {
-               nd_print_trunc(ndo);
-               return (caplen);
+       ndo->ndo_protocol = "pktap";
+       if (length < sizeof(pktap_header_t)) {
+               ND_PRINT(" (packet too short, %u < %zu)",
+                        length, sizeof(pktap_header_t));
+               goto invalid;
        }
        hdr = (const pktap_header_t *)p;
        dlt = GET_LE_U_4(hdr->pkt_dlt);
@@ -122,13 +122,16 @@ pktap_if_print(netdissect_options *ndo,
                 * is the length supplied so that the header can
                 * be expanded in the future)?
                 */
-               nd_print_trunc(ndo);
-               return (caplen);
+               ND_PRINT(" (pkt_len too small, %u < %zu)",
+                        hdrlen, sizeof(pktap_header_t));
+               goto invalid;
        }
-       if (caplen < hdrlen) {
-               nd_print_trunc(ndo);
-               return (caplen);
+       if (hdrlen > length) {
+               ND_PRINT(" (pkt_len too big, %u > %u)",
+                        hdrlen, length);
+               goto invalid;
        }
+       ND_TCHECK_LEN(p, hdrlen);
 
        if (ndo->ndo_eflag)
                pktap_header_print(ndo, p, length);
@@ -145,16 +148,13 @@ pktap_if_print(netdissect_options *ndo,
                break;
 
        case PKT_REC_PACKET:
-               printer = lookup_printer(ndo, dlt);
-               if (printer.printer != NULL) {
+               printer = lookup_printer(dlt);
+               if (printer != NULL) {
                        nhdr = *h;
                        nhdr.caplen = caplen;
                        nhdr.len = length;
-                       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);
+                       printer(ndo, &nhdr, p);
+                       hdrlen += ndo->ndo_ll_hdr_len;
                } else {
                        if (!ndo->ndo_eflag)
                                pktap_header_print(ndo, (const u_char *)hdr,
@@ -166,6 +166,10 @@ pktap_if_print(netdissect_options *ndo,
                break;
        }
 
-       return (hdrlen);
+       ndo->ndo_ll_hdr_len += hdrlen;
+       return;
+
+invalid:
+       nd_print_invalid(ndo);
 }
 #endif /* DLT_PKTAP */