diff options
author | Anton Kling <anton@kling.gg> | 2024-02-28 21:47:49 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-02-28 21:47:49 +0100 |
commit | e6c8f7298b40757a410d9df6319824c4f0d70351 (patch) | |
tree | b90ee0eba9a45c7551d9f23b6e66620ff0ea5b66 /kernel/socket.h | |
parent | 4536dc81b4be9a62328826455664cd6d696df8fb (diff) |
TCP/UDP: Start rewrite of network sockets
Having sockets be file descriptors seems like a bad idea so I trying to
make UDP and TCP sockets be more independent and not be abstracted away
as much.
Diffstat (limited to 'kernel/socket.h')
-rw-r--r-- | kernel/socket.h | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/kernel/socket.h b/kernel/socket.h index f765fb7..174ceb1 100644 --- a/kernel/socket.h +++ b/kernel/socket.h @@ -3,6 +3,7 @@ #include <fs/fifo.h> #include <fs/vfs.h> #include <lib/buffered_write.h> +#include <lib/stack.h> #include <stddef.h> #include <typedefs.h> @@ -17,6 +18,42 @@ #define MSG_WAITALL 1 +u32 gen_ipv4(u8 i1, u8 i2, u8 i3, u8 i4); +u32 tcp_connect_ipv4(u32 ip, u16 port, int *error); + +u32 tcp_listen_ipv4(u32 ip, u16 port, int *error); +u32 tcp_accept(u32 listen_socket, int *error); + +int tcp_write(u32 socket, const u8 *buffer, u64 len, u64 *out); +int tcp_read(u32 socket, u8 *buffer, u64 buffer_size, u64 *out); + +struct TcpListen { + u32 ip; + u16 port; + struct stack incoming_connections; +}; + +struct TcpConnection { + int dead; + u16 incoming_port; + u32 outgoing_ip; + u16 outgoing_port; + + int unhandled_packet; + + FIFO_FILE *data_file; + + u32 seq; + u32 ack; + + int handshake_state; +}; + +struct TcpConnection *internal_tcp_incoming(u32 src_ip, u16 src_port, + u32 dst_ip, u16 dst_port); + +struct TcpConnection *tcp_find_connection(u16 port); + typedef struct { vfs_fd_t *ptr_socket_fd; FIFO_FILE *fifo_file; @@ -42,20 +79,6 @@ typedef struct { SOCKET *s; } OPEN_INET_SOCKET; -struct INCOMING_TCP_CONNECTION { - u8 ip[4]; - u16 n_port; - u16 dst_port; - FIFO_FILE *data_file; - struct buffered buffer; - u8 *has_data_ptr; - u8 is_used; - u32 ack_num; - u32 seq_num; - u8 connection_closed; - u8 requesting_connection_close; -}; - typedef u32 in_addr_t; typedef u16 in_port_t; typedef unsigned int sa_family_t; |