]> The Tcpdump Group git mirrors - tcpdump/blobdiff - extract.h
icmp: clean up the extension code and comments.
[tcpdump] / extract.h
index 007e9dbb57e805f3a775f270d0c4afc87bbc9fc0..c355c4d97be554c804cdf51fbb079202ffb1a84b 100644 (file)
--- a/extract.h
+++ b/extract.h
@@ -37,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__
@@ -152,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
@@ -575,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);
 }
 
@@ -589,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);
 }
 
@@ -599,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);
 }
 
@@ -607,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);
 }
 
@@ -615,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);
 }
 
@@ -623,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);
 }
 
@@ -631,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);
 }
 
@@ -639,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);
 }
 
@@ -647,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);
 }
 
@@ -657,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);
 }
 
@@ -665,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);
 }
 
@@ -673,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);
 }
 
@@ -681,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);
 }
 
@@ -689,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);
 }
 
@@ -697,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);
 }
 
@@ -705,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);
 }
 
@@ -715,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);
 }
 
@@ -723,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);
 }
 
@@ -733,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);
 }
 
@@ -741,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);
 }
 
@@ -751,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);
 }
 
@@ -759,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);
 }
 
@@ -767,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);
 }
 
@@ -775,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);
 }
 
@@ -783,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);
 }
 
@@ -791,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);
 }
 
@@ -799,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);
 }
 
@@ -809,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);
 }
 
@@ -817,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);
 }
 
@@ -825,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);
 }
 
@@ -833,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);
 }
 
@@ -843,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);
 }
 
@@ -851,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))
 
@@ -896,4 +919,6 @@ 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 */