Skip to content

Commit

Permalink
pcap: Add a packet couter for diagnostics
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 17, 2024
1 parent a0a6635 commit 06259c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/utils/pcap_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ typedef struct {
FILE *file;
size_t offset;
void *cache;
size_t num_packets;
} pcap_t;

pcap_t *pcap_start(char *path, uint32_t max_packet_size, uint32_t link_type);
Expand Down
6 changes: 4 additions & 2 deletions src/pcap_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pcap_t *pcap_start(char *path, uint32_t max_packet_size, uint32_t link_type)
header.link_type = link_type;

cap->offset = 0;
cap->num_packets = 0;
cap->file = fopen(path, "wb");
if(cap->file == NULL) {
free(cap->cache);
Expand Down Expand Up @@ -86,8 +87,9 @@ int pcap_add(pcap_t *cap, uint8_t *capture_data, uint32_t length)
uint32_t sec, usec;

if (cap->offset + sizeof(header) + length > PCAP_CACHE_SIZE) {
if (pcap_flush(cap))
if (pcap_flush(cap)) {
return -1;
}
}

get_time(&sec, &usec);
Expand All @@ -100,7 +102,7 @@ int pcap_add(pcap_t *cap, uint8_t *capture_data, uint32_t length)

memcpy((char *)cap->cache + cap->offset, capture_data, length);
cap->offset += length;

cap->num_packets++;
return 0;
}

Expand Down

0 comments on commit 06259c4

Please sign in to comment.