Optimize log output

This commit is contained in:
luwenpeng
2024-10-24 16:22:18 +08:00
parent cb6f231935
commit e0b8732a15
6 changed files with 33 additions and 22 deletions

View File

@@ -241,21 +241,31 @@ static void packet_handler(u_char *user, const struct pcap_pkthdr *h, const u_ch
{
struct runtime *rte = (struct runtime *)user;
char *ptr = (char *)calloc(1, h->caplen);
if (ptr == NULL)
{
PRINT_RED("calloc() failed");
return;
}
memcpy(ptr, bytes, h->caplen);
struct packet pkt;
memset(&pkt, 0, sizeof(pkt));
packet_parse(&pkt, (const char *)bytes, h->caplen);
packet_parse(&pkt, (const char *)ptr, h->caplen);
rte->pcap_count++;
if (rte->print_verbose)
{
PRINT_GREEN("frame=%lu len=%u", rte->pcap_count, h->caplen);
packet_print(&pkt);
packet_dump_hex(&pkt, STDOUT_FILENO);
}
if (rte->tshark_format)
{
tshark_format(rte, &pkt);
}
free(ptr);
}
static void usage(char *cmd)