diff options
author | Francois-Xavier Le Bail <devel.fx.lebail@orange.fr> | 2020-05-04 15:23:34 +0200 |
---|---|---|
committer | Francois-Xavier Le Bail <devel.fx.lebail@orange.fr> | 2020-05-04 15:38:02 +0200 |
commit | 04df7bc71ece093300003430c457736610a062da (patch) | |
tree | 6670815cf0c2f49f3c2a859cb54d499018f796e0 | |
parent | a881efab395fb7b7941de8204e91ea6d7cc7d4d7 (diff) | |
download | tcpdump-04df7bc71ece093300003430c457736610a062da.tar.gz |
NFLOG: Add two macros
-rw-r--r-- | print-nflog.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/print-nflog.c b/print-nflog.c index d10f8539..86e1a43c 100644 --- a/print-nflog.c +++ b/print-nflog.c @@ -55,12 +55,16 @@ typedef struct nflog_hdr { nd_uint16_t nflog_rid; /* resource ID */ } nflog_hdr_t; +#define NFLOG_HDR_LEN sizeof(nflog_hdr_t) + typedef struct nflog_tlv { nd_uint16_t tlv_length; /* tlv length */ nd_uint16_t tlv_type; /* tlv type */ /* value follows this */ } nflog_tlv_t; +#define NFLOG_TLV_LEN sizeof(nflog_tlv_t) + typedef struct nflog_packet_hdr { nd_uint16_t hw_protocol; /* hw protocol */ nd_uint8_t hook; /* netfilter hook */ @@ -134,12 +138,12 @@ nflog_if_print(netdissect_options *ndo, { const nflog_hdr_t *hdr = (const nflog_hdr_t *)p; uint16_t size; - uint16_t h_size = sizeof(nflog_hdr_t); + uint16_t h_size = NFLOG_HDR_LEN; u_int caplen = h->caplen; u_int length = h->len; ndo->ndo_protocol = "nflog_if"; - if (caplen < sizeof(nflog_hdr_t)) + if (caplen < NFLOG_HDR_LEN) goto trunc; ND_TCHECK_SIZE(hdr); @@ -151,15 +155,15 @@ nflog_if_print(netdissect_options *ndo, if (ndo->ndo_eflag) nflog_hdr_print(ndo, hdr, length); - p += sizeof(nflog_hdr_t); - length -= sizeof(nflog_hdr_t); - caplen -= sizeof(nflog_hdr_t); + p += NFLOG_HDR_LEN; + length -= NFLOG_HDR_LEN; + caplen -= NFLOG_HDR_LEN; while (length > 0) { const nflog_tlv_t *tlv; /* We have some data. Do we have enough for the TLV header? */ - if (caplen < sizeof(nflog_tlv_t)) + if (caplen < NFLOG_TLV_LEN) goto trunc; /* No. */ tlv = (const nflog_tlv_t *) p; @@ -169,7 +173,7 @@ nflog_if_print(netdissect_options *ndo, size += 4 - size % 4; /* Is the TLV's length less than the minimum? */ - if (size < sizeof(nflog_tlv_t)) + if (size < NFLOG_TLV_LEN) goto trunc; /* Yes. Give up now. */ /* Do we have enough data for the full TLV? */ @@ -182,10 +186,10 @@ nflog_if_print(netdissect_options *ndo, * Skip past the TLV header, and break out * of the loop so we print the packet data. */ - p += sizeof(nflog_tlv_t); - h_size += sizeof(nflog_tlv_t); - length -= sizeof(nflog_tlv_t); - caplen -= sizeof(nflog_tlv_t); + p += NFLOG_TLV_LEN; + h_size += NFLOG_TLV_LEN; + length -= NFLOG_TLV_LEN; + caplen -= NFLOG_TLV_LEN; break; } @@ -210,7 +214,7 @@ nflog_if_print(netdissect_options *ndo, default: if (!ndo->ndo_eflag) nflog_hdr_print(ndo, hdr, - length + sizeof(nflog_hdr_t)); + length + NFLOG_HDR_LEN); if (!ndo->ndo_suppress_default_print) ND_DEFAULTPRINT(p, caplen); |