]> The Tcpdump Group git mirrors - tcpdump/blobdiff - netdissect.h
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / netdissect.h
index ce878abe06671b912f77c43b57a7b685d0d85427..ca2b566537d38b4bcf4fcabf03f5a12bf6e8d873 100644 (file)
@@ -30,9 +30,9 @@
 #endif
 #include <sys/types.h>
 #include <setjmp.h>
+#include <time.h>
 #include "status-exit-codes.h"
 #include "funcattrs.h" /* for PRINTFLIKE_FUNCPTR() */
-#include "diag-control.h" /* for ND_UNREACHABLE */
 
 /*
  * Data types corresponding to multi-byte integral values within data
@@ -58,13 +58,28 @@ typedef signed char nd_int8_t[1];
 
 /*
  * "unsigned char" so that sign extension isn't done on the
- * individual bytes while they're being assembled.
+ * individual bytes while they're being assembled.  Use
+ * GET_S_BE_n() and GET_S_LE_n() macros to extract the value
+ * as a signed integer.
  */
+typedef unsigned char nd_int16_t[2];
+typedef unsigned char nd_int24_t[3];
 typedef unsigned char nd_int32_t[4];
+typedef unsigned char nd_int40_t[5];
+typedef unsigned char nd_int48_t[6];
+typedef unsigned char nd_int56_t[7];
 typedef unsigned char nd_int64_t[8];
 
 #define        FMAXINT (4294967296.0)  /* floating point rep. of MAXINT */
 
+/*
+ * Data types corresponding to multi-byte floating_point values within
+ * data structures.  These are defined as arrays of octets, for the
+ * same reason that we do so for integral values.
+ */
+typedef unsigned char nd_float[4];
+typedef unsigned char nd_double[8];
+
 /*
  * Use this for IPv4 addresses and netmasks.
  *
@@ -101,8 +116,14 @@ typedef unsigned char nd_ipv6[16];
 /*
  * Use this for MAC addresses.
  */
-#define MAC_ADDR_LEN   6U              /* length of MAC addresses */
-typedef unsigned char nd_mac_addr[MAC_ADDR_LEN];
+#define MAC48_LEN      6U              /* length of MAC addresses */
+typedef unsigned char nd_mac48[MAC48_LEN];
+
+/*
+ * Use this for EUI64s.
+ */
+#define EUI64_LEN      8U
+typedef unsigned char nd_eui64[EUI64_LEN];
 
 /*
  * Use this for blobs of bytes; make them arrays of nd_byte.
@@ -129,10 +150,6 @@ extern size_t strlcat (char *, const char *, size_t);
 extern size_t strlcpy (char *, const char *, size_t);
 #endif
 
-#ifndef HAVE_STRDUP
-extern char *strdup (const char *str);
-#endif
-
 #ifndef HAVE_STRSEP
 extern char *strsep(char **, const char *);
 #endif
@@ -143,9 +160,9 @@ struct tok {
 };
 
 /* tok2str is deprecated */
-extern const char *tok2str(const struct tok *, const char *, u_int);
-extern char *bittok2str(const struct tok *, const char *, u_int);
-extern char *bittok2str_nosep(const struct tok *, const char *, u_int);
+extern const char *tok2str(const struct tok *, const char *, const u_int);
+extern char *bittok2str(const struct tok *, const char *, const u_int);
+extern char *bittok2str_nosep(const struct tok *, const char *, const u_int);
 
 /* Initialize netdissect. */
 extern int nd_init(char *, size_t);
@@ -218,6 +235,7 @@ struct netdissect_options {
   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_lengths;             /* print packet header caplen and len */
   int ndo_print_sampling;      /* print every Nth packet */
   int ndo_suppress_default_print; /* don't use default_print() for unknown packet types */
   int ndo_tstamp_precision;    /* requested time stamp precision */
@@ -269,19 +287,10 @@ extern void nd_change_snaplen(netdissect_options *, const u_char *, const u_int)
 extern void nd_pop_packet_info(netdissect_options *);
 extern void nd_pop_all_packet_info(netdissect_options *);
 
-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 */
-}
+/*
+ * Report a packet truncation with a longjmp().
+ */
+NORETURN void nd_trunc_longjmp(netdissect_options *ndo);
 
 #define PT_VAT         1       /* Visual Audio Tool */
 #define PT_WB          2       /* distributed White Board */
@@ -377,9 +386,15 @@ nd_trunc_longjmp(netdissect_options *ndo)
 
 /* Bail out if "l" bytes from "p" were not captured */
 #ifdef ND_LONGJMP_FROM_TCHECK
-#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo)
+#define ND_TCHECK_LEN(p, l) \
+do { \
+if (!ND_TTEST_LEN(p, l)) nd_trunc_longjmp(ndo); \
+} while (0)
 #else
-#define ND_TCHECK_LEN(p, l) if (!ND_TTEST_LEN(p, l)) goto trunc
+#define ND_TCHECK_LEN(p, l) \
+do { \
+if (!ND_TTEST_LEN(p, l)) goto trunc; \
+} while (0)
 #endif
 
 /* Bail out if "*(p)" was not captured */
@@ -388,23 +403,25 @@ nd_trunc_longjmp(netdissect_options *ndo)
 /*
  * Number of bytes between two pointers.
  */
-#define ND_BYTES_BETWEEN(p1, p2) ((u_int)(((const uint8_t *)(p1)) - (const uint8_t *)(p2)))
+#define ND_BYTES_BETWEEN(p1, p2) ((const u_char *)(p1) >= (const u_char *)(p2) ? 0 : ((u_int)(((const u_char *)(p2)) - (const u_char *)(p1))))
 
 /*
  * Number of bytes remaining in the captured data, starting at the
  * byte pointed to by the argument.
  */
-#define ND_BYTES_AVAILABLE_AFTER(p) ND_BYTES_BETWEEN(ndo->ndo_snapend, (p))
+#define ND_BYTES_AVAILABLE_AFTER(p) ((const u_char *)(p) < ndo->ndo_packetp ? 0 : ND_BYTES_BETWEEN((p), ndo->ndo_snapend))
 
 /*
  * Check (expression_1 operator expression_2) for invalid packet with
  * a custom message, format %u
  */
 #define ND_ICHECKMSG_U(message, expression_1, operator, expression_2) \
+do { \
 if ((expression_1) operator (expression_2)) { \
 ND_PRINT(" [%s %u %s %u]", (message), (expression_1), (#operator), (expression_2)); \
 goto invalid; \
-}
+} \
+} while (0)
 
 /*
  * Check (expression_1 operator expression_2) for invalid packet with
@@ -418,10 +435,12 @@ ND_ICHECKMSG_U((#expression_1), (expression_1), operator, (expression_2))
  * a custom message, format %zu
  */
 #define ND_ICHECKMSG_ZU(message, expression_1, operator, expression_2) \
+do { \
 if ((expression_1) operator (expression_2)) { \
 ND_PRINT(" [%s %u %s %zu]", (message), (expression_1), (#operator), (expression_2)); \
 goto invalid; \
-}
+} \
+} while (0)
 
 /*
  * Check (expression_1 operator expression_2) for invalid packet with
@@ -437,12 +456,16 @@ extern void ts_print(netdissect_options *, const struct timeval *);
 extern void signed_relts_print(netdissect_options *, int32_t);
 extern void unsigned_relts_print(netdissect_options *, uint32_t);
 
+extern const char *nd_format_time(char *buf, size_t bufsize,
+    const char *format, const struct tm *timeptr);
+
 extern void fn_print_char(netdissect_options *, u_char);
 extern void fn_print_str(netdissect_options *, const u_char *);
 extern u_int nd_printztn(netdissect_options *, const u_char *, u_int, const u_char *);
 extern int nd_printn(netdissect_options *, const u_char *, u_int, const u_char *);
 extern void nd_printjn(netdissect_options *, const u_char *, u_int);
 extern void nd_printjnp(netdissect_options *, const u_char *, u_int);
+extern void nd_print_bytes_hex(netdissect_options *, const u_char *, u_int);
 
 /*
  * Flags for txtproto_print().
@@ -496,7 +519,7 @@ extern int unaligned_memcmp(const void *, const void *, size_t);
 #define PLURAL_SUFFIX(n) \
        (((n) != 1) ? "s" : "")
 
-extern const char *tok2strary_internal(const char **, int, const char *, int);
+extern const char *tok2strary_internal(const char **, int, const char *, const int);
 #define        tok2strary(a,f,i) tok2strary_internal(a, sizeof(a)/sizeof(a[0]),f,i)
 
 struct uint_tokary
@@ -561,7 +584,6 @@ extern void null_if_print IF_PRINTER_ARGS;
 extern void pflog_if_print IF_PRINTER_ARGS;
 extern void pktap_if_print IF_PRINTER_ARGS;
 extern void ppi_if_print IF_PRINTER_ARGS;
-extern void ppp_bsdos_if_print IF_PRINTER_ARGS;
 extern void ppp_hdlc_if_print IF_PRINTER_ARGS;
 extern void ppp_if_print IF_PRINTER_ARGS;
 extern void pppoe_if_print IF_PRINTER_ARGS;
@@ -617,7 +639,7 @@ extern void calm_fast_print(netdissect_options *, const u_char *, u_int, const s
 extern void carp_print(netdissect_options *, const u_char *, u_int, u_int);
 extern void cdp_print(netdissect_options *, const u_char *, u_int);
 extern void cfm_print(netdissect_options *, const u_char *, u_int);
-extern u_int chdlc_print(netdissect_options *, const u_char *, u_int);
+extern void chdlc_print(netdissect_options *, const u_char *, u_int);
 extern void cisco_autorp_print(netdissect_options *, const u_char *, u_int);
 extern void cnfp_print(netdissect_options *, const u_char *);
 extern void dccp_print(netdissect_options *, const u_char *, const u_char *, u_int);
@@ -627,10 +649,12 @@ extern void domain_print(netdissect_options *, const u_char *, u_int, int, int);
 extern int dstopt_process(netdissect_options *, const u_char *);
 extern void dtp_print(netdissect_options *, const u_char *, u_int);
 extern void dvmrp_print(netdissect_options *, const u_char *, u_int);
-extern void eap_print(netdissect_options *, const u_char *, u_int);
+extern void eap_print(netdissect_options *, const u_char *, const u_int);
 extern void eapol_print(netdissect_options *, const u_char *);
 extern void egp_print(netdissect_options *, const u_char *, u_int);
 extern void eigrp_print(netdissect_options *, const u_char *, u_int);
+extern void erspan_i_ii_print(netdissect_options *, uint16_t, const u_char *, u_int);
+extern void erspan_iii_print(netdissect_options *, const u_char *, u_int);
 extern void esp_print(netdissect_options *, const u_char *, u_int, const u_char *, u_int, int, u_int);
 extern u_int ether_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), const u_char *);
 extern u_int ether_switch_tag_print(netdissect_options *, const u_char *, u_int, u_int, void (*)(netdissect_options *, const u_char *), u_int);
@@ -652,14 +676,14 @@ extern void hncp_print(netdissect_options *, const u_char *, u_int);
 extern void hsrp_print(netdissect_options *, const u_char *, u_int);
 extern void http_print(netdissect_options *, const u_char *, u_int);
 extern void icmp6_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
-extern void icmp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
+extern void icmp_print(netdissect_options *, const u_char *, u_int, int);
 extern u_int ieee802_11_radio_print(netdissect_options *, const u_char *, u_int, u_int);
 extern u_int ieee802_15_4_print(netdissect_options *, const u_char *, u_int);
 extern void igmp_print(netdissect_options *, const u_char *, u_int);
 extern void igrp_print(netdissect_options *, const u_char *, u_int);
 extern void ip6_print(netdissect_options *, const u_char *, u_int);
 extern void ipN_print(netdissect_options *, const u_char *, u_int);
-extern void ip_print(netdissect_options *, const u_char *, u_int);
+extern void ip_print(netdissect_options *, const u_char *, const u_int);
 extern void ipcomp_print(netdissect_options *, const u_char *);
 extern void ipx_netbios_print(netdissect_options *, const u_char *, u_int);
 extern void ipx_print(netdissect_options *, const u_char *, u_int);
@@ -697,6 +721,7 @@ extern void netbeui_print(netdissect_options *, u_short, const u_char *, u_int);
 extern void nfsreply_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
 extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_char *);
 extern void nfsreq_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
+extern void nhrp_print(netdissect_options *, const u_char *, u_int);
 extern void nsh_print(netdissect_options *, const u_char *, u_int);
 extern void ntp_print(netdissect_options *, const u_char *, u_int);
 extern void oam_print(netdissect_options *, const u_char *, u_int, u_int);
@@ -718,8 +743,8 @@ extern void ptp_print(netdissect_options *, const u_char *, u_int);
 extern const char *q922_string(netdissect_options *, const u_char *, u_int);
 extern void q933_print(netdissect_options *, const u_char *, u_int);
 extern int quic_detect(netdissect_options *, const u_char *, const u_int);
-extern void quic_print(netdissect_options *, const u_char *, const u_int);
-extern void radius_print(netdissect_options *, const u_char *, u_int);
+extern void quic_print(netdissect_options *, const u_char *);
+extern void radius_print(netdissect_options *, const u_char *, const u_int);
 extern void resp_print(netdissect_options *, const u_char *, u_int);
 extern void rip_print(netdissect_options *, const u_char *, u_int);
 extern void ripng_print(netdissect_options *, const u_char *, unsigned int);
@@ -764,7 +789,6 @@ extern void zmtp1_datagram_print(netdissect_options *, const u_char *, const u_i
 extern void zmtp1_print(netdissect_options *, const u_char *, u_int);
 
 /* checksum routines */
-extern void init_checksum(void);
 extern uint16_t verify_crc10_cksum(uint16_t, const u_char *, int);
 extern uint16_t create_osi_cksum(const uint8_t *, int, int);
 
@@ -789,7 +813,7 @@ extern void nd_print_protocol(netdissect_options *);
 extern void nd_print_protocol_caps(netdissect_options *);
 extern void nd_print_invalid(netdissect_options *);
 
-extern int mask2plen(uint32_t);
+extern int mask2plen(const uint32_t);
 extern int mask62plen(const u_char *);
 
 extern const char *dnnum_string(netdissect_options *, u_short);