diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-14 01:00:10 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-14 01:00:10 +0100 |
commit | be46f1bb1ff497e6d113705ffa3b751ba455e65d (patch) | |
tree | c66f2dee7abfbffe89aaed2d56edfc68bf66d23a /Kernel/IPv4Socket.cpp | |
parent | 66d55f8e0c16c641ec3ca47711835de974320b06 (diff) | |
download | serenity-be46f1bb1ff497e6d113705ffa3b751ba455e65d.zip |
IPv4: More work on the TCP implementation.
Reading from the peer now kinda works. Something still going wrong with
sending packets but it's getting closer.
Diffstat (limited to 'Kernel/IPv4Socket.cpp')
-rw-r--r-- | Kernel/IPv4Socket.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Kernel/IPv4Socket.cpp b/Kernel/IPv4Socket.cpp index a749ddf9ee..5ab2a3e283 100644 --- a/Kernel/IPv4Socket.cpp +++ b/Kernel/IPv4Socket.cpp @@ -97,25 +97,27 @@ KResult IPv4Socket::connect(const sockaddr* address, socklen_t address_size) m_destination_address = IPv4Address((const byte*)&ia.sin_addr.s_addr); m_destination_port = ntohs(ia.sin_port); - if (type() == SOCK_STREAM) { - // FIXME: Figure out the adapter somehow differently. - auto* adapter = NetworkAdapter::from_ipv4_address(IPv4Address(192, 168, 5, 2)); - if (!adapter) - ASSERT_NOT_REACHED(); + if (type() != SOCK_STREAM) + return KSuccess; + + // FIXME: Figure out the adapter somehow differently. + auto* adapter = NetworkAdapter::from_ipv4_address(IPv4Address(192, 168, 5, 2)); + if (!adapter) + ASSERT_NOT_REACHED(); - allocate_source_port_if_needed(); + allocate_source_port_if_needed(); - send_tcp_packet(*adapter, TCPFlags::SYN); - m_tcp_state = TCPState::Connecting1; + m_tcp_sequence_number = 0; + m_tcp_ack_number = 0; - current->set_blocked_socket(this); - block(Process::BlockedConnect); - Scheduler::yield(); + send_tcp_packet(*adapter, TCPFlags::SYN); + m_tcp_state = TCPState::Connecting1; - ASSERT(is_connected()); - return KSuccess; - } + current->set_blocked_socket(this); + block(Process::BlockedConnect); + Scheduler::yield(); + ASSERT(is_connected()); return KSuccess; } @@ -372,7 +374,7 @@ ssize_t IPv4Socket::recvfrom(void* buffer, size_t buffer_length, int flags, sock if (type() == SOCK_STREAM) { auto& tcp_packet = *static_cast<const TCPPacket*>(ipv4_packet.payload()); - size_t payload_size = packet_buffer.size() - sizeof(TCPPacket); + size_t payload_size = packet_buffer.size() - tcp_packet.header_size(); ASSERT(buffer_length >= payload_size); if (addr) { auto& ia = *(sockaddr_in*)addr; |