diff --git a/src/internet/model/ipv4-end-point-demux.cc b/src/internet/model/ipv4-end-point-demux.cc index 9bfd2f712..7c3cde2e7 100644 --- a/src/internet/model/ipv4-end-point-demux.cc +++ b/src/internet/model/ipv4-end-point-demux.cc @@ -27,7 +27,7 @@ namespace ns3 { NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux"); Ipv4EndPointDemux::Ipv4EndPointDemux () - : m_ephemeral (49152) + : m_ephemeral (49152), m_portLast (65535), m_portFirst (49152) { NS_LOG_FUNCTION_NOARGS (); } diff --git a/src/internet/model/ipv4-end-point-demux.h b/src/internet/model/ipv4-end-point-demux.h index a8d3a2d28..f76dff7f2 100644 --- a/src/internet/model/ipv4-end-point-demux.h +++ b/src/internet/model/ipv4-end-point-demux.h @@ -77,6 +77,8 @@ private: uint16_t AllocateEphemeralPort (void); uint16_t m_ephemeral; + uint16_t m_portLast; + uint16_t m_portFirst; EndPoints m_endPoints; }; diff --git a/src/internet/model/tcp-socket-base.cc b/src/internet/model/tcp-socket-base.cc index 415a5368c..3f445dd3b 100644 --- a/src/internet/model/tcp-socket-base.cc +++ b/src/internet/model/tcp-socket-base.cc @@ -219,6 +219,11 @@ TcpSocketBase::Bind (void) { NS_LOG_FUNCTION_NOARGS (); m_endPoint = m_tcp->Allocate (); + if (0 == m_endPoint) + { + m_errno = ERROR_ADDRNOTAVAIL; + return -1; + } return SetupCallback (); } @@ -238,6 +243,11 @@ TcpSocketBase::Bind (const Address &address) if (ipv4 == Ipv4Address::GetAny () && port == 0) { m_endPoint = m_tcp->Allocate (); + if (0 == m_endPoint) + { + m_errno = ERROR_ADDRNOTAVAIL; + return -1; + } } else if (ipv4 == Ipv4Address::GetAny () && port != 0) { @@ -251,6 +261,11 @@ TcpSocketBase::Bind (const Address &address) else if (ipv4 != Ipv4Address::GetAny () && port == 0) { m_endPoint = m_tcp->Allocate (ipv4); + if (0 == m_endPoint) + { + m_errno = ERROR_ADDRNOTAVAIL; + return -1; + } } else if (ipv4 != Ipv4Address::GetAny () && port != 0) {