Skip to content

Commit

Permalink
tcpdump-145
Browse files Browse the repository at this point in the history
Imported from tcpdump-145.tar.gz
  • Loading branch information
AppleOSSDistributions committed Jan 15, 2025
1 parent 8430c00 commit 9b6c0fa
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 19 deletions.
9 changes: 5 additions & 4 deletions tcpdump/netdissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,12 @@ extern void nd_pop_all_packet_info(netdissect_options *);
#define PRMD_FLOWID 0x2000
#define PRMD_TRACETAG 0x4000
#define PRMD_DLT 0x8000
#define PRMD_DROP_REASON 0x10000
#define PRMD_DROP_FUNC 0x20000
#define PRMD_DROP_LINE 0x40000
#define PRMD_DROP_REASON 0x10000
#define PRMD_DROP_FUNC 0x20000
#define PRMD_DROP_LINE 0x40000
#define PRMD_COMP_GENCNT 0x80000
#define PRMD_DEFAULT (PRMD_IF|PRMD_PNAME|PRMD_PID|PRMD_SVC|PRMD_DIR|PRMD_COMMENT|PRMD_FLAGS|PRMD_DROP_REASON|PRMD_DROP_FUNC|PRMD_DROP_LINE)
#define PRMD_ALL 0x1ffff
#define PRMD_ALL 0xfffff
#endif /* __APPLE__ */

/*
Expand Down
22 changes: 18 additions & 4 deletions tcpdump/print_pktap.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,39 @@ print_pktap_header(struct netdissect_options *ndo, struct pktap_header *pktp_hdr
pktp_hdr->pth_flowid);
prsep = ", ";
}
#ifdef PKTAP_HAS_TRACE_TAG
if (ndo->ndo_kflag & PRMD_TRACETAG) {
ND_PRINT("%s" "ttag 0x%x",
prsep,
pktp_hdr->pth_trace_tag);
prsep = ", ";
}
#endif /* PKTAP_HAS_TRACE_TAG */
if (ndo->ndo_kflag & PRMD_DLT) {
ND_PRINT("%s" "dlt 0x%x",
prsep,
pktp_hdr->pth_dlt);
prsep = ", ";
}
#ifdef PKTAP_HAS_COMP_GENCNT
if (ndo->ndo_kflag & PRMD_COMP_GENCNT) {
ND_PRINT("%s" "cmpgc 0x%x",
prsep,
pktp_hdr->pth_comp_gencnt);
prsep = ", ";
}
#endif /* PKTAP_HAS_COMP_GENCNT */
if (pktp_hdr->pth_type_next == PTH_TYPE_DROP) {
struct droptap_header *dtap_hdr = (struct droptap_header *)pktp_hdr;
const char *reason_str = drop_reason_str(dtap_hdr->dth_dropreason);
char num_str[32];

if (reason_str == NULL) {
snprintf(num_str, sizeof(num_str), "reason: 0x%08x", dtap_hdr->dth_dropreason);
reason_str = num_str;
}

ND_PRINT("%s" "%s",
prsep,
drop_reason_str(dtap_hdr->dth_dropreason));
prsep,
reason_str);
prsep = ", ";
if (dtap_hdr->dth_dropfunc_size > 0) {
ND_PRINT("%s" "%s:%u",
Expand Down
59 changes: 48 additions & 11 deletions tcpdump/tcpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,9 @@ main(int argc, char **argv)
case 'V':
val |= PRMD_VERBOSE;
break;
case 'c':
val |= PRMD_COMP_GENCNT;
break;
case 'f':
val |= PRMD_FLOWID;
break;
Expand Down Expand Up @@ -3823,10 +3826,14 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
if (ndo->ndo_packet_number)
ND_PRINT("%5lu ", packets_captured - skip_packet_cnt);

if (is_pcap_pkthdr_valid(ndo, h) == 0) {
return;
}

ts_print(ndo, &h->ts);

if (ndo->ndo_kflag && h->comment[0])
ND_PRINT("%s ", h->comment);
ND_PRINT("(%s) ", h->comment);

pretty_print_packet(ndo, h, sp, (u_int)packets_captured);
}
Expand Down Expand Up @@ -3881,10 +3888,14 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
if (ndo->ndo_packet_number)
ND_PRINT("%5lu ", packets_captured - skip_packet_cnt);

if (is_pcap_pkthdr_valid(ndo, h) == 0) {
return;
}

ts_print(ndo, &h->ts);

if (ndo->ndo_kflag && h->comment[0])
ND_PRINT("%s ", h->comment);
ND_PRINT("(%s) ", h->comment);

pretty_print_packet(ndo, h, sp, (u_int)packets_captured);
}
Expand Down Expand Up @@ -4482,7 +4493,7 @@ print_pcap(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
ts_print(ndo, &h->ts);

if (ndo->ndo_kflag && h->comment[0])
ND_PRINT("%s ", h->comment);
ND_PRINT("(%s) ", h->comment);

pretty_print_packet(ndo, h, sp, (u_int)packets_captured);
}
Expand Down Expand Up @@ -4562,6 +4573,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
const char *drop_func = NULL;
uint16_t drop_line = 0;
uint16_t drop_func_len = 0;
uint32_t comp_gencnt = 0;
struct pcapng_option_info option_info;

block = pcap_ng_block_alloc_with_raw_block(ndo->ndo_pcap, (u_char *)sp);
Expand Down Expand Up @@ -4690,7 +4702,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
if (pcap_is_swapped(ndo->ndo_pcap))
packet_flags = SWAPLONG(pmdflags);
}
#ifdef PCAPNG_EPB_FLOW_ID

if (pcap_ng_block_get_option(block, PCAPNG_EPB_FLOW_ID, &option_info) == 1) {
if (option_info.length != 4) {
warning("%s: flow_id option length %u != 4", __func__, option_info.length);
Expand All @@ -4701,9 +4713,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
flow_id = SWAPLONG(flow_id);
}
}
#endif /* PCAPNG_EPB_FLOW_ID */

#ifdef PCAPNG_EPB_TRACE_TAG
if (pcap_ng_block_get_option(block, PCAPNG_EPB_TRACE_TAG, &option_info) == 1) {
if (option_info.length != 2) {
warning("%s: trace_tag option length %u != 2", __func__, option_info.length);
Expand All @@ -4714,7 +4724,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
trace_tag = SWAPSHORT(trace_tag);
}
}
#endif /* PCAPNG_EPB_TRACE_TAG */

/*
* PCAPNG_EPB_DROP_REASON option is set only for droptap.
*/
Expand Down Expand Up @@ -4743,6 +4753,19 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
drop_func = (const char *)(option_info.value);
drop_func_len = option_info.length;
}
#ifdef PCAPNG_EPB_COMP_GENCNT
if (pcap_ng_block_get_option(block, PCAPNG_EPB_COMP_GENCNT, &option_info) == 1) {
if (option_info.length != 4) {
warning("%s: comp_gencnt option length %u != 4", __func__, option_info.length);
goto done;
}
comp_gencnt = *(uint32_t *)(option_info.value);
if (pcap_is_swapped(ndo->ndo_pcap)) {
comp_gencnt = SWAPLONG(comp_gencnt);
}
}
#endif /* PCAPNG_EPB_COMP_GENCNT */

if_id = epbp->interface_id;

pack_flags_code = PCAPNG_EPB_FLAGS;
Expand Down Expand Up @@ -4897,6 +4920,10 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
if (ndo->ndo_packet_number)
ND_PRINT("%5lu ", packets_captured - skip_packet_cnt);

if (is_pcap_pkthdr_valid(ndo, h) == 0) {
return;
}

ts_print(ndo, &h->ts);

/*
Expand Down Expand Up @@ -4984,7 +5011,6 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
}
}

#ifdef PCAPNG_EPB_FLOW_ID
/*
* Flow-id
*/
Expand All @@ -4994,8 +5020,7 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
flow_id);
prsep = ", ";
}
#endif /* PCAPNG_EPB_FLOW_ID */
#ifdef PCAPNG_EPB_TRACE_TAG

/*
* trace_tag
*/
Expand All @@ -5005,14 +5030,26 @@ print_pcap_ng_block(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
trace_tag);
prsep = ", ";
}
#endif /* PCAPNG_EPB_TRACE_TAG */

if (ndo->ndo_kflag & PRMD_DLT) {
ND_PRINT("%s" "dlt 0x%x",
prsep,
if_info->if_linktype);
prsep = ", ";
}

#ifdef PKTAP_HAS_COMP_GENCNT
/*
* compression generation count
*/
if (ndo->ndo_kflag & PRMD_COMP_GENCNT) {
ND_PRINT("%s" "cmpgc 0x%x",
prsep,
comp_gencnt);
prsep = ", ";
}
#endif /* PKTAP_HAS_COMP_GENCNT */

/*
* Comment
*/
Expand Down

0 comments on commit 9b6c0fa

Please # to comment.