From: Francois-Xavier Le Bail Date: Fri, 18 Sep 2020 11:17:39 +0000 (+0200) Subject: Use a switch to manage the setjmp() return values X-Git-Tag: tcpdump-4.99-bp~223 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/a2a16f6b4c76ca6d5a9bce323ef22613d153ae9e Use a switch to manage the setjmp() return values Also rename 'ndo_truncated' to 'ndo_early_end'. The current case (truncated packet) uses ND_TRUNCATED value. Prepare to add other cases when the current packet cannot be processed any more ('Invalid' cases, etc.). --- diff --git a/extract.h b/extract.h index dfb21f69..58b8cc19 100644 --- a/extract.h +++ b/extract.h @@ -578,7 +578,7 @@ EXTRACT_IPV4_TO_NETWORK_ORDER(const void *p) static inline NORETURN void nd_trunc(netdissect_options *ndo) { - longjmp(ndo->ndo_truncated, 1); + longjmp(ndo->ndo_early_end, ND_TRUNCATED); } /* get_u_1 and get_s_1 */ diff --git a/netdissect.h b/netdissect.h index b774ae63..e430a0b8 100644 --- a/netdissect.h +++ b/netdissect.h @@ -194,6 +194,9 @@ struct netdissect_saved_packet_info { struct netdissect_saved_packet_info *ndspi_prev; /* previous buffer on the stack */ }; +/* 'val' value(s) for longjmp */ +#define ND_TRUNCATED 1 + struct netdissect_options { int ndo_bflag; /* print 4 byte ASes in ASDOT notation */ int ndo_eflag; /* print ethernet header */ @@ -213,7 +216,7 @@ struct netdissect_options { */ int ndo_Hflag; /* dissect 802.11s draft mesh standard */ const char *ndo_protocol; /* protocol */ - jmp_buf ndo_truncated; /* jmp_buf for setjmp()/longjmp() */ + jmp_buf ndo_early_end; /* jmp_buf for setjmp()/longjmp() */ void *ndo_last_mem_p; /* pointer to the last allocated memory chunk */ int ndo_packet_number; /* print a packet number in the beginning of line */ int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */ diff --git a/print.c b/print.c index 6e4cf893..864e9ddd 100644 --- a/print.c +++ b/print.c @@ -398,12 +398,15 @@ pretty_print_packet(netdissect_options *ndo, const struct pcap_pkthdr *h, ndo->ndo_protocol = ""; ndo->ndo_ll_hdr_len = 0; - if (setjmp(ndo->ndo_truncated) == 0) { + switch (setjmp(ndo->ndo_early_end)) { + case 0: /* Print the packet. */ (ndo->ndo_if_printer)(ndo, h, sp); - } else { + break; + case ND_TRUNCATED: /* A printer quit because the packet was truncated; report it */ nd_print_trunc(ndo); + break; } hdrlen = ndo->ndo_ll_hdr_len;