5 /* \summary: Per-Packet Information (DLT_PPI) printer */
8 * Per-Packet Information Header Specification - Version 1.0.7
9 * https://web.archive.org/web/20160328114748/http://www.cacetech.com/documents/PPI%20Header%20format%201.0.7.pdf
16 #include "netdissect-stdinc.h"
18 #include "netdissect.h"
22 typedef struct ppi_header
{
23 nd_uint8_t ppi_ver
; /* Version. Currently 0 */
24 nd_uint8_t ppi_flags
; /* Flags. */
25 nd_uint16_t ppi_len
; /* Length of entire message, including
26 * this header and TLV payload. */
27 nd_uint32_t ppi_dlt
; /* Data Link Type of the captured
36 ppi_header_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
38 const ppi_header_t
*hdr
;
43 hdr
= (const ppi_header_t
*)bp
;
45 len
= GET_LE_U_2(hdr
->ppi_len
);
46 dlt
= GET_LE_U_4(hdr
->ppi_dlt
);
47 dltname
= pcap_datalink_val_to_name(dlt
);
49 if (!ndo
->ndo_qflag
) {
50 ND_PRINT("V.%u DLT %s (%u) len %u", GET_U_1(hdr
->ppi_ver
),
51 (dltname
!= NULL
? dltname
: "UNKNOWN"), dlt
,
54 ND_PRINT("%s", (dltname
!= NULL
? dltname
: "UNKNOWN"));
57 ND_PRINT(", length %u: ", length
);
61 * This is the top level routine of the printer. 'p' points
62 * to the ether header of the packet, 'h->ts' is the timestamp,
63 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
64 * is the number of bytes actually captured.
67 ppi_if_print(netdissect_options
*ndo
,
68 const struct pcap_pkthdr
*h
, const u_char
*p
)
71 const ppi_header_t
*hdr
;
72 u_int caplen
= h
->caplen
;
73 u_int length
= h
->len
;
77 struct pcap_pkthdr nhdr
;
79 ndo
->ndo_protocol
= "ppi";
80 if (caplen
< sizeof(ppi_header_t
)) {
82 ndo
->ndo_ll_header_length
+= caplen
;
86 hdr
= (const ppi_header_t
*)p
;
87 len
= GET_LE_U_2(hdr
->ppi_len
);
88 if (len
< sizeof(ppi_header_t
) || len
> 65532) {
89 /* It MUST be between 8 and 65,532 inclusive (spec 3.1.3) */
90 ND_PRINT(" [length %u < %zu or > 65532]", len
,
91 sizeof(ppi_header_t
));
92 nd_print_invalid(ndo
);
93 ndo
->ndo_ll_header_length
+= caplen
;
98 * If we don't have the entire PPI header, don't
102 ndo
->ndo_ll_header_length
+= caplen
;
105 dlt
= GET_LE_U_4(hdr
->ppi_dlt
);
108 ppi_header_print(ndo
, p
, length
);
114 printer
= lookup_printer(ndo
, dlt
);
115 if (printer
.printer
!= NULL
) {
117 nhdr
.caplen
= caplen
;
119 if (ndo
->ndo_void_printer
== TRUE
) {
120 printer
.void_printer(ndo
, &nhdr
, p
);
121 hdrlen
= ndo
->ndo_ll_header_length
;
123 hdrlen
= printer
.uint_printer(ndo
, &nhdr
, p
);
126 ppi_header_print(ndo
, (const u_char
*)hdr
, length
+ len
);
128 if (!ndo
->ndo_suppress_default_print
)
129 ND_DEFAULTPRINT(p
, caplen
);
132 ndo
->ndo_ll_header_length
+= len
+ hdrlen
;