FIX static timeGetTime, make it similar to linux port (#358)
This commit is contained in:
+24
-8
@@ -42,10 +42,7 @@
|
|||||||
#include "bacnet/basic/bbmd/h_bbmd.h"
|
#include "bacnet/basic/bbmd/h_bbmd.h"
|
||||||
#include "bacport.h"
|
#include "bacport.h"
|
||||||
|
|
||||||
/**
|
/** @file bsd/bip-init.c @brief Initializes BACnet/IP interface (BSD/MAC OS X). */
|
||||||
* @file
|
|
||||||
* @brief Initializes BACnet/IP interface (BSD/MAC OS X).
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* unix sockets */
|
/* unix sockets */
|
||||||
static int BIP_Socket = -1;
|
static int BIP_Socket = -1;
|
||||||
@@ -63,6 +60,8 @@ static struct in_addr BIP_Address;
|
|||||||
static struct in_addr BIP_Broadcast_Addr;
|
static struct in_addr BIP_Broadcast_Addr;
|
||||||
/* enable debugging */
|
/* enable debugging */
|
||||||
static bool BIP_Debug = false;
|
static bool BIP_Debug = false;
|
||||||
|
/* interface name */
|
||||||
|
static char BIP_Interface_Name[IF_NAMESIZE] = { 0 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print the IPv4 address with debug info
|
* @brief Print the IPv4 address with debug info
|
||||||
@@ -475,6 +474,19 @@ static void *get_addr_ptr(struct sockaddr *sockaddr_ptr)
|
|||||||
return addr_ptr;
|
return addr_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the default interface name using routing info
|
||||||
|
* @return interface name, or NULL if not found or none
|
||||||
|
*/
|
||||||
|
static char *ifname_default(void)
|
||||||
|
{
|
||||||
|
if (BIP_Interface_Name[0] != 0) {
|
||||||
|
return BIP_Interface_Name;
|
||||||
|
}
|
||||||
|
strncpy(BIP_Interface_Name, "en0", sizeof(BIP_Interface_Name));
|
||||||
|
return BIP_Interface_Name;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the local IP address and local broadcast address from the system,
|
/** Gets the local IP address and local broadcast address from the system,
|
||||||
* and saves it into the BACnet/IP data structures.
|
* and saves it into the BACnet/IP data structures.
|
||||||
*
|
*
|
||||||
@@ -638,17 +650,22 @@ bool bip_init(char *ifname)
|
|||||||
int sock_fd = -1;
|
int sock_fd = -1;
|
||||||
|
|
||||||
if (ifname) {
|
if (ifname) {
|
||||||
|
strncpy(BIP_Interface_Name, ifname, sizeof(BIP_Interface_Name));
|
||||||
bip_set_interface(ifname);
|
bip_set_interface(ifname);
|
||||||
printf("interface %s", ifname);
|
|
||||||
} else {
|
} else {
|
||||||
bip_set_interface("en0");
|
bip_set_interface(ifname_default());
|
||||||
|
}
|
||||||
|
if (BIP_Address.s_addr == 0) {
|
||||||
|
fprintf(stderr, "BIP: Failed to get an IP address from %s!\n",
|
||||||
|
BIP_Interface_Name);
|
||||||
|
fflush(stderr);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sin.sin_family = AF_INET;
|
sin.sin_family = AF_INET;
|
||||||
sin.sin_port = BIP_Port;
|
sin.sin_port = BIP_Port;
|
||||||
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
|
||||||
|
|
||||||
|
|
||||||
sin.sin_addr.s_addr = BIP_Address.s_addr;
|
sin.sin_addr.s_addr = BIP_Address.s_addr;
|
||||||
sock_fd = createSocket(&sin);
|
sock_fd = createSocket(&sin);
|
||||||
BIP_Socket = sock_fd;
|
BIP_Socket = sock_fd;
|
||||||
@@ -682,7 +699,6 @@ bool bip_valid(void)
|
|||||||
*/
|
*/
|
||||||
void bip_cleanup(void)
|
void bip_cleanup(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (BIP_Socket != -1) {
|
if (BIP_Socket != -1) {
|
||||||
close(BIP_Socket);
|
close(BIP_Socket);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -432,7 +432,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", htons(BIP6_Addr.port));
|
PRINTF("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);
|
||||||
@@ -476,6 +476,7 @@ bool bip6_init(char *ifname)
|
|||||||
server.sin6_family = AF_INET6;
|
server.sin6_family = AF_INET6;
|
||||||
server.sin6_addr = in6addr_any;
|
server.sin6_addr = in6addr_any;
|
||||||
server.sin6_port = htons(BIP6_Addr.port);
|
server.sin6_port = htons(BIP6_Addr.port);
|
||||||
|
debug_print_ipv6("Binding->", &server.sin6_addr);
|
||||||
status = bind(BIP6_Socket, (const void *)&server, sizeof(server));
|
status = bind(BIP6_Socket, (const void *)&server, sizeof(server));
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
perror("BIP: bind");
|
perror("BIP: bind");
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
static struct timespec start;
|
static struct timespec start;
|
||||||
/* The timeGetTime function retrieves the system time, in milliseconds.
|
/* The timeGetTime function retrieves the system time, in milliseconds.
|
||||||
The system time is the time elapsed since the OS was started. */
|
The system time is the time elapsed since the OS was started. */
|
||||||
unsigned long timeGetTime(void)
|
static unsigned long timeGetTime(void)
|
||||||
{
|
{
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
unsigned long ticks;
|
unsigned long ticks;
|
||||||
|
|||||||
Reference in New Issue
Block a user