diff options
author | Anton Kling <anton@kling.gg> | 2024-04-29 22:00:55 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-04-29 22:00:55 +0200 |
commit | 231301a6190605bd3ced4d961ee0d5d3fcd49d65 (patch) | |
tree | 8af67c28f9b638393f700fbaf2c9e33fd97a8b46 /userland/libc | |
parent | 7d2ab3a71f4bda9d8ee997764d98b29e13a902c5 (diff) |
Kernel/IRC: Add setsockopt and move IRC client to use new socket interface
Diffstat (limited to 'userland/libc')
-rw-r--r-- | userland/libc/Makefile | 2 | ||||
-rw-r--r-- | userland/libc/include/socket.h | 57 | ||||
-rw-r--r-- | userland/libc/include/sys/socket.h | 11 | ||||
-rw-r--r-- | userland/libc/include/syscall.h | 3 | ||||
-rw-r--r-- | userland/libc/sys/socket/connect.c | 6 | ||||
-rw-r--r-- | userland/libc/sys/socket/setsockopt.c | 8 | ||||
-rw-r--r-- | userland/libc/unistd/lseek.c | 7 |
7 files changed, 24 insertions, 70 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index af65a56..2d301cb 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 -O0 -Wall -Wextra -pedantic -Werror -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.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 signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.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 signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o fcntl/open_process.o tb/sb.o tb/sv.o string/memchr.o stdlib/atol.o stdlib/atoll.o stdlib/strtoll.o sys/stat/fstat.o unistd/lseek.o ctype/isupper.o ctype/islower.o ctype/isblank.o ctype/isgraph.o ctype/iscntrl.o math/ldexp.o sys/socket/connect.o sys/socket/setsockopt.o all: libc.a %.o: %.c diff --git a/userland/libc/include/socket.h b/userland/libc/include/socket.h deleted file mode 100644 index bee592b..0000000 --- a/userland/libc/include/socket.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef SOCKET_H -#define SOCKET_H -#include <stddef.h> -#include <stdint.h> - -#define AF_UNIX 0 -#define AF_INET 1 -#define AF_LOCAL AF_UNIX - -#define SOCK_DGRAM 0 -#define SOCK_STREAM 1 - -#define INADDR_ANY 0 - -typedef struct { - int domain; - int type; - int protocol; - - // UNIX socket - char *path; - int incoming_fd; -} SOCKET; - -typedef struct { - char *path; - SOCKET *s; -} OPEN_UNIX_SOCKET; - -typedef uint32_t in_addr_t; -typedef uint16_t in_port_t; -typedef unsigned int sa_family_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; - uint8_t a[4]; - } sin_addr; - uint16_t sin_port; -}; - -struct sockaddr_un { - sa_family_t sun_family; /* Address family */ - char *sun_path; /* Socket pathname */ -}; - -int socket(int domain, int type, int protocol); -int accept(int socket, struct sockaddr *address, socklen_t *address_len); -int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); -#endif // SOCKET_H diff --git a/userland/libc/include/sys/socket.h b/userland/libc/include/sys/socket.h deleted file mode 100644 index fb874a1..0000000 --- a/userland/libc/include/sys/socket.h +++ /dev/null @@ -1,11 +0,0 @@ -#include <socket.h> -#include <stddef.h> - -#define MSG_WAITALL 1 - -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); -int listen(int socket, int backlog); -int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h index f318955..dcc4742 100644 --- a/userland/libc/include/syscall.h +++ b/userland/libc/include/syscall.h @@ -1,8 +1,8 @@ #ifndef SYSCALL_H #define SYSCALL_H -#include "socket.h" #include <stddef.h> #include <stdint.h> +#include <sys/socket.h> #include <sys/types.h> #define SYS_OPEN 0 @@ -60,6 +60,7 @@ #define SYS_OPEN_PROCESS 49 #define SYS_LSEEK 50 #define SYS_CONNECT 51 +#define SYS_SETSOCKOPT 52 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/connect.c b/userland/libc/sys/socket/connect.c new file mode 100644 index 0000000..9b692ef --- /dev/null +++ b/userland/libc/sys/socket/connect.c @@ -0,0 +1,6 @@ +#include <sys/socket.h> +#include <syscall.h> + +int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { + RC_ERRNO(syscall(SYS_CONNECT, sockfd, addr, addrlen, 0, 0)); +} diff --git a/userland/libc/sys/socket/setsockopt.c b/userland/libc/sys/socket/setsockopt.c new file mode 100644 index 0000000..3fa69d6 --- /dev/null +++ b/userland/libc/sys/socket/setsockopt.c @@ -0,0 +1,8 @@ +#include <sys/socket.h> +#include <syscall.h> + +int setsockopt(int socket, int level, int option_name, const void *option_value, + socklen_t option_len) { + RC_ERRNO(syscall(SYS_SETSOCKOPT, socket, level, option_name, option_value, + option_len)); +} diff --git a/userland/libc/unistd/lseek.c b/userland/libc/unistd/lseek.c new file mode 100644 index 0000000..2dcd661 --- /dev/null +++ b/userland/libc/unistd/lseek.c @@ -0,0 +1,7 @@ +#include <errno.h> +#include <unistd.h> +#include <syscall.h> + +off_t lseek(int fildes, off_t offset, int whence) { + RC_ERRNO(syscall(SYS_LSEEK, (u32)fildes, offset, whence, 0, 0)); +} |