]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-cnfp.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-cnfp.c
index 4799ce1464160fc6b767795fa20458104d80e47a..d5fd9d67472684c6aaf2cb79d8aae21806477c0f 100644 (file)
  *    https://www.cisco.com/c/en/us/td/docs/net_mgmt/netflow_collection_engine/3-6/user/guide/format.html#wp1005892
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include "netdissect-stdinc.h"
 
-#include <stdio.h>
-#include <string.h>
-
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -167,7 +163,6 @@ cnfp_v1_print(netdissect_options *ndo, const u_char *cp)
 #endif
 
        nh = (const struct nfhdr_v1 *)cp;
-       ND_TCHECK_SIZE(nh);
 
        ver = GET_BE_U_2(nh->version);
        nrecs = GET_BE_U_4(nh->count);
@@ -190,28 +185,18 @@ cnfp_v1_print(netdissect_options *ndo, const u_char *cp)
        ND_PRINT("%2u recs", nrecs);
 
        for (; nrecs != 0; nr++, nrecs--) {
-               char buf[20];
-               char asbuf[20];
-
-               /*
-                * Make sure we have the entire record.
-                */
-               ND_TCHECK_SIZE(nr);
                ND_PRINT("\n  started %u.%03u, last %u.%03u",
                       GET_BE_U_4(nr->start_time)/1000,
                       GET_BE_U_4(nr->start_time)%1000,
                       GET_BE_U_4(nr->last_time)/1000,
                       GET_BE_U_4(nr->last_time)%1000);
 
-               asbuf[0] = buf[0] = '\0';
-               ND_PRINT("\n    %s%s%s:%u ",
+               ND_PRINT("\n    %s:%u ",
                        intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
-                       buf, asbuf,
                        GET_BE_U_2(nr->srcport));
 
-               ND_PRINT("> %s%s%s:%u ",
+               ND_PRINT("> %s:%u ",
                        intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
-                       buf, asbuf,
                        GET_BE_U_2(nr->dstport));
 
                ND_PRINT(">> %s\n    ",
@@ -227,27 +212,17 @@ cnfp_v1_print(netdissect_options *ndo, const u_char *cp)
                if (proto == IPPROTO_TCP) {
                        u_int flags;
                        flags = GET_U_1(nr->tcp_flags);
-                       ND_PRINT("%s%s%s%s%s%s%s",
-                               flags & TH_FIN  ? "F" : "",
-                               flags & TH_SYN  ? "S" : "",
-                               flags & TH_RST  ? "R" : "",
-                               flags & TH_PUSH ? "P" : "",
-                               flags & TH_ACK  ? "A" : "",
-                               flags & TH_URG  ? "U" : "",
-                               flags           ? " " : "");
+                       if (flags)
+                               ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", flags));
                }
 
-               buf[0]='\0';
-               ND_PRINT("tos %u, %u (%u octets) %s",
+               ND_PRINT("tos %u, %u (%u octets)",
                       GET_U_1(nr->tos),
                       GET_BE_U_4(nr->packets),
-                      GET_BE_U_4(nr->octets), buf);
+                      GET_BE_U_4(nr->octets));
+               /* This was not all of struct nfrec_v1. */
+               ND_TCHECK_SIZE(nr);
        }
-       return;
-
-trunc:
-       nd_print_trunc(ndo);
-       return;
 }
 
 static void
@@ -263,7 +238,6 @@ cnfp_v5_print(netdissect_options *ndo, const u_char *cp)
 #endif
 
        nh = (const struct nfhdr_v5 *)cp;
-       ND_TCHECK_SIZE(nh);
 
        ver = GET_BE_U_2(nh->version);
        nrecs = GET_BE_U_4(nh->count);
@@ -282,39 +256,27 @@ cnfp_v5_print(netdissect_options *ndo, const u_char *cp)
               GET_BE_U_4(nh->utc_sec), GET_BE_U_4(nh->utc_nsec));
 
        ND_PRINT("#%u, ", GET_BE_U_4(nh->sequence));
+       /* This was not all of struct nfhdr_v5. */
+       ND_TCHECK_SIZE(nh);
        nr = (const struct nfrec_v5 *)&nh[1];
 
        ND_PRINT("%2u recs", nrecs);
 
        for (; nrecs != 0; nr++, nrecs--) {
-               char buf[20];
-               char asbuf[20];
-
-               /*
-                * Make sure we have the entire record.
-                */
-               ND_TCHECK_SIZE(nr);
                ND_PRINT("\n  started %u.%03u, last %u.%03u",
                       GET_BE_U_4(nr->start_time)/1000,
                       GET_BE_U_4(nr->start_time)%1000,
                       GET_BE_U_4(nr->last_time)/1000,
                       GET_BE_U_4(nr->last_time)%1000);
 
-               asbuf[0] = buf[0] = '\0';
-               snprintf(buf, sizeof(buf), "/%u", GET_U_1(nr->src_mask));
-               snprintf(asbuf, sizeof(asbuf), ":%u",
-                       GET_BE_U_2(nr->src_as));
-               ND_PRINT("\n    %s%s%s:%u ",
+               ND_PRINT("\n    %s/%u:%u:%u ",
                        intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
-                       buf, asbuf,
+                       GET_U_1(nr->src_mask), GET_BE_U_2(nr->src_as),
                        GET_BE_U_2(nr->srcport));
 
-               snprintf(buf, sizeof(buf), "/%u", GET_U_1(nr->dst_mask));
-               snprintf(asbuf, sizeof(asbuf), ":%u",
-                        GET_BE_U_2(nr->dst_as));
-               ND_PRINT("> %s%s%s:%u ",
+               ND_PRINT("> %s/%u:%u:%u ",
                        intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
-                       buf, asbuf,
+                       GET_U_1(nr->dst_mask), GET_BE_U_2(nr->dst_as),
                        GET_BE_U_2(nr->dstport));
 
                ND_PRINT(">> %s\n    ",
@@ -330,27 +292,17 @@ cnfp_v5_print(netdissect_options *ndo, const u_char *cp)
                if (proto == IPPROTO_TCP) {
                        u_int flags;
                        flags = GET_U_1(nr->tcp_flags);
-                       ND_PRINT("%s%s%s%s%s%s%s",
-                               flags & TH_FIN  ? "F" : "",
-                               flags & TH_SYN  ? "S" : "",
-                               flags & TH_RST  ? "R" : "",
-                               flags & TH_PUSH ? "P" : "",
-                               flags & TH_ACK  ? "A" : "",
-                               flags & TH_URG  ? "U" : "",
-                               flags           ? " " : "");
+                       if (flags)
+                               ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", flags));
                }
 
-               buf[0]='\0';
-               ND_PRINT("tos %u, %u (%u octets) %s",
+               ND_PRINT("tos %u, %u (%u octets)",
                       GET_U_1(nr->tos),
                       GET_BE_U_4(nr->packets),
-                      GET_BE_U_4(nr->octets), buf);
+                      GET_BE_U_4(nr->octets));
+               /* This was not all of struct nfrec_v5. */
+               ND_TCHECK_SIZE(nr);
        }
-       return;
-
-trunc:
-       nd_print_trunc(ndo);
-       return;
 }
 
 static void
@@ -366,7 +318,6 @@ cnfp_v6_print(netdissect_options *ndo, const u_char *cp)
 #endif
 
        nh = (const struct nfhdr_v6 *)cp;
-       ND_TCHECK_SIZE(nh);
 
        ver = GET_BE_U_2(nh->version);
        nrecs = GET_BE_U_4(nh->count);
@@ -385,39 +336,27 @@ cnfp_v6_print(netdissect_options *ndo, const u_char *cp)
               GET_BE_U_4(nh->utc_sec), GET_BE_U_4(nh->utc_nsec));
 
        ND_PRINT("#%u, ", GET_BE_U_4(nh->sequence));
+       /* This was not all of struct nfhdr_v6. */
+       ND_TCHECK_SIZE(nh);
        nr = (const struct nfrec_v6 *)&nh[1];
 
        ND_PRINT("%2u recs", nrecs);
 
        for (; nrecs != 0; nr++, nrecs--) {
-               char buf[20];
-               char asbuf[20];
-
-               /*
-                * Make sure we have the entire record.
-                */
-               ND_TCHECK_SIZE(nr);
                ND_PRINT("\n  started %u.%03u, last %u.%03u",
                       GET_BE_U_4(nr->start_time)/1000,
                       GET_BE_U_4(nr->start_time)%1000,
                       GET_BE_U_4(nr->last_time)/1000,
                       GET_BE_U_4(nr->last_time)%1000);
 
-               asbuf[0] = buf[0] = '\0';
-               snprintf(buf, sizeof(buf), "/%u", GET_U_1(nr->src_mask));
-               snprintf(asbuf, sizeof(asbuf), ":%u",
-                       GET_BE_U_2(nr->src_as));
-               ND_PRINT("\n    %s%s%s:%u ",
+               ND_PRINT("\n    %s/%u:%u:%u ",
                        intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
-                       buf, asbuf,
+                       GET_U_1(nr->src_mask), GET_BE_U_2(nr->src_as),
                        GET_BE_U_2(nr->srcport));
 
-               snprintf(buf, sizeof(buf), "/%u", GET_U_1(nr->dst_mask));
-               snprintf(asbuf, sizeof(asbuf), ":%u",
-                        GET_BE_U_2(nr->dst_as));
-               ND_PRINT("> %s%s%s:%u ",
+               ND_PRINT("> %s/%u:%u:%u ",
                        intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
-                       buf, asbuf,
+                       GET_U_1(nr->dst_mask), GET_BE_U_2(nr->dst_as),
                        GET_BE_U_2(nr->dstport));
 
                ND_PRINT(">> %s\n    ",
@@ -433,30 +372,19 @@ cnfp_v6_print(netdissect_options *ndo, const u_char *cp)
                if (proto == IPPROTO_TCP) {
                        u_int flags;
                        flags = GET_U_1(nr->tcp_flags);
-                       ND_PRINT("%s%s%s%s%s%s%s",
-                               flags & TH_FIN  ? "F" : "",
-                               flags & TH_SYN  ? "S" : "",
-                               flags & TH_RST  ? "R" : "",
-                               flags & TH_PUSH ? "P" : "",
-                               flags & TH_ACK  ? "A" : "",
-                               flags & TH_URG  ? "U" : "",
-                               flags           ? " " : "");
+                       if (flags)
+                               ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", flags));
                }
 
-               buf[0]='\0';
-               snprintf(buf, sizeof(buf), "(%u<>%u encaps)",
-                        (GET_BE_U_2(nr->flags) >> 8) & 0xff,
-                        (GET_BE_U_2(nr->flags)) & 0xff);
-               ND_PRINT("tos %u, %u (%u octets) %s",
+               ND_PRINT("tos %u, %u (%u octets) (%u<>%u encaps)",
                       GET_U_1(nr->tos),
                       GET_BE_U_4(nr->packets),
-                      GET_BE_U_4(nr->octets), buf);
+                      GET_BE_U_4(nr->octets),
+                      (GET_BE_U_2(nr->flags) >> 8) & 0xff,
+                      (GET_BE_U_2(nr->flags)) & 0xff);
+               /* This was not all of struct nfrec_v6. */
+               ND_TCHECK_SIZE(nr);
        }
-       return;
-
-trunc:
-       nd_print_trunc(ndo);
-       return;
 }
 
 void
@@ -468,7 +396,6 @@ cnfp_print(netdissect_options *ndo, const u_char *cp)
         * First 2 bytes are the version number.
         */
        ndo->ndo_protocol = "cnfp";
-       ND_TCHECK_2(cp);
        ver = GET_BE_U_2(cp);
        switch (ver) {
 
@@ -488,9 +415,4 @@ cnfp_print(netdissect_options *ndo, const u_char *cp)
                ND_PRINT("NetFlow v%x", ver);
                break;
        }
-       return;
-
-trunc:
-       nd_print_trunc(ndo);
-       return;
 }