Skip to content

Commit

Permalink
Fix packet print
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigliano committed Apr 10, 2024
1 parent 1c0e8e6 commit 5982fb1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion userland/examples/pfcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void print_packet(const struct pfring_pkthdr *h, const u_char *p, u_int8_t dump_
pfring_print_parsed_pkt(bigbuf, sizeof(bigbuf), p, h);
len = strlen(bigbuf);

if(len > 0) bigbuf[len-1] = '\0';
if(len > 0) bigbuf[len] = '\0';

snprintf(&dump_str[strlen(dump_str)], sizeof(dump_str)-strlen(dump_str), "%s", bigbuf);
} else {
Expand Down
3 changes: 2 additions & 1 deletion userland/examples/pfcount_multichannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ void print_packet(const struct pfring_pkthdr *h, const u_char *p, long threadId)
else buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "[eth_type=0x%04X]", eth_type);

buflen += snprintf(&bigbuf[buflen], BUFSIZE - buflen, "[caplen=%d][len=%d]"
"[eth_offset=%d][l3_offset=%d][l4_offset=%d][payload_offset=%d]\n",
"[eth_offset=%d][l3_offset=%d][l4_offset=%d][payload_offset=%d]",
h->caplen, h->len,
h->extended_hdr.parsed_pkt.offset.eth_offset,
h->extended_hdr.parsed_pkt.offset.l3_offset,
h->extended_hdr.parsed_pkt.offset.l4_offset,
h->extended_hdr.parsed_pkt.offset.payload_offset);
}
fputs(bigbuf, stdout);
fputs("\n", stdout);
}

/* ****************************************************** */
Expand Down
20 changes: 12 additions & 8 deletions userland/examples/pfflow_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,28 @@ void processPacket(const struct pfring_pkthdr *h,

if (!quiet) {

buffer[0] = '\0';
pfring_print_pkt(buffer, sizeof(buffer), p, h->len, h->len);

printf("%s ", buffer);

if (h->extended_hdr.flags & PKT_FLAGS_FLOW_HIT) {
printf("Packet - flow hit\n");
printf("[HIT]");
} else if (h->extended_hdr.flags & PKT_FLAGS_FLOW_MISS) {
printf("Packet - flow miss\n");
printf("[MISS]");
} else if (h->extended_hdr.flags & PKT_FLAGS_FLOW_UNHANDLED) {
printf("Packet - flow unhandled\n");
printf("[UNHANDLED]");
} else {
printf("[-]");
}

buffer[0] = '\0';
pfring_print_pkt(buffer, sizeof(buffer), p, h->len, h->len);
printf("\n");
}

#if 0
/* TODO Discard all future packets for this flow */
hw_filtering_rule r;
hw_filtering_rule r = { 0 };
r.rule_family_type = generic_flow_id_rule;
r.rule_family.flow_id_rule.action = flow_drop_rule;
r.rule_family.flow_id_rule.thread = 0;
r.rule_family.flow_id_rule.flow_id = flow_id;
pfring_add_hw_rule(pd, &r);
#endif
Expand Down
2 changes: 1 addition & 1 deletion userland/lib/pfring_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ int pfring_print_parsed_pkt(char *buff, u_int buff_len, const u_char *p, const s
}

buff_used += snprintf(&buff[buff_used], buff_len - buff_used,
" [caplen=%d][len=%d][eth_offset=%d][l3_offset=%d][l4_offset=%d][payload_offset=%d]\n",
" [caplen=%d][len=%d][eth_offset=%d][l3_offset=%d][l4_offset=%d][payload_offset=%d]",
h->caplen, h->len,
h->extended_hdr.parsed_pkt.offset.eth_offset,
h->extended_hdr.parsed_pkt.offset.l3_offset,
Expand Down

0 comments on commit 5982fb1

Please sign in to comment.