* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+/* \summary: Apple's DLT_PKTAP 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"
* to host byte order in libpcap.
*/
typedef struct pktap_header {
- uint32_t pkt_len; /* length of pktap header */
- uint32_t pkt_rectype; /* type of record */
- uint32_t pkt_dlt; /* DLT type of this packet */
+ nd_uint32_t pkt_len; /* length of pktap header */
+ nd_uint32_t pkt_rectype; /* type of record */
+ nd_uint32_t pkt_dlt; /* DLT type of this packet */
char pkt_ifname[24]; /* interface name */
- uint32_t pkt_flags;
- uint32_t pkt_pfamily; /* "protocol family" */
- uint32_t pkt_llhdrlen; /* link-layer header length? */
- uint32_t pkt_lltrlrlen; /* link-layer trailer length? */
- uint32_t pkt_pid; /* process ID */
+ nd_uint32_t pkt_flags;
+ nd_uint32_t pkt_pfamily; /* "protocol family" */
+ nd_uint32_t pkt_llhdrlen; /* link-layer header length? */
+ nd_uint32_t pkt_lltrlrlen; /* link-layer trailer length? */
+ nd_uint32_t pkt_pid; /* process ID */
char pkt_cmdname[20]; /* command name */
- uint32_t pkt_svc_class; /* "service class" */
- uint16_t pkt_iftype; /* "interface type" */
- uint16_t pkt_ifunit; /* unit number of interface? */
- uint32_t pkt_epid; /* "effective process ID" */
+ nd_uint32_t pkt_svc_class; /* "service class" */
+ nd_uint16_t pkt_iftype; /* "interface type" */
+ nd_uint16_t pkt_ifunit; /* unit number of interface? */
+ nd_uint32_t pkt_epid; /* "effective process ID" */
char pkt_ecmdname[20]; /* "effective command name" */
} pktap_header_t;
#define PKT_REC_NONE 0 /* nothing follows the header */
#define PKT_REC_PACKET 1 /* a packet follows the header */
-static inline void
+static void
pktap_header_print(netdissect_options *ndo, const u_char *bp, u_int length)
{
const pktap_header_t *hdr;
uint32_t dlt, hdrlen;
+ const char *dltname;
hdr = (const pktap_header_t *)bp;
- dlt = EXTRACT_LE_32BITS(&hdr->pkt_dlt);
- hdrlen = EXTRACT_LE_32BITS(&hdr->pkt_len);
+ dlt = EXTRACT_LE_U_4(hdr->pkt_dlt);
+ hdrlen = EXTRACT_LE_U_4(hdr->pkt_len);
+ dltname = pcap_datalink_val_to_name(dlt);
if (!ndo->ndo_qflag) {
- ND_PRINT((ndo,", DLT %s (%d) len %d",
- pcap_datalink_val_to_name(dlt), dlt, hdrlen));
+ ND_PRINT("DLT %s (%u) len %u",
+ (dltname != NULL ? dltname : "UNKNOWN"), dlt, hdrlen);
} else {
- ND_PRINT((ndo,", %s", pcap_datalink_val_to_name(dlt)));
+ ND_PRINT("%s", (dltname != NULL ? dltname : "UNKNOWN"));
}
- ND_PRINT((ndo, ", length %u: ", length));
+ ND_PRINT(", length %u: ", length);
}
/*
u_int length = h->len;
if_printer printer;
const pktap_header_t *hdr;
+ struct pcap_pkthdr nhdr;
- if (caplen < sizeof(pktap_header_t) || length < sizeof(pktap_header_t)) {
- ND_PRINT((ndo, "[|pktap]"));
- return (0);
+ ndo->ndo_protocol = "pktap_if";
+ if (caplen < sizeof(pktap_header_t)) {
+ nd_print_trunc(ndo);
+ return (caplen);
}
hdr = (const pktap_header_t *)p;
- dlt = EXTRACT_LE_32BITS(&hdr->pkt_dlt);
- hdrlen = EXTRACT_LE_32BITS(&hdr->pkt_len);
+ dlt = EXTRACT_LE_U_4(hdr->pkt_dlt);
+ hdrlen = EXTRACT_LE_U_4(hdr->pkt_len);
if (hdrlen < sizeof(pktap_header_t)) {
/*
* Claimed header length < structure length.
* is the length supplied so that the header can
* be expanded in the future)?
*/
- ND_PRINT((ndo, "[|pktap]"));
- return (0);
+ nd_print_trunc(ndo);
+ return (caplen);
}
- if (caplen < hdrlen || length < hdrlen) {
- ND_PRINT((ndo, "[|pktap]"));
- return (hdrlen);
+ if (caplen < hdrlen) {
+ nd_print_trunc(ndo);
+ return (caplen);
}
if (ndo->ndo_eflag)
caplen -= hdrlen;
p += hdrlen;
- rectype = EXTRACT_LE_32BITS(&hdr->pkt_rectype);
+ rectype = EXTRACT_LE_U_4(hdr->pkt_rectype);
switch (rectype) {
case PKT_REC_NONE:
- ND_PRINT((ndo, "no data"));
+ ND_PRINT("no data");
break;
case PKT_REC_PACKET:
if ((printer = lookup_printer(dlt)) != NULL) {
- hdrlen += printer(ndo, h, p);
+ nhdr = *h;
+ nhdr.caplen = caplen;
+ nhdr.len = length;
+ hdrlen += printer(ndo, &nhdr, p);
} else {
if (!ndo->ndo_eflag)
pktap_header_print(ndo, (const u_char *)hdr,
return (hdrlen);
}
-
-/*
- * Local Variables:
- * c-style: whitesmith
- * c-basic-offset: 8
- * End:
- */
-
#endif /* DLT_PKTAP */