Changed BIP debug from define to variable since we are using a lib. Affects Win32 and Linux.
This commit is contained in:
@@ -151,6 +151,7 @@ int main(int argc, char *argv[])
|
|||||||
Device_Object_Instance_Number(),
|
Device_Object_Instance_Number(),
|
||||||
MAX_APDU);
|
MAX_APDU);
|
||||||
Init_Service_Handlers();
|
Init_Service_Handlers();
|
||||||
|
BIP_Debug = true;
|
||||||
if (!datalink_init(getenv("BACNET_IFACE")))
|
if (!datalink_init(getenv("BACNET_IFACE")))
|
||||||
return 1;
|
return 1;
|
||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
|
|||||||
@@ -47,6 +47,8 @@
|
|||||||
|
|
||||||
#define BVLL_TYPE_BACNET_IP (0x81)
|
#define BVLL_TYPE_BACNET_IP (0x81)
|
||||||
|
|
||||||
|
extern bool BIP_Debug;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|||||||
@@ -12,9 +12,6 @@
|
|||||||
|
|
||||||
/* optional debug info for BACnet/IP datalink layers */
|
/* optional debug info for BACnet/IP datalink layers */
|
||||||
#if defined(BACDL_BIP)
|
#if defined(BACDL_BIP)
|
||||||
#if !defined(BIP_DEBUG)
|
|
||||||
#define BIP_DEBUG 1
|
|
||||||
#endif
|
|
||||||
#if !defined(USE_INADDR)
|
#if !defined(USE_INADDR)
|
||||||
#define USE_INADDR 1
|
#define USE_INADDR 1
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
#include "bip.h"
|
#include "bip.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
|
bool BIP_Debug = false;
|
||||||
|
|
||||||
static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr,
|
static int get_local_ifr_ioctl(char *ifname, struct ifreq *ifr,
|
||||||
int request)
|
int request)
|
||||||
{
|
{
|
||||||
@@ -83,10 +85,10 @@ static void bip_set_interface(char *ifname)
|
|||||||
local_address.s_addr = 0;
|
local_address.s_addr = 0;
|
||||||
}
|
}
|
||||||
bip_set_addr(local_address.s_addr);
|
bip_set_addr(local_address.s_addr);
|
||||||
#if BIP_DEBUG
|
if (BIP_Debug) {
|
||||||
fprintf(stderr, "Interface: %s\n", ifname);
|
fprintf(stderr, "Interface: %s\n", ifname);
|
||||||
fprintf(stderr, "IP Address: %s\n", inet_ntoa(local_address));
|
fprintf(stderr, "IP Address: %s\n", inet_ntoa(local_address));
|
||||||
#endif
|
}
|
||||||
/* setup local broadcast address */
|
/* setup local broadcast address */
|
||||||
rv = get_local_address_ioctl(ifname, &broadcast_address,
|
rv = get_local_address_ioctl(ifname, &broadcast_address,
|
||||||
SIOCGIFBRDADDR);
|
SIOCGIFBRDADDR);
|
||||||
@@ -94,13 +96,13 @@ static void bip_set_interface(char *ifname)
|
|||||||
broadcast_address.s_addr = ~0;
|
broadcast_address.s_addr = ~0;
|
||||||
}
|
}
|
||||||
bip_set_broadcast_addr(broadcast_address.s_addr);
|
bip_set_broadcast_addr(broadcast_address.s_addr);
|
||||||
#if BIP_DEBUG
|
if (BIP_Debug) {
|
||||||
fprintf(stderr, "IP Broadcast Address: %s\n",
|
fprintf(stderr, "IP Broadcast Address: %s\n",
|
||||||
inet_ntoa(broadcast_address));
|
inet_ntoa(broadcast_address));
|
||||||
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
|
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
|
||||||
bip_get_port(),
|
bip_get_port(),
|
||||||
bip_get_port());
|
bip_get_port());
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bip_init(char *ifname)
|
bool bip_init(char *ifname)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include "bip.h"
|
#include "bip.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
|
||||||
|
bool BIP_Debug = false;
|
||||||
/* To fill a need, we invent the gethostaddr() function. */
|
/* To fill a need, we invent the gethostaddr() function. */
|
||||||
static long gethostaddr(void)
|
static long gethostaddr(void)
|
||||||
{
|
{
|
||||||
@@ -51,13 +52,13 @@ static long gethostaddr(void)
|
|||||||
|
|
||||||
if ((host_ent = gethostbyname(host_name)) == NULL)
|
if ((host_ent = gethostbyname(host_name)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
#if BIP_DEBUG
|
if (BIP_Debug) {
|
||||||
printf("host: %s at %u.%u.%u.%u\n", host_name,
|
printf("host: %s at %u.%u.%u.%u\n", host_name,
|
||||||
((uint8_t*)host_ent->h_addr)[0],
|
((uint8_t*)host_ent->h_addr)[0],
|
||||||
((uint8_t*)host_ent->h_addr)[1],
|
((uint8_t*)host_ent->h_addr)[1],
|
||||||
((uint8_t*)host_ent->h_addr)[2],
|
((uint8_t*)host_ent->h_addr)[2],
|
||||||
((uint8_t*)host_ent->h_addr)[3]);
|
((uint8_t*)host_ent->h_addr)[3]);
|
||||||
#endif
|
}
|
||||||
/* note: network byte order */
|
/* note: network byte order */
|
||||||
return *(long *) host_ent->h_addr;
|
return *(long *) host_ent->h_addr;
|
||||||
}
|
}
|
||||||
@@ -105,10 +106,10 @@ void bip_set_interface(char *ifname)
|
|||||||
if (bip_get_addr() == 0) {
|
if (bip_get_addr() == 0) {
|
||||||
bip_set_addr(inet_addr(ifname));
|
bip_set_addr(inet_addr(ifname));
|
||||||
}
|
}
|
||||||
#if BIP_DEBUG
|
if (BIP_Debug) {
|
||||||
address.s_addr = htonl(bip_get_addr());
|
address.s_addr = htonl(bip_get_addr());
|
||||||
fprintf(stderr, "Interface: %s\n", ifname);
|
fprintf(stderr, "Interface: %s\n", ifname);
|
||||||
#endif
|
}
|
||||||
/* setup local broadcast address */
|
/* setup local broadcast address */
|
||||||
if (bip_get_broadcast_addr() == 0) {
|
if (bip_get_broadcast_addr() == 0) {
|
||||||
address.s_addr = htonl(bip_get_addr());
|
address.s_addr = htonl(bip_get_addr());
|
||||||
@@ -263,21 +264,21 @@ bool bip_init(char *ifname)
|
|||||||
}
|
}
|
||||||
bip_set_addr(address.s_addr);
|
bip_set_addr(address.s_addr);
|
||||||
}
|
}
|
||||||
#if BIP_DEBUG
|
if (BIP_Debug) {
|
||||||
fprintf(stderr, "IP Address: %s\n", inet_ntoa(address));
|
fprintf(stderr, "IP Address: %s\n", inet_ntoa(address));
|
||||||
#endif
|
}
|
||||||
/* has broadcast address been set? */
|
/* has broadcast address been set? */
|
||||||
if (bip_get_broadcast_addr() == 0) {
|
if (bip_get_broadcast_addr() == 0) {
|
||||||
set_broadcast_address(address.s_addr);
|
set_broadcast_address(address.s_addr);
|
||||||
}
|
}
|
||||||
#if BIP_DEBUG
|
if (BIP_Debug) {
|
||||||
broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
|
broadcast_address.s_addr = htonl(bip_get_broadcast_addr());
|
||||||
fprintf(stderr, "IP Broadcast Address: %s\n",
|
fprintf(stderr, "IP Broadcast Address: %s\n",
|
||||||
inet_ntoa(broadcast_address));
|
inet_ntoa(broadcast_address));
|
||||||
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
|
fprintf(stderr, "UDP Port: 0x%04X [%hu]\n",
|
||||||
bip_get_port(),
|
bip_get_port(),
|
||||||
bip_get_port());
|
bip_get_port());
|
||||||
#endif
|
}
|
||||||
/* assumes that the driver has already been initialized */
|
/* assumes that the driver has already been initialized */
|
||||||
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
bip_set_socket(sock_fd);
|
bip_set_socket(sock_fd);
|
||||||
|
|||||||
Reference in New Issue
Block a user