]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use a switch to manage the setjmp() return values
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 18 Sep 2020 11:17:39 +0000 (13:17 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 18 Sep 2020 11:27:48 +0000 (13:27 +0200)
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.).

extract.h
netdissect.h
print.c

index dfb21f694f14e7b317388e2dac58e3331e1145c0..58b8cc19dd98ea6ee9670f59fa80a82d087a6750 100644 (file)
--- 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 */
index b774ae63ef01ea6bc48b4be3d9bdb1903d9e42d5..e430a0b823c275631893ce0ae52416c374d807f8 100644 (file)
@@ -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 6e4cf8937a31fc7b3caa2b05bc44bdcad34533b3..864e9ddde2920e50d2fa20e4b52844e2634d6876 100644 (file)
--- 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;