diff options
author | Francois-Xavier Le Bail <devel.fx.lebail@orange.fr> | 2018-01-13 09:36:04 +0100 |
---|---|---|
committer | Francois-Xavier Le Bail <devel.fx.lebail@orange.fr> | 2018-01-13 09:38:44 +0100 |
commit | e319ff0ab28bb4a57768468d516ec01b5082783f (patch) | |
tree | a8595015a499d7161dc3f063507bba9ed09ac0f1 /print-ppi.c | |
parent | 6ecaf7e8680f09e4a1e6effc1cdc503ac6844670 (diff) | |
download | tcpdump-e319ff0ab28bb4a57768468d516ec01b5082783f.tar.gz |
PPI: Use nd_ types, add EXTRACT_ call, tstr[] and bounds checks
Moreover:
Remove unneeded '&' when getting a pointer to an nd_uintN_t type
Diffstat (limited to 'print-ppi.c')
-rw-r--r-- | print-ppi.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/print-ppi.c b/print-ppi.c index d7110d12..1c4469fa 100644 --- a/print-ppi.c +++ b/print-ppi.c @@ -13,11 +13,13 @@ #include "netdissect.h" #include "extract.h" +static const char tstr[] = "[|ppi]"; + 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 @@ -34,12 +36,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 = EXTRACT_LE_U_2(hdr->ppi_len); + dlt = EXTRACT_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", EXTRACT_U_1(hdr->ppi_ver), (dltname != NULL ? dltname : "UNKNOWN"), dlt, len); } else { @@ -51,7 +53,7 @@ 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; const ppi_header_t *hdr; @@ -63,25 +65,27 @@ ppi_print(netdissect_options *ndo, struct pcap_pkthdr nhdr; if (caplen < sizeof(ppi_header_t)) { - ND_PRINT("[|ppi]"); + ND_PRINT(" %s", tstr); return (caplen); } hdr = (const ppi_header_t *)p; - len = EXTRACT_LE_U_2(&hdr->ppi_len); + ND_TCHECK_2(hdr->ppi_len); + len = EXTRACT_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(" %s", tstr); return (caplen); } if (len < sizeof(ppi_header_t)) { - ND_PRINT("[|ppi]"); + ND_PRINT(" %s", tstr); return (len); } - dlt = EXTRACT_LE_U_4(&hdr->ppi_dlt); + ND_TCHECK_4(hdr->ppi_dlt); + dlt = EXTRACT_LE_U_4(hdr->ppi_dlt); if (ndo->ndo_eflag) ppi_header_print(ndo, p, length); @@ -104,6 +108,8 @@ ppi_print(netdissect_options *ndo, hdrlen = 0; } return (len + hdrlen); +trunc: + return (caplen); } /* @@ -114,7 +120,7 @@ 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) { return (ppi_print(ndo, h, p)); } |