Skip to content

Commit

Permalink
Print time for each log
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigliano committed Sep 3, 2024
1 parent 970e2c5 commit a341083
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion userland/examples_ft/ftflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pfring *pd = NULL;
pfring_ft_table *ft = NULL;
int bind_core = -1;
int bind_time_pulse_core = -1;
u_int8_t quiet = 0, verbose = 0, stats_only = 0;
u_int8_t quiet = 0, verbose = 0, stats_only = 0, log_time = 1;
u_int8_t time_pulse = 0, enable_l7 = 0, do_shutdown = 0;
u_int64_t num_pkts = 0, num_bytes = 0, num_flows = 0;
#ifdef PRINT_NDPI_INFO
Expand Down Expand Up @@ -215,6 +215,16 @@ const char *status_to_string(pfring_ft_flow_status status) {

/* ******************************** */

void print_time() {
time_t now = time(NULL);
struct tm* tm_info = localtime(&now);
char time_buff[26];
strftime(time_buff, sizeof(time_buff), "%H:%M:%S", tm_info);
printf("%s ", time_buff);
}

/* ******************************** */

/* This callback is called when a flow expires */
void processFlow(pfring_ft_flow *flow, void *user){
pfring_ft_flow_key *k;
Expand All @@ -233,6 +243,9 @@ void processFlow(pfring_ft_flow *flow, void *user){
ip2 = (char *) inet_ntop(AF_INET6, &k->daddr.v6, buf2, sizeof(buf2));
}

if (log_time)
print_time();

printf("[Flow] ");

if(enable_l7)
Expand Down Expand Up @@ -319,6 +332,8 @@ void process_packet(const struct pfring_pkthdr *h, const u_char *p, const u_char
char buffer[256];
buffer[0] = '\0';
pfring_print_pkt(buffer, sizeof(buffer), p, h->len, h->caplen);
if (log_time)
print_time();
printf("[Packet]%s %s", action == PFRING_FT_ACTION_DISCARD ? " [discard]" : "", buffer);
}
}
Expand Down

0 comments on commit a341083

Please sign in to comment.