diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index 16c356cec..710a112cf 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -630,8 +630,17 @@ int TcpSocketImpl::GetSockName (Address &address) const { NS_LOG_FUNCTION_NOARGS (); - address = InetSocketAddress(m_endPoint->GetLocalAddress (), - m_endPoint->GetLocalPort ()); + if (m_endPoint != 0) + { + address = InetSocketAddress (m_endPoint->GetLocalAddress (), + m_endPoint->GetLocalPort ()); + } + else + { + // It is possible to call this method on a socket without a name + // in which case, behavior is unspecified + address = InetSocketAddress (Ipv4Address::GetZero (), 0); + } return 0; } diff --git a/src/internet-stack/udp-socket-impl.cc b/src/internet-stack/udp-socket-impl.cc index f2c015957..e1e2f1d0b 100644 --- a/src/internet-stack/udp-socket-impl.cc +++ b/src/internet-stack/udp-socket-impl.cc @@ -531,6 +531,8 @@ UdpSocketImpl::GetSockName (Address &address) const } else { + // It is possible to call this method on a socket without a name + // in which case, behavior is unspecified address = InetSocketAddress(Ipv4Address::GetZero(), 0); } return 0;