]> The Tcpdump Group git mirrors - tcpdump/blobdiff - extract.h
icmp: clean up the extension code and comments.
[tcpdump] / extract.h
index fca0b811b625c9818b161eb07e36040433d27f16..c355c4d97be554c804cdf51fbb079202ffb1a84b 100644 (file)
--- a/extract.h
+++ b/extract.h
@@ -19,6 +19,9 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#ifndef EXTRACT_H
+#define EXTRACT_H
+
 #include <string.h>
 
 /*
@@ -34,6 +37,7 @@
  */
 #include "funcattrs.h"
 #include "netdissect.h"
+#include "diag-control.h"
 
 /*
  * If we have versions of GCC or Clang that support an __attribute__
@@ -149,7 +153,7 @@ EXTRACT_IPV4_TO_HOST_ORDER(const void *p)
  *
  * We do this in case the compiler can generate code using those
  * instructions to do an unaligned load and pass stuff to "ntohs()" or
- * "ntohl()", which might be better than than the code to fetch the
+ * "ntohl()", which might be better than the code to fetch the
  * bytes one at a time and assemble them.  (That might not be the
  * case on a little-endian platform, such as DEC's MIPS machines and
  * Alpha machines, where "ntohs()" and "ntohl()" might not be done
@@ -572,13 +576,27 @@ EXTRACT_IPV4_TO_NETWORK_ORDER(const void *p)
 #define ND_TTEST_16(p) ND_TTEST_LEN((p), 16)
 #define ND_TCHECK_16(p) ND_TCHECK_LEN((p), 16)
 
+static inline NORETURN void
+nd_trunc_longjmp(netdissect_options *ndo)
+{
+       longjmp(ndo->ndo_early_end, ND_TRUNCATED);
+#ifdef _AIX
+       /*
+        * In AIX <setjmp.h> decorates longjmp() with "#pragma leaves", which tells
+        * XL C that the function is noreturn, but GCC remains unaware of that and
+        * yields a "'noreturn' function does return" warning.
+        */
+       ND_UNREACHABLE
+#endif /* _AIX */
+}
+
 /* get_u_1 and get_s_1 */
 
 static inline uint8_t
 get_u_1(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_1(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_U_1(p);
 }
 
@@ -586,7 +604,7 @@ static inline int8_t
 get_s_1(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_1(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_S_1(p);
 }
 
@@ -596,7 +614,7 @@ static inline uint16_t
 get_be_u_2(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_2(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_2(p);
 }
 
@@ -604,7 +622,7 @@ static inline uint32_t
 get_be_u_3(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_3(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_3(p);
 }
 
@@ -612,7 +630,7 @@ static inline uint32_t
 get_be_u_4(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_4(p);
 }
 
@@ -620,7 +638,7 @@ static inline uint64_t
 get_be_u_5(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_5(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_5(p);
 }
 
@@ -628,7 +646,7 @@ static inline uint64_t
 get_be_u_6(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_6(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_6(p);
 }
 
@@ -636,7 +654,7 @@ static inline uint64_t
 get_be_u_7(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_7(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_7(p);
 }
 
@@ -644,7 +662,7 @@ static inline uint64_t
 get_be_u_8(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_8(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_U_8(p);
 }
 
@@ -654,7 +672,7 @@ static inline int16_t
 get_be_s_2(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_2(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_2(p);
 }
 
@@ -662,7 +680,7 @@ static inline int32_t
 get_be_s_3(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_3(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_3(p);
 }
 
@@ -670,7 +688,7 @@ static inline int32_t
 get_be_s_4(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_4(p);
 }
 
@@ -678,7 +696,7 @@ static inline int64_t
 get_be_s_5(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_5(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_5(p);
 }
 
@@ -686,7 +704,7 @@ static inline int64_t
 get_be_s_6(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_6(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_6(p);
 }
 
@@ -694,7 +712,7 @@ static inline int64_t
 get_be_s_7(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_7(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_7(p);
 }
 
@@ -702,7 +720,7 @@ static inline int64_t
 get_be_s_8(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_8(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_BE_S_8(p);
 }
 
@@ -712,7 +730,7 @@ static inline uint16_t
 get_he_u_2(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_2(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_HE_U_2(p);
 }
 
@@ -720,7 +738,7 @@ static inline uint32_t
 get_he_u_4(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_HE_U_4(p);
 }
 
@@ -730,7 +748,7 @@ static inline int16_t
 get_he_s_2(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_2(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_HE_S_2(p);
 }
 
@@ -738,7 +756,7 @@ static inline int32_t
 get_he_s_4(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_HE_S_4(p);
 }
 
@@ -748,7 +766,7 @@ static inline uint16_t
 get_le_u_2(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_2(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_2(p);
 }
 
@@ -756,7 +774,7 @@ static inline uint32_t
 get_le_u_3(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_3(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_3(p);
 }
 
@@ -764,7 +782,7 @@ static inline uint32_t
 get_le_u_4(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_4(p);
 }
 
@@ -772,7 +790,7 @@ static inline uint64_t
 get_le_u_5(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_5(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_5(p);
 }
 
@@ -780,7 +798,7 @@ static inline uint64_t
 get_le_u_6(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_6(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_6(p);
 }
 
@@ -788,7 +806,7 @@ static inline uint64_t
 get_le_u_7(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_7(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_7(p);
 }
 
@@ -796,7 +814,7 @@ static inline uint64_t
 get_le_u_8(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_8(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_U_8(p);
 }
 
@@ -806,7 +824,7 @@ static inline int16_t
 get_le_s_2(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_2(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_S_2(p);
 }
 
@@ -814,7 +832,7 @@ static inline int32_t
 get_le_s_3(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_3(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_S_3(p);
 }
 
@@ -822,7 +840,7 @@ static inline int32_t
 get_le_s_4(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_S_4(p);
 }
 
@@ -830,7 +848,7 @@ static inline int64_t
 get_le_s_8(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_8(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_LE_S_8(p);
 }
 
@@ -840,7 +858,7 @@ static inline uint32_t
 get_ipv4_to_host_order(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_IPV4_TO_HOST_ORDER(p);
 }
 
@@ -848,10 +866,18 @@ static inline uint32_t
 get_ipv4_to_network_order(netdissect_options *ndo, const u_char *p)
 {
        if (!ND_TTEST_4(p))
-               longjmp(ndo->ndo_truncated, 1);
+               nd_trunc_longjmp(ndo);
        return EXTRACT_IPV4_TO_NETWORK_ORDER(p);
 }
 
+static inline void
+get_cpy_bytes(netdissect_options *ndo, u_char *dst, const u_char *p, size_t len)
+{
+       if (!ND_TTEST_LEN(p, len))
+               nd_trunc_longjmp(ndo);
+       UNALIGNED_MEMCPY(dst, p, len);
+}
+
 #define GET_U_1(p) get_u_1(ndo, (const u_char *)(p))
 #define GET_S_1(p) get_s_1(ndo, (const u_char *)(p))
 
@@ -892,3 +918,7 @@ get_ipv4_to_network_order(netdissect_options *ndo, const u_char *p)
 
 #define GET_IPV4_TO_HOST_ORDER(p) get_ipv4_to_host_order(ndo, (const u_char *)(p))
 #define GET_IPV4_TO_NETWORK_ORDER(p) get_ipv4_to_network_order(ndo, (const u_char *)(p))
+
+#define GET_CPY_BYTES(dst, p, len) get_cpy_bytes(ndo, (u_char *)(dst), (const u_char *)(p), len)
+
+#endif /* EXTRACT_H */