fix bsd/bip6.c:35:16: error: variadic macros are a C99 feature (#805)

Copy debug_fprintf_bip6() from linux
This commit is contained in:
Patrick Grimm
2024-10-11 16:46:17 +02:00
committed by GitHub
parent 52a2cd437a
commit e71c4177a1
2 changed files with 34 additions and 15 deletions
+33 -14
View File
@@ -15,6 +15,9 @@
#include "bacnet/datalink/bip6.h" #include "bacnet/datalink/bip6.h"
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#include "bacnet/basic/bbmd6/h_bbmd6.h" #include "bacnet/basic/bbmd6/h_bbmd6.h"
#if DEBUG_ENABLED
#include "bacnet/basic/sys/debug.h"
#endif
#include "bacport.h" #include "bacport.h"
#if defined(__APPLE__) || defined(__darwin__) #if defined(__APPLE__) || defined(__darwin__)
@@ -29,17 +32,31 @@
/* enable debugging */ /* enable debugging */
static bool BIP6_Debug = false; static bool BIP6_Debug = false;
#if PRINT_ENABLED
#include <stdarg.h> /**
#include <stdio.h> * @brief Conditionally use the debug_printf function
#define PRINTF(...) \ *
if (BIP6_Debug) { \ * @param stream - file stream to print to
fprintf(stderr,__VA_ARGS__); \ * @param format - printf format string
fflush(stderr); \ * @param ... - variable arguments
* @note This function is only works if
* PRINT_ENABLED and BIP6_Debug is non-zero
*/
static void debug_fprintf_bip6(FILE *stream, const char *format, ...)
{
#if DEBUG_ENABLED
va_list ap;
if (BIP6_Debug) {
va_start(ap, format);
debug_fprintf(stream, format, ap);
va_end(ap);
} }
#else #else
#define PRINTF(...) (void)stream;
(void)format;
#endif #endif
}
/** /**
* @brief Print the IPv6 address with debug info * @brief Print the IPv6 address with debug info
@@ -48,7 +65,9 @@ static bool BIP6_Debug = false;
*/ */
static void debug_print_ipv6(const char *str, const struct in6_addr *addr) static void debug_print_ipv6(const char *str, const struct in6_addr *addr)
{ {
PRINTF("BIP6: %s " debug_fprintf_bip6(
stdout,
"BIP6: %s "
"%02x%02x:%02x%02x:%02x%02x:%02x%02x:" "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
"%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", "%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
str, (int)addr->s6_addr[0], (int)addr->s6_addr[1], str, (int)addr->s6_addr[0], (int)addr->s6_addr[1],
@@ -62,7 +81,7 @@ static void debug_print_ipv6(const char *str, const struct in6_addr *addr)
} }
/** /**
* @brief Enabled debug printing of BACnet/IPv4 * @brief Enabled debug printing of BACnet/IPv6
*/ */
void bip6_debug_enable(void) void bip6_debug_enable(void)
{ {
@@ -95,11 +114,11 @@ void bip6_set_interface(char *ifname)
} }
ifa_tmp = ifa; ifa_tmp = ifa;
if (BIP6_Debug) { if (BIP6_Debug) {
PRINTF("BIP6: seeking interface: %s\n", ifname); debug_fprintf_bip6(stdout, "BIP6: seeking interface: %s\n", ifname);
} }
while (ifa_tmp) { while (ifa_tmp) {
if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6)) { if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6)) {
PRINTF("BIP6: found interface: %s\n", ifa_tmp->ifa_name); debug_fprintf_bip6(stdout, "BIP6: found interface: %s\n", ifa_tmp->ifa_name);
} }
if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6) && if ((ifa_tmp->ifa_addr) && (ifa_tmp->ifa_addr->sa_family == AF_INET6) &&
(strcasecmp(ifa_tmp->ifa_name, ifname) == 0)) { (strcasecmp(ifa_tmp->ifa_name, ifname) == 0)) {
@@ -120,7 +139,7 @@ void bip6_set_interface(char *ifname)
ifa_tmp = ifa_tmp->ifa_next; ifa_tmp = ifa_tmp->ifa_next;
} }
if (!found) { if (!found) {
PRINTF("BIP6: unable to set interface: %s\n", ifname); debug_fprintf_bip6(stdout, "BIP6: unable to set interface: %s\n", ifname);
exit(1); exit(1);
} }
} }
@@ -409,7 +428,7 @@ bool bip6_init(char *ifname)
if (BIP6_Addr.port == 0) { if (BIP6_Addr.port == 0) {
bip6_set_port(0xBAC0U); bip6_set_port(0xBAC0U);
} }
PRINTF("BIP6: IPv6 UDP port: 0x%04X\n", BIP6_Addr.port); debug_fprintf_bip6(stdout, "BIP6: IPv6 UDP port: 0x%04X\n", BIP6_Addr.port);
if (BIP6_Broadcast_Addr.address[0] == 0) { if (BIP6_Broadcast_Addr.address[0] == 0) {
bvlc6_address_set(&BIP6_Broadcast_Addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0, bvlc6_address_set(&BIP6_Broadcast_Addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0,
0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID); 0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID);
+1 -1
View File
@@ -69,7 +69,7 @@ static void debug_print_ipv6(const char *str, const struct in6_addr *addr)
} }
/** /**
* @brief Enabled debug printing of BACnet/IPv4 * @brief Enabled debug printing of BACnet/IPv6
*/ */
void bip6_debug_enable(void) void bip6_debug_enable(void)
{ {