From cf3f881f7aa099e71708f9298e43ade362993cb7 Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 25 Oct 2007 02:13:02 +0000 Subject: [PATCH] Changed BIP debug from define to variable since we are using a lib. Affects Win32 and Linux. --- bacnet-stack/demo/server/main.c | 1 + bacnet-stack/include/bip.h | 2 ++ bacnet-stack/include/config.h | 3 -- bacnet-stack/ports/linux/bip-init.c | 24 ++++++++------- bacnet-stack/ports/win32/bip-init.c | 45 +++++++++++++++-------------- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/bacnet-stack/demo/server/main.c b/bacnet-stack/demo/server/main.c index 88399f86..98e77987 100644 --- a/bacnet-stack/demo/server/main.c +++ b/bacnet-stack/demo/server/main.c @@ -151,6 +151,7 @@ int main(int argc, char *argv[]) Device_Object_Instance_Number(), MAX_APDU); Init_Service_Handlers(); + BIP_Debug = true; if (!datalink_init(getenv("BACNET_IFACE"))) return 1; atexit(cleanup); diff --git a/bacnet-stack/include/bip.h b/bacnet-stack/include/bip.h index a7fc6d3b..0a2a66b8 100644 --- a/bacnet-stack/include/bip.h +++ b/bacnet-stack/include/bip.h @@ -47,6 +47,8 @@ #define BVLL_TYPE_BACNET_IP (0x81) +extern bool BIP_Debug; + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ diff --git a/bacnet-stack/include/config.h b/bacnet-stack/include/config.h index eb96d631..d43b78b4 100644 --- a/bacnet-stack/include/config.h +++ b/bacnet-stack/include/config.h @@ -12,9 +12,6 @@ /* optional debug info for BACnet/IP datalink layers */ #if defined(BACDL_BIP) - #if !defined(BIP_DEBUG) - #define BIP_DEBUG 1 - #endif #if !defined(USE_INADDR) #define USE_INADDR 1 #endif diff --git a/bacnet-stack/ports/linux/bip-init.c b/bacnet-stack/ports/linux/bip-init.c index 0cddb517..6867e5ac 100644 --- a/bacnet-stack/ports/linux/bip-init.c +++ b/bacnet-stack/ports/linux/bip-init.c @@ -38,6 +38,8 @@ #include "bip.h" #include "net.h" +bool BIP_Debug = false; + static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr, int request) { @@ -83,10 +85,10 @@ static void bip_set_interface(char *ifname) local_address.s_addr = 0; } bip_set_addr(local_address.s_addr); -#if BIP_DEBUG - fprintf(stderr, "Interface: %s\n", ifname); - fprintf(stderr, "IP Address: %s\n", inet_ntoa(local_address)); -#endif + if (BIP_Debug) { + fprintf(stderr, "Interface: %s\n", ifname); + fprintf(stderr, "IP Address: %s\n", inet_ntoa(local_address)); + } /* setup local broadcast address */ rv = get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR); @@ -94,13 +96,13 @@ static void bip_set_interface(char *ifname) broadcast_address.s_addr = ~0; } bip_set_broadcast_addr(broadcast_address.s_addr); -#if BIP_DEBUG - fprintf(stderr, "IP Broadcast Address: %s\n", - inet_ntoa(broadcast_address)); - fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", - bip_get_port(), - bip_get_port()); -#endif + if (BIP_Debug) { + fprintf(stderr, "IP Broadcast Address: %s\n", + inet_ntoa(broadcast_address)); + fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", + bip_get_port(), + bip_get_port()); + } } bool bip_init(char *ifname) diff --git a/bacnet-stack/ports/win32/bip-init.c b/bacnet-stack/ports/win32/bip-init.c index 3bcae9d0..4bfb79a9 100644 --- a/bacnet-stack/ports/win32/bip-init.c +++ b/bacnet-stack/ports/win32/bip-init.c @@ -40,6 +40,7 @@ #include "bip.h" #include "net.h" +bool BIP_Debug = false; /* To fill a need, we invent the gethostaddr() function. */ static long gethostaddr(void) { @@ -51,13 +52,13 @@ static long gethostaddr(void) if ((host_ent = gethostbyname(host_name)) == NULL) return -1; -#if BIP_DEBUG - printf("host: %s at %u.%u.%u.%u\n", host_name, - ((uint8_t*)host_ent->h_addr)[0], - ((uint8_t*)host_ent->h_addr)[1], - ((uint8_t*)host_ent->h_addr)[2], - ((uint8_t*)host_ent->h_addr)[3]); -#endif + if (BIP_Debug) { + printf("host: %s at %u.%u.%u.%u\n", host_name, + ((uint8_t*)host_ent->h_addr)[0], + ((uint8_t*)host_ent->h_addr)[1], + ((uint8_t*)host_ent->h_addr)[2], + ((uint8_t*)host_ent->h_addr)[3]); + } /* note: network byte order */ return *(long *) host_ent->h_addr; } @@ -105,10 +106,10 @@ void bip_set_interface(char *ifname) if (bip_get_addr() == 0) { bip_set_addr(inet_addr(ifname)); } -#if BIP_DEBUG - address.s_addr = htonl(bip_get_addr()); - fprintf(stderr, "Interface: %s\n", ifname); -#endif + if (BIP_Debug) { + address.s_addr = htonl(bip_get_addr()); + fprintf(stderr, "Interface: %s\n", ifname); + } /* setup local broadcast address */ if (bip_get_broadcast_addr() == 0) { address.s_addr = htonl(bip_get_addr()); @@ -263,21 +264,21 @@ bool bip_init(char *ifname) } bip_set_addr(address.s_addr); } -#if BIP_DEBUG - fprintf(stderr, "IP Address: %s\n", inet_ntoa(address)); -#endif + if (BIP_Debug) { + fprintf(stderr, "IP Address: %s\n", inet_ntoa(address)); + } /* has broadcast address been set? */ if (bip_get_broadcast_addr() == 0) { set_broadcast_address(address.s_addr); } -#if BIP_DEBUG - broadcast_address.s_addr = htonl(bip_get_broadcast_addr()); - fprintf(stderr, "IP Broadcast Address: %s\n", - inet_ntoa(broadcast_address)); - fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", - bip_get_port(), - bip_get_port()); -#endif + if (BIP_Debug) { + broadcast_address.s_addr = htonl(bip_get_broadcast_addr()); + fprintf(stderr, "IP Broadcast Address: %s\n", + inet_ntoa(broadcast_address)); + fprintf(stderr, "UDP Port: 0x%04X [%hu]\n", + bip_get_port(), + bip_get_port()); + } /* assumes that the driver has already been initialized */ sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); bip_set_socket(sock_fd);