summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-27 22:17:24 +0200
committerAnton Kling <anton@kling.gg>2023-10-30 21:49:48 +0100
commitd50d18c9da3a125f0196bec89802dec1c5b0b800 (patch)
treed9a4e74906c5ab51708d148ad3728cc155a9893d /userland
parent4f9ed7087cb58683d9423ab771ad76b31dac5514 (diff)
Kernel/LibC/Networking: Be able to send UDP messages
Now it can send UDP messages to a specific IP address and libc has enough to create a basic UDP ECHO server, that is kinda cool.
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/Makefile2
-rw-r--r--userland/libc/include/sys/socket.h2
-rw-r--r--userland/libc/include/syscall.h1
-rw-r--r--userland/libc/sys/socket/recvfrom.c17
-rw-r--r--userland/libc/sys/socket/sendto.c16
5 files changed, 37 insertions, 1 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile
index 02f5584..bcb82f8 100644
--- a/userland/libc/Makefile
+++ b/userland/libc/Makefile
@@ -2,7 +2,7 @@ CC="i686-sb-gcc"
AR="i686-sb-ar"
AS="i686-sb-as"
CFLAGS = -ggdb -ffreestanding -O2 -Wall -pedantic -Wimplicit-fallthrough -I./include/ -static
-OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o
+OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o
all: libc.a
%.o: %.c
diff --git a/userland/libc/include/sys/socket.h b/userland/libc/include/sys/socket.h
index 18402d0..c4f10e2 100644
--- a/userland/libc/include/sys/socket.h
+++ b/userland/libc/include/sys/socket.h
@@ -5,3 +5,5 @@
size_t recvfrom(int socket, void *buffer, size_t length, int flags,
struct sockaddr *address, socklen_t *address_len);
+size_t sendto(int socket, const void *message, size_t length, int flags,
+ const struct sockaddr *dest_addr, socklen_t dest_len);
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index 7d84b8f..3af425d 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -33,6 +33,7 @@
#define SYS_UPTIME 25
#define SYS_MKDIR 26
#define SYS_RECVFROM 27
+#define SYS_SENDTO 28
int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
uint32_t esi, uint32_t edi);
diff --git a/userland/libc/sys/socket/recvfrom.c b/userland/libc/sys/socket/recvfrom.c
new file mode 100644
index 0000000..5bbfeea
--- /dev/null
+++ b/userland/libc/sys/socket/recvfrom.c
@@ -0,0 +1,17 @@
+#include <assert.h>
+#include <sys/socket.h>
+#include <syscall.h>
+
+struct two_args {
+ uint32_t a;
+ uint32_t b;
+};
+
+size_t recvfrom(int socket, void *buffer, size_t length, int flags,
+ struct sockaddr *address, socklen_t *address_len) {
+ struct two_args extra_args;
+ extra_args.a = address;
+ extra_args.b = address_len;
+
+ return syscall(SYS_RECVFROM, socket, buffer, length, flags, &extra_args);
+}
diff --git a/userland/libc/sys/socket/sendto.c b/userland/libc/sys/socket/sendto.c
new file mode 100644
index 0000000..73437ab
--- /dev/null
+++ b/userland/libc/sys/socket/sendto.c
@@ -0,0 +1,16 @@
+#include <sys/socket.h>
+#include <syscall.h>
+
+struct two_args {
+ uint32_t a;
+ uint32_t b;
+};
+
+size_t sendto(int socket, const void *message, size_t length, int flags,
+ const struct sockaddr *dest_addr, socklen_t dest_len) {
+ struct two_args extra = {
+ .a = dest_addr,
+ .b = dest_len,
+ };
+ return syscall(SYS_SENDTO, socket, message, length, flags, &extra);
+}