FIX static timeGetTime, make it similar to linux port (#358)

This commit is contained in:
Patrick Grimm
2022-11-20 21:27:30 +01:00
committed by GitHub
parent 0f75085771
commit 78fd0cf9cb
3 changed files with 27 additions and 10 deletions
+24 -8
View File
@@ -42,10 +42,7 @@
#include "bacnet/basic/bbmd/h_bbmd.h"
#include "bacport.h"
/**
* @file
* @brief Initializes BACnet/IP interface (BSD/MAC OS X).
*/
/** @file bsd/bip-init.c @brief Initializes BACnet/IP interface (BSD/MAC OS X). */
/* unix sockets */
static int BIP_Socket = -1;
@@ -63,6 +60,8 @@ static struct in_addr BIP_Address;
static struct in_addr BIP_Broadcast_Addr;
/* enable debugging */
static bool BIP_Debug = false;
/* interface name */
static char BIP_Interface_Name[IF_NAMESIZE] = { 0 };
/**
* @brief Print the IPv4 address with debug info
@@ -475,6 +474,19 @@ static void *get_addr_ptr(struct sockaddr *sockaddr_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,
* and saves it into the BACnet/IP data structures.
*
@@ -638,17 +650,22 @@ bool bip_init(char *ifname)
int sock_fd = -1;
if (ifname) {
strncpy(BIP_Interface_Name, ifname, sizeof(BIP_Interface_Name));
bip_set_interface(ifname);
printf("interface %s", ifname);
} 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_port = BIP_Port;
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));
sin.sin_addr.s_addr = BIP_Address.s_addr;
sock_fd = createSocket(&sin);
BIP_Socket = sock_fd;
@@ -682,7 +699,6 @@ bool bip_valid(void)
*/
void bip_cleanup(void)
{
if (BIP_Socket != -1) {
close(BIP_Socket);
}
+2 -1
View File
@@ -432,7 +432,7 @@ bool bip6_init(char *ifname)
if (BIP6_Addr.port == 0) {
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) {
bvlc6_address_set(&BIP6_Broadcast_Addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0,
0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID);
@@ -476,6 +476,7 @@ bool bip6_init(char *ifname)
server.sin6_family = AF_INET6;
server.sin6_addr = in6addr_any;
server.sin6_port = htons(BIP6_Addr.port);
debug_print_ipv6("Binding->", &server.sin6_addr);
status = bind(BIP6_Socket, (const void *)&server, sizeof(server));
if (status < 0) {
perror("BIP: bind");
+1 -1
View File
@@ -38,7 +38,7 @@
static struct timespec start;
/* The timeGetTime function retrieves the system time, in milliseconds.
The system time is the time elapsed since the OS was started. */
unsigned long timeGetTime(void)
static unsigned long timeGetTime(void)
{
struct timespec now;
unsigned long ticks;