diff --git a/src/internet-stack/ipv4-l3-protocol.cc b/src/internet-stack/ipv4-l3-protocol.cc index 0baae1e72..076a24fcf 100644 --- a/src/internet-stack/ipv4-l3-protocol.cc +++ b/src/internet-stack/ipv4-l3-protocol.cc @@ -482,6 +482,7 @@ Ipv4L3Protocol::Receive( Ptr device, Ptr p, uint16_t pr socket->ForwardUp (packet, ipHeader, device); } + NS_ASSERT_MSG (m_routingProtocol != 0, "Need a routing protocol object to process packets"); m_routingProtocol->RouteInput (packet, ipHeader, device, MakeCallback (&Ipv4L3Protocol::IpForward, this), MakeCallback (&Ipv4L3Protocol::IpMulticastForward, this), @@ -609,7 +610,15 @@ Ipv4L3Protocol::Send (Ptr packet, Socket::SocketErrno errno_; Ptr oif (0); // unused for now ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, mayFragment); - Ptr newRoute = m_routingProtocol->RouteOutput (packet, ipHeader, oif, errno_); + Ptr newRoute; + if (m_routingProtocol != 0) + { + newRoute = m_routingProtocol->RouteOutput (packet, ipHeader, oif, errno_); + } + else + { + NS_LOG_ERROR ("Ipv4L3Protocol::Send: m_routingProtocol == 0"); + } if (newRoute) { int32_t interface = GetInterfaceForDevice (newRoute->GetOutputDevice ()); diff --git a/src/internet-stack/tcp-l4-protocol.cc b/src/internet-stack/tcp-l4-protocol.cc index d361a8604..f741a449c 100644 --- a/src/internet-stack/tcp-l4-protocol.cc +++ b/src/internet-stack/tcp-l4-protocol.cc @@ -584,7 +584,15 @@ TcpL4Protocol::Send (Ptr packet, Socket::SocketErrno errno_; Ptr route; Ptr oif (0); //specify non-zero if bound to a source address - route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_); + if (ipv4->GetRoutingProtocol () != 0) + { + route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_); + } + else + { + NS_LOG_ERROR ("No IPV4 Routing Protocol"); + route = 0; + } ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route); } } @@ -623,7 +631,15 @@ TcpL4Protocol::SendPacket (Ptr packet, const TcpHeader &outgoing, header.SetProtocol (PROT_NUMBER); Socket::SocketErrno errno_; Ptr route; - route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_); + if (ipv4->GetRoutingProtocol () != 0) + { + route = ipv4->GetRoutingProtocol ()->RouteOutput (packet, header, oif, errno_); + } + else + { + NS_LOG_ERROR ("No IPV4 Routing Protocol"); + route = 0; + } ipv4->Send (packet, saddr, daddr, PROT_NUMBER, route); } else diff --git a/src/internet-stack/tcp-socket-impl.cc b/src/internet-stack/tcp-socket-impl.cc index cc0e9065e..16c356cec 100644 --- a/src/internet-stack/tcp-socket-impl.cc +++ b/src/internet-stack/tcp-socket-impl.cc @@ -358,6 +358,7 @@ TcpSocketImpl::Connect (const Address & address) NS_LOG_FUNCTION (this << address); Ptr ipv4 = m_node->GetObject (); + NS_ASSERT (ipv4 != 0); if (m_endPoint == 0) { @@ -772,11 +773,17 @@ void TcpSocketImpl::SendEmptyPacket (uint8_t flags) Ptr p = Create (); TcpHeader header; + if (m_endPoint == 0) + { + NS_LOG_WARN ("Failed to send empty packet due to null endpoint"); + return; + } + if (flags & TcpHeader::FIN) { flags |= TcpHeader::ACK; } - + header.SetFlags (flags); header.SetSequenceNumber (m_nextTxSequence); header.SetAckNumber (m_nextRxSequence); @@ -811,9 +818,12 @@ void TcpSocketImpl::SendRST() SendEmptyPacket(TcpHeader::RST); NotifyErrorClose(); CancelAllTimers(); - m_endPoint->SetDestroyCallback(MakeNullCallback()); - m_tcp->DeAllocate (m_endPoint); - m_endPoint = 0; + if (m_endPoint != 0) + { + m_endPoint->SetDestroyCallback(MakeNullCallback()); + m_tcp->DeAllocate (m_endPoint); + m_endPoint = 0; + } } @@ -1093,6 +1103,11 @@ bool TcpSocketImpl::SendPendingData (bool withAck) { return false; // No data exists } + if (m_endPoint == 0) + { + NS_LOG_INFO ("TcpSocketImpl::SendPendingData: No endpoint; m_shutdownSend=" << m_shutdownSend); + return false; // Is this the right way to handle this condition? + } uint32_t nPacketsSent = 0; while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence)) { @@ -1142,7 +1157,7 @@ bool TcpSocketImpl::SendPendingData (bool withAck) if (m_shutdownSend) { m_errno = ERROR_SHUTDOWN; - return -1; + return false; }