Skip to content

Commit

Permalink
Use C99 format macro constants for timestamp and vlan_tag
Browse files Browse the repository at this point in the history
Since timestamp and vlan_tag in the shm_log_entry struct are C99 fixed
width integer types (uint64_t and uint16_t), the cross-platform way to
print these values is to use the corresponding format macro
constants[1], PRIu64 and PRIu16.

This also adjusts the places where the time_t timestamp value is
printed, casting it to uint64_t, for consistency.

Fixes #25
Fixes #26

[1]: https://en.cppreference.com/w/c/types/integer#Format_macro_constants
  • Loading branch information
jefferyto committed Jul 4, 2021
1 parent 27b57d9 commit b49c70f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/addrwatch_stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void process_entry(struct shm_log_entry *e, void *arg)
ip4_ntoa(e->ip_address, ip_str);
}

printf("%lu %s %u %s %s %s\n", e->timestamp, e->interface, e->vlan_tag,
printf("%" PRIu64 " %s %" PRIu16 " %s %s %s\n", e->timestamp, e->interface, e->vlan_tag,
mac_str, ip_str, pkt_origin_str[e->origin]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/addrwatch_syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void process_entry(struct shm_log_entry *e, void *arg)
ip4_ntoa(e->ip_address, ip_str);
}

syslog(LOG_INFO, "%lu %s %u %s %s %s", e->timestamp, e->interface,
syslog(LOG_INFO, "%" PRIu64 " %s %" PRIu16 " %s %s %s", e->timestamp, e->interface,
e->vlan_tag, mac_str, ip_str, pkt_origin_str[e->origin]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/output_flatfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ void output_flatfile_reload()
void output_flatfile_save(struct pkt *p, char *mac_str, char *ip_str)
{
if (cfg.data_fd) {
fprintf(cfg.data_fd, "%lu %s %u %s %s %s\n",
p->pcap_header->ts.tv_sec, p->ifc->name, p->vlan_tag,
fprintf(cfg.data_fd, "%" PRIu64 " %s %" PRIu16 " %s %s %s\n",
(uint64_t)p->pcap_header->ts.tv_sec, p->ifc->name, p->vlan_tag,
mac_str, ip_str, pkt_origin_str[p->origin]);
fflush(cfg.data_fd);
}
Expand Down
2 changes: 1 addition & 1 deletion src/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void save_pairing(struct pkt *p)

output_shm_save(p, mac_str, ip_str);
if (!cfg.quiet) {
printf("%lu %s %u %s %s %s\n", tstamp, p->ifc->name,
printf("%" PRIu64 " %s %" PRIu16 " %s %s %s\n", (uint64_t)tstamp, p->ifc->name,
p->vlan_tag, mac_str, ip_str, pkt_origin_str[p->origin]);
fflush(stdout);
}
Expand Down

0 comments on commit b49c70f

Please sign in to comment.