From 8b91b7acc00007374b6beca37c5caa7609ba1b06 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 28 Jul 2023 17:30:59 +0200 Subject: [PATCH] libc: Add wrappers for listen(), connect(), and accept() --- libc/include/sys/socket.h | 9 +++++++++ libc/src/sys/socket.cpp | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h index 5183e974..07f918dd 100644 --- a/libc/include/sys/socket.h +++ b/libc/include/sys/socket.h @@ -16,6 +16,15 @@ extern "C" /* Bind a socket to an address. */ int bind(int sockfd, struct sockaddr* addr, socklen_t addrlen); + /* Connect a socket to a remote address. */ + int connect(int sockfd, struct sockaddr* addr, socklen_t addrlen); + + /* Start listening on a socket. */ + int listen(int sockfd, int backlog); + + /* Wait for an incoming connection on a socket. */ + int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen); + #ifdef __cplusplus } #endif diff --git a/libc/src/sys/socket.cpp b/libc/src/sys/socket.cpp index 686d4da7..1f8432a4 100644 --- a/libc/src/sys/socket.cpp +++ b/libc/src/sys/socket.cpp @@ -16,4 +16,22 @@ extern "C" long rc = syscall(SYS_bind, sockfd, addr, addrlen); __errno_return(rc, int); } + + int connect(int sockfd, struct sockaddr* addr, socklen_t addrlen) + { + long rc = syscall(SYS_connect, sockfd, addr, addrlen); + __errno_return(rc, int); + } + + int listen(int sockfd, int backlog) + { + long rc = syscall(SYS_listen, sockfd, backlog); + __errno_return(rc, int); + } + + int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen) + { + long rc = syscall(SYS_accept, sockfd, addr, addrlen); + __errno_return(rc, int); + } }