Make GetBindAddress() callable from outside net.cpp
What changed, and why it matters
This commit simply moves a small helper function that reads a socket's local address from one source file to another, making it usable by more parts of the program. The actual code behavior is unchanged; it is a routine refactoring, not a security fix or vulnerability.
No security action required; treat as normal code refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates GetBindAddress() from src/net.cpp (where it was a static, file-local function) to src/netbase.cpp and exposes it via a declaration in src/netbase.h. The implementation is moved verbatim: it calls getsockname via Sock::GetSockName(), wraps the result in a CService, and logs a warning on failure. No logic changes, no new callers introduced, and no security boundary altered.
Changed components
src/net.cppsrc/netbase.cppsrc/netbase.hInspect captured patch +16 / −14
diff --git a/src/net.cpp b/src/net.cpp
index bd3d0bb1..559319bf 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -360,20 +360,6 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)
return true;
}
-/** Get the bind address for a socket as CService. */
-static CService GetBindAddress(const Sock& sock)
-{
- CService addr_bind;
- struct sockaddr_storage sockaddr_bind;
- socklen_t sockaddr_bind_len = sizeof(sockaddr_bind);
- if (!sock.GetSockName((struct sockaddr*)&sockaddr_bind, &sockaddr_bind_len)) {
- addr_bind.SetSockAddr((const struct sockaddr*)&sockaddr_bind, sockaddr_bind_len);
- } else {
- LogWarning("getsockname failed\n");
- }
- return addr_bind;
-}
-
CNode* CConnman::ConnectNode(CAddress addrConnect,
const char* pszDest,
bool fCountFailure,
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 1cc8f095..43d9d04b 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -947,3 +947,16 @@ CService MaybeFlipIPv6toCJDNS(const CService& service)
}
return ret;
}
+
+CService GetBindAddress(const Sock& sock)
+{
+ CService addr_bind;
+ struct sockaddr_storage sockaddr_bind;
+ socklen_t sockaddr_bind_len = sizeof(sockaddr_bind);
+ if (!sock.GetSockName((struct sockaddr*)&sockaddr_bind, &sockaddr_bind_len)) {
+ addr_bind.SetSockAddr((const struct sockaddr*)&sockaddr_bind, sockaddr_bind_len);
+ } else {
+ LogWarning("getsockname failed\n");
+ }
+ return addr_bind;
+}
diff --git a/src/netbase.h b/src/netbase.h
index d3c263f9..9c4c6262 100644
--- a/src/netbase.h
+++ b/src/netbase.h
@@ -362,4 +362,7 @@ bool IsBadPort(uint16_t port);
*/
CService MaybeFlipIPv6toCJDNS(const CService& service);
+/** Get the bind address for a socket as CService. */
+CService GetBindAddress(const Sock& sock);
+
#endif // BITCOIN_NETBASE_H
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.