diff --git a/ports/bsd/bip-init.c b/ports/bsd/bip-init.c index 7a94b58a..c57962ea 100644 --- a/ports/bsd/bip-init.c +++ b/ports/bsd/bip-init.c @@ -80,6 +80,15 @@ static void debug_print_ipv4(const char *str, } } +/** + * @brief Return the active BIP socket. + * @return The active BIP socket, or -1 if uninitialized. + */ +int bip_get_socket(void) +{ + return BIP_Socket; +} + /** * @brief Enabled debug printing of BACnet/IPv4 */ diff --git a/ports/linux/bip-init.c b/ports/linux/bip-init.c index f68f57f5..5c03b54a 100644 --- a/ports/linux/bip-init.c +++ b/ports/linux/bip-init.c @@ -94,6 +94,17 @@ static void debug_print_ipv4(const char *str, } } + +/** + * @brief Return the active BIP socket. + * @return The active BIP socket, or -1 if uninitialized. + */ +int bip_get_socket(void) +{ + return BIP_Socket; +} + + /** * @brief Enabled debug printing of BACnet/IPv4 */ diff --git a/ports/win32/bip-init.c b/ports/win32/bip-init.c index 5087aff8..37567950 100644 --- a/ports/win32/bip-init.c +++ b/ports/win32/bip-init.c @@ -87,6 +87,17 @@ static void debug_print_ipv4(const char *str, } } +/** + * @brief Return the active BIP socket. + * @return The active BIP socket, or INVALID_SOCKET if uninitialized. + * @note Strictly, the return type should be SOCKET, however in practice + * Windows never returns values large enough that truncation is an issue. + */ +int bip_get_socket(void) +{ + return (int)BIP_Socket; +} + /** * @brief Enabled debug printing of BACnet/IPv4 */ diff --git a/src/bacnet/datalink/bip.h b/src/bacnet/datalink/bip.h index 4ca9d1c3..0ae20cbe 100644 --- a/src/bacnet/datalink/bip.h +++ b/src/bacnet/datalink/bip.h @@ -115,6 +115,9 @@ extern "C" { BACNET_STACK_EXPORT void bip_debug_enable(void); + BACNET_STACK_EXPORT + int bip_get_socket(void); + #ifdef __cplusplus } #endif /* __cplusplus */