Skip to content

Commit 11f224b

Browse files
committed
Use C99 format macro constants for timestamp and vlan_tag
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
1 parent 27b57d9 commit 11f224b

13 files changed

Lines changed: 14 additions & 14 deletions

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ AC_ARG_ENABLE([mysql],
5353
)
5454

5555
# Checks for header files.
56-
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h stdint.h stdlib.h syslog.h unistd.h])
56+
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h inttypes.h stdlib.h syslog.h unistd.h])
5757

5858
# Checks for typedefs, structures, and compiler characteristics.
5959
AC_C_INLINE

src/addrwatch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <limits.h>
44
#include <pwd.h>
55
#include <signal.h>
6-
#include <stdint.h>
6+
#include <inttypes.h>
77
#include <stdio.h>
88
#include <stdlib.h>
99
#include <string.h>

src/addrwatch_stdout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void process_entry(struct shm_log_entry *e, void *arg)
1616
ip4_ntoa(e->ip_address, ip_str);
1717
}
1818

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

src/addrwatch_syslog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void process_entry(struct shm_log_entry *e, void *arg)
1818
ip4_ntoa(e->ip_address, ip_str);
1919
}
2020

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

src/base64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define BASE64_H
33

44
#include "addrwatch.h"
5-
#include <stdint.h>
5+
#include <inttypes.h>
66

77
void base64_encode(const uint8_t *src, char *dst, int ssize, int dsize);
88
char *base64_encode_packet(struct pkt *p);

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define COMMON_H
33

44
#include <arpa/inet.h>
5-
#include <stdint.h>
5+
#include <inttypes.h>
66
#include <stdio.h>
77
#include <sys/socket.h>
88

src/mcache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <sys/types.h>
88
#include <netinet/if_ether.h>
9-
#include <stdint.h>
9+
#include <inttypes.h>
1010

1111
struct mcache_node {
1212
uint8_t l2_addr[ETHER_ADDR_LEN];

src/output_flatfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void output_flatfile_reload()
2222
void output_flatfile_save(struct pkt *p, char *mac_str, char *ip_str)
2323
{
2424
if (cfg.data_fd) {
25-
fprintf(cfg.data_fd, "%lu %s %u %s %s %s\n",
26-
p->pcap_header->ts.tv_sec, p->ifc->name, p->vlan_tag,
25+
fprintf(cfg.data_fd, "%" PRIu64 " %s %" PRIu16 " %s %s %s\n",
26+
(uint64_t)p->pcap_header->ts.tv_sec, p->ifc->name, p->vlan_tag,
2727
mac_str, ip_str, pkt_origin_str[p->origin]);
2828
fflush(cfg.data_fd);
2929
}

src/parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//#include <stdint.h>
1+
//#include <inttypes.h>
22
//#include <stdio.h>
33
//#include <stdlib.h>
44

src/shm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <net/if.h>
55
#include <netinet/in.h>
66
#include <netinet/if_ether.h>
7-
#include <stdint.h>
7+
#include <inttypes.h>
88
#include <sys/socket.h>
99

1010
#define DEFAULT_SHM_LOG_NAME "/addrwatch-shm-log"

0 commit comments

Comments
 (0)