From 0b948d40987ba3d15d9640d6c4ed2fed449c20dd Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 22 Sep 2021 19:00:04 +0100 Subject: [PATCH] Make sure that bind returns error if it cannot bind. Added test for SCTP bind error/success. --- lib/src/common/network_utils.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/common/network_utils.cc b/lib/src/common/network_utils.cc index 5d829b70b..e6dc6a97b 100644 --- a/lib/src/common/network_utils.cc +++ b/lib/src/common/network_utils.cc @@ -195,6 +195,8 @@ bool bind_addr(int fd, const sockaddr_in& addr_in) perror("bind()"); return false; } + srslog::fetch_basic_logger(LOGSERVICE) + .debug("Successfully bound to address %s:%d", get_ip(addr_in).c_str(), get_port(addr_in)); return true; } @@ -206,7 +208,11 @@ bool bind_addr(int fd, const char* bind_addr_str, int port, sockaddr_in* addr_re .error("Failed to convert IP address (%s) to sockaddr_in struct", bind_addr_str); return false; } - bind_addr(fd, addr_tmp); + + if (not bind_addr(fd, addr_tmp)) { + return false; + } + if (addr_result != nullptr) { *addr_result = addr_tmp; }