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);
}