From 431c88102153b8b41a15a1105e291ecf161c030e Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Wed, 18 Nov 2020 13:49:19 +0100
Subject: Started libnet

---
 libc/inc/socket.h | 33 +++++++++++++++++++++++++++++++++
 libc/inc/sys.h    |  6 +++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 libc/inc/socket.h

(limited to 'libc/inc')

diff --git a/libc/inc/socket.h b/libc/inc/socket.h
new file mode 100644
index 0000000..651bba0
--- /dev/null
+++ b/libc/inc/socket.h
@@ -0,0 +1,33 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef SOCKET_H
+#define SOCKET_H
+
+#include <def.h>
+
+// TODO: Use actual socket types (stream etc)
+enum socket_type { S_TCP, S_UDP };
+enum socket_state { S_CONNECTING, S_CONNECTED, S_OPEN, S_CLOSED, S_FAILED };
+
+struct tcp_socket {
+	u32 seq_no;
+	u32 ack_no;
+	u32 state;
+};
+
+struct socket {
+	u32 ip_addr;
+	u32 dst_port;
+	u32 src_port;
+	enum socket_state state;
+	enum socket_type type;
+	u32 bytes_available;
+	u32 bytes_read;
+	void *current_packet;
+	union {
+		struct tcp_socket tcp;
+		/* struct udp_socket udp; */
+	} prot;
+};
+
+#endif
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index 86f530b..4e52ac1 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -21,7 +21,11 @@ enum sys {
 	SYS_UNREGISTER, // Unregister event
 	SYS_SEND, // Send message to process
 	SYS_RECEIVE, // Receive message (non-blocking/sync)
-	SYS_GETPID // Get the process ID
+	SYS_GETPID, // Get the process ID
+	SYS_NET_OPEN, // Open network socket
+	SYS_NET_CLOSE, // Close network socket
+	SYS_NET_CONNECT, // Connect to destination
+	SYS_NET_SEND, // Send to socket
 };
 
 enum event_type { EVENT_KEYBOARD, EVENT_MOUSE, EVENT_MAX };
-- 
cgit v1.2.3