From 54ceabd48d49fdc44a70a2ff66f98d9bb1ff2ee2 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Fri, 9 Aug 2019 12:34:32 +1000 Subject: Kernel: Use WeakPtr instead of NetworkAdapter* in net code --- Kernel/Net/TCPSocket.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Kernel/Net/TCPSocket.cpp') diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index b6c1b726af..df998389f4 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -80,7 +80,16 @@ int TCPSocket::protocol_send(const void* data, int data_length) void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size) { - ASSERT(m_adapter); + if (!m_adapter) { + if (has_specific_local_address()) { + m_adapter = NetworkAdapter::from_ipv4_address(local_address()); + } else { + m_adapter = adapter_for_route_to(peer_address()); + if (m_adapter) + set_local_address(m_adapter->ipv4_address()); + } + } + ASSERT(!!m_adapter); auto buffer = ByteBuffer::create_zeroed(sizeof(TCPPacket) + payload_size); auto& tcp_packet = *(TCPPacket*)(buffer.pointer()); -- cgit v1.2.3