From 5026f823fa2708404302aa59d03401635a435c0b Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 27 Oct 2023 00:48:21 +0200 Subject: Kernel/Networking/LibC: Add syscalls and libc functions for UDP This allows a UDP server to be created in userland and read data. Currently it can't send data and is very very simplistic. Code is horrible and probably needs some fixing until it can be further built upon. --- socket.h | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'socket.h') diff --git a/socket.h b/socket.h index debe29d..168386e 100644 --- a/socket.h +++ b/socket.h @@ -1,34 +1,23 @@ #ifndef SOCKET_H #define SOCKET_H -#include "fs/vfs.h" +#include +#include #include #include -/* -// Create a directory with the proper permissions -mkdir(path, 0700); -// Append the name of the socket -strcat(path, "/socket_name"); - -// Create the socket normally -sockaddr_un address; -address.sun_family = AF_UNIX; -strcpy(address.sun_path, path); -int fd = socket(AF_UNIX, SOCK_STREAM, 0); -bind(fd, (sockaddr*)(&address), sizeof(address)); -listen(fd, 100); -*/ - #define AF_UNIX 0 +#define AF_INET 1 #define AF_LOCAL AF_UNIX +#define SOCK_DGRAM 0 + #define INADDR_ANY 0 -typedef struct { - int fifo_fd; - vfs_fd_t *ptr_fifo_fd; +#define MSG_WAITALL 1 +typedef struct { vfs_fd_t *ptr_socket_fd; + FIFO_FILE *fifo_file; int domain; int type; @@ -44,21 +33,36 @@ typedef struct { SOCKET *s; } OPEN_UNIX_SOCKET; +typedef struct { + uint32_t address; + uint16_t port; + SOCKET *s; +} OPEN_INET_SOCKET; + typedef uint32_t in_addr_t; typedef uint16_t in_port_t; typedef unsigned int sa_family_t; -typedef uint32_t socklen_t; +typedef int socklen_t; struct sockaddr { sa_family_t sa_family; /* Address family */ char *sa_data; /* Socket address */ }; +struct sockaddr_in { + sa_family_t sin_family; + union { + uint32_t s_addr; + } sin_addr; + uint16_t sin_port; +}; + struct sockaddr_un { sa_family_t sun_family; /* Address family */ char *sun_path; /* Socket pathname */ }; +OPEN_INET_SOCKET *find_open_udp_port(uint16_t port); int uds_open(const char *path); int socket(int domain, int type, int protocol); int accept(int socket, struct sockaddr *address, socklen_t *address_len); -- cgit v1.2.3