Enable ND_LONGJMP_FROM_TCHECK. Remove one redundant ND_TCHECK_SIZE()
instance and place the remaining ones after the code that prints
individual structure fields, so it can print incomplete structures. Lose
intermediate snprintf() calls and associated props. Lose trailing spaces
in v1 and v5 output.
#include "netdissect-stdinc.h"
#include "netdissect-stdinc.h"
+#define ND_LONGJMP_FROM_TCHECK
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
#endif
nh = (const struct nfhdr_v1 *)cp;
#endif
nh = (const struct nfhdr_v1 *)cp;
ver = GET_BE_U_2(nh->version);
nrecs = GET_BE_U_4(nh->count);
ver = GET_BE_U_2(nh->version);
nrecs = GET_BE_U_4(nh->count);
ND_PRINT("%2u recs", nrecs);
for (; nrecs != 0; nr++, nrecs--) {
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);
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 ",
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
GET_BE_U_2(nr->srcport));
GET_BE_U_2(nr->srcport));
- ND_PRINT("> %s%s%s:%u ",
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
GET_BE_U_2(nr->dstport));
ND_PRINT(">> %s\n ",
GET_BE_U_2(nr->dstport));
ND_PRINT(">> %s\n ",
ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", 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_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);
#endif
nh = (const struct nfhdr_v5 *)cp;
#endif
nh = (const struct nfhdr_v5 *)cp;
ver = GET_BE_U_2(nh->version);
nrecs = GET_BE_U_4(nh->count);
ver = GET_BE_U_2(nh->version);
nrecs = GET_BE_U_4(nh->count);
GET_BE_U_4(nh->utc_sec), GET_BE_U_4(nh->utc_nsec));
ND_PRINT("#%u, ", GET_BE_U_4(nh->sequence));
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--) {
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);
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)),
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
+ GET_U_1(nr->src_mask), GET_BE_U_2(nr->src_as),
GET_BE_U_2(nr->srcport));
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)),
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
+ GET_U_1(nr->dst_mask), GET_BE_U_2(nr->dst_as),
GET_BE_U_2(nr->dstport));
ND_PRINT(">> %s\n ",
GET_BE_U_2(nr->dstport));
ND_PRINT(">> %s\n ",
ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", 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_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);
#endif
nh = (const struct nfhdr_v6 *)cp;
#endif
nh = (const struct nfhdr_v6 *)cp;
ver = GET_BE_U_2(nh->version);
nrecs = GET_BE_U_4(nh->count);
ver = GET_BE_U_2(nh->version);
nrecs = GET_BE_U_4(nh->count);
GET_BE_U_4(nh->utc_sec), GET_BE_U_4(nh->utc_nsec));
ND_PRINT("#%u, ", GET_BE_U_4(nh->sequence));
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--) {
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);
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)),
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->src_ina)),
+ GET_U_1(nr->src_mask), GET_BE_U_2(nr->src_as),
GET_BE_U_2(nr->srcport));
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)),
intoa(GET_IPV4_TO_NETWORK_ORDER(nr->dst_ina)),
+ GET_U_1(nr->dst_mask), GET_BE_U_2(nr->dst_as),
GET_BE_U_2(nr->dstport));
ND_PRINT(">> %s\n ",
GET_BE_U_2(nr->dstport));
ND_PRINT(">> %s\n ",
ND_PRINT("%s ", bittok2str_nosep(tcp_flag_values, "", 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_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);