You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.8 KiB

  1. From 11f224baeede709a181a9ccb01558ff39432a994 Mon Sep 17 00:00:00 2001
  2. From: Jeffery To <jeffery.to@gmail.com>
  3. Date: Mon, 5 Jul 2021 04:23:19 +0800
  4. Subject: [PATCH] Use C99 format macro constants for timestamp and vlan_tag
  5. Since timestamp and vlan_tag in the shm_log_entry struct are C99 fixed
  6. width integer types (uint64_t and uint16_t), the cross-platform way to
  7. print these values is to use the corresponding format macro
  8. constants[1], PRIu64 and PRIu16.
  9. This also adjusts the places where the time_t timestamp value is
  10. printed, casting it to uint64_t, for consistency.
  11. Fixes https://github.com/fln/addrwatch/issues/25
  12. Fixes https://github.com/fln/addrwatch/issues/26
  13. [1]: https://en.cppreference.com/w/c/types/integer#Format_macro_constants
  14. ---
  15. configure.ac | 2 +-
  16. src/addrwatch.c | 2 +-
  17. src/addrwatch_stdout.c | 2 +-
  18. src/addrwatch_syslog.c | 2 +-
  19. src/base64.h | 2 +-
  20. src/common.h | 2 +-
  21. src/mcache.h | 2 +-
  22. src/output_flatfile.c | 4 ++--
  23. src/parse.c | 2 +-
  24. src/shm.h | 2 +-
  25. src/shm_client.c | 2 +-
  26. src/storage.c | 2 +-
  27. src/util.h | 2 +-
  28. 13 files changed, 14 insertions(+), 14 deletions(-)
  29. --- a/configure.ac
  30. +++ b/configure.ac
  31. @@ -53,7 +53,7 @@ AC_ARG_ENABLE([mysql],
  32. )
  33. # Checks for header files.
  34. -AC_CHECK_HEADERS([arpa/inet.h netinet/in.h stdint.h stdlib.h syslog.h unistd.h])
  35. +AC_CHECK_HEADERS([arpa/inet.h netinet/in.h inttypes.h stdlib.h syslog.h unistd.h])
  36. # Checks for typedefs, structures, and compiler characteristics.
  37. AC_C_INLINE
  38. --- a/src/addrwatch.c
  39. +++ b/src/addrwatch.c
  40. @@ -3,7 +3,7 @@
  41. #include <limits.h>
  42. #include <pwd.h>
  43. #include <signal.h>
  44. -#include <stdint.h>
  45. +#include <inttypes.h>
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. --- a/src/addrwatch_stdout.c
  50. +++ b/src/addrwatch_stdout.c
  51. @@ -16,7 +16,7 @@ void process_entry(struct shm_log_entry
  52. ip4_ntoa(e->ip_address, ip_str);
  53. }
  54. - printf("%lu %s %u %s %s %s\n", e->timestamp, e->interface, e->vlan_tag,
  55. + printf("%" PRIu64 " %s %" PRIu16 " %s %s %s\n", e->timestamp, e->interface, e->vlan_tag,
  56. mac_str, ip_str, pkt_origin_str[e->origin]);
  57. }
  58. --- a/src/addrwatch_syslog.c
  59. +++ b/src/addrwatch_syslog.c
  60. @@ -18,7 +18,7 @@ void process_entry(struct shm_log_entry
  61. ip4_ntoa(e->ip_address, ip_str);
  62. }
  63. - syslog(LOG_INFO, "%lu %s %u %s %s %s", e->timestamp, e->interface,
  64. + syslog(LOG_INFO, "%" PRIu64 " %s %" PRIu16 " %s %s %s", e->timestamp, e->interface,
  65. e->vlan_tag, mac_str, ip_str, pkt_origin_str[e->origin]);
  66. }
  67. --- a/src/base64.h
  68. +++ b/src/base64.h
  69. @@ -2,7 +2,7 @@
  70. #define BASE64_H
  71. #include "addrwatch.h"
  72. -#include <stdint.h>
  73. +#include <inttypes.h>
  74. void base64_encode(const uint8_t *src, char *dst, int ssize, int dsize);
  75. char *base64_encode_packet(struct pkt *p);
  76. --- a/src/common.h
  77. +++ b/src/common.h
  78. @@ -2,7 +2,7 @@
  79. #define COMMON_H
  80. #include <arpa/inet.h>
  81. -#include <stdint.h>
  82. +#include <inttypes.h>
  83. #include <stdio.h>
  84. #include <sys/socket.h>
  85. --- a/src/mcache.h
  86. +++ b/src/mcache.h
  87. @@ -6,7 +6,7 @@
  88. #include <sys/types.h>
  89. #include <netinet/if_ether.h>
  90. -#include <stdint.h>
  91. +#include <inttypes.h>
  92. struct mcache_node {
  93. uint8_t l2_addr[ETHER_ADDR_LEN];
  94. --- a/src/output_flatfile.c
  95. +++ b/src/output_flatfile.c
  96. @@ -22,8 +22,8 @@ void output_flatfile_reload()
  97. void output_flatfile_save(struct pkt *p, char *mac_str, char *ip_str)
  98. {
  99. if (cfg.data_fd) {
  100. - fprintf(cfg.data_fd, "%lu %s %u %s %s %s\n",
  101. - p->pcap_header->ts.tv_sec, p->ifc->name, p->vlan_tag,
  102. + fprintf(cfg.data_fd, "%" PRIu64 " %s %" PRIu16 " %s %s %s\n",
  103. + (uint64_t)p->pcap_header->ts.tv_sec, p->ifc->name, p->vlan_tag,
  104. mac_str, ip_str, pkt_origin_str[p->origin]);
  105. fflush(cfg.data_fd);
  106. }
  107. --- a/src/parse.c
  108. +++ b/src/parse.c
  109. @@ -1,4 +1,4 @@
  110. -//#include <stdint.h>
  111. +//#include <inttypes.h>
  112. //#include <stdio.h>
  113. //#include <stdlib.h>
  114. --- a/src/shm.h
  115. +++ b/src/shm.h
  116. @@ -4,7 +4,7 @@
  117. #include <net/if.h>
  118. #include <netinet/in.h>
  119. #include <netinet/if_ether.h>
  120. -#include <stdint.h>
  121. +#include <inttypes.h>
  122. #include <sys/socket.h>
  123. #define DEFAULT_SHM_LOG_NAME "/addrwatch-shm-log"
  124. --- a/src/shm_client.c
  125. +++ b/src/shm_client.c
  126. @@ -2,7 +2,7 @@
  127. #include <fcntl.h>
  128. #include <net/if.h>
  129. -#include <stdint.h>
  130. +#include <inttypes.h>
  131. #include <stdlib.h>
  132. #include <sys/mman.h>
  133. #include <sys/stat.h>
  134. --- a/src/storage.c
  135. +++ b/src/storage.c
  136. @@ -129,7 +129,7 @@ void save_pairing(struct pkt *p)
  137. output_shm_save(p, mac_str, ip_str);
  138. if (!cfg.quiet) {
  139. - printf("%lu %s %u %s %s %s\n", tstamp, p->ifc->name,
  140. + printf("%" PRIu64 " %s %" PRIu16 " %s %s %s\n", (uint64_t)tstamp, p->ifc->name,
  141. p->vlan_tag, mac_str, ip_str, pkt_origin_str[p->origin]);
  142. fflush(stdout);
  143. }
  144. --- a/src/util.h
  145. +++ b/src/util.h
  146. @@ -5,7 +5,7 @@
  147. #include "config.h"
  148. #endif
  149. -#include <stdint.h>
  150. +#include <inttypes.h>
  151. #include <stdio.h>
  152. #include <syslog.h>