[Inet] Explicit error return from FromSockAddr (#13049)
#### Problem
A review raised questions about failure cases of `IPAddress::FromSockAddr`
(see link in the issue for details).
Fixes #10800 _IPAddress::FromSockAddr falls through to return Any — is this correct?_
#### Change overview
- Replace `FromSockAddr(SockAddr)` with `GetIPAddressFromSockAddr()`
with an explicit error return.
- Change its main use, `InterfaceIterator::GetAddress()`, to also
have an explicit error return.
#### Testing
CI (`GetAddress` is unit tested).
diff --git a/src/inet/TCPEndPointImplSockets.cpp b/src/inet/TCPEndPointImplSockets.cpp
index 1f6bd36..faa6972 100644
--- a/src/inet/TCPEndPointImplSockets.cpp
+++ b/src/inet/TCPEndPointImplSockets.cpp
@@ -748,10 +748,8 @@
bool ipAddrFound = false;
for (InterfaceAddressIterator addrIter; addrIter.HasCurrent(); addrIter.Next())
{
- const IPAddress curAddr = addrIter.GetAddress();
- const InterfaceId curIntfId = addrIter.GetInterfaceId();
-
- if (curIntfId == intfId)
+ IPAddress curAddr;
+ if ((addrIter.GetInterfaceId() == intfId) && (addrIter.GetAddress(curAddr) == CHIP_NO_ERROR))
{
// Search for an IPv4 address on the TargetInterface