aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ovsienko <infrastation@yandex.ru>2013-10-31 18:58:42 +0400
committerDenis Ovsienko <infrastation@yandex.ru>2013-10-31 19:01:56 +0400
commitfc133e2edba0fce13d34813308e7523596f869e1 (patch)
treef6cfaa1c2c10ac0c3c9621fcfd6b02b96723d99d
parenta26b064bcbad35e0268b7a533101f02bee2c23a5 (diff)
downloadpublic-fc133e2edba0fce13d34813308e7523596f869e1.tar.gz
NFLOG: more minor improvements
Reduce pointer conversion and do version check before header decoding.
-rw-r--r--print-nflog.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/print-nflog.c b/print-nflog.c
index c2ea7b7..adeecd3 100644
--- a/print-nflog.c
+++ b/print-nflog.c
@@ -50,11 +50,8 @@ static const struct tok nflog_values[] = {
};
static inline void
-nflog_hdr_print(struct netdissect_options *ndo, const u_char *bp, u_int length)
+nflog_hdr_print(struct netdissect_options *ndo, const nflog_hdr_t *hdr, u_int length)
{
- const nflog_hdr_t *hdr;
- hdr = (const nflog_hdr_t *)bp;
-
ND_PRINT((ndo, "version %d, resource ID %d", hdr->nflog_version, ntohs(hdr->nflog_rid)));
if (!ndo->ndo_qflag) {
@@ -76,7 +73,7 @@ u_int
nflog_if_print(struct netdissect_options *ndo,
const struct pcap_pkthdr *h, const u_char *p)
{
- const nflog_hdr_t *hdr;
+ const nflog_hdr_t *hdr = (const nflog_hdr_t *)p;
const nflog_tlv_t *tlv;
u_int16_t size;
u_int16_t h_size = sizeof(nflog_hdr_t);
@@ -88,19 +85,18 @@ nflog_if_print(struct netdissect_options *ndo,
return h_size;
}
+ if (!(hdr->nflog_version) == 0) {
+ ND_PRINT((ndo, ", NFLOG version mismatch: %u", hdr->nflog_version));
+ return h_size;
+ }
+
if (ndo->ndo_eflag)
- nflog_hdr_print(ndo, p, length);
+ nflog_hdr_print(ndo, hdr, length);
length -= sizeof(nflog_hdr_t);
caplen -= sizeof(nflog_hdr_t);
- hdr = (const nflog_hdr_t *)p;
p += sizeof(nflog_hdr_t);
- if (!(hdr->nflog_version) == 0) {
- ND_PRINT((ndo, ", NFLOG version mismatch: %u", hdr->nflog_version));
- return h_size;
- }
-
do {
tlv = (const nflog_tlv_t *) p;
size = tlv->tlv_length;
@@ -140,7 +136,7 @@ nflog_if_print(struct netdissect_options *ndo,
default:
if (!ndo->ndo_eflag)
- nflog_hdr_print(ndo, (u_char *)hdr,
+ nflog_hdr_print(ndo, hdr,
length + sizeof(nflog_hdr_t));
if (!ndo->ndo_suppress_default_print)