mirror of
https://github.com/RGBCube/serenity
synced 2025-07-08 17:27:35 +00:00
LibC: Add socket(), bind(), listen(), accept() and connect().
This commit is contained in:
parent
54b1d6f57f
commit
a63e8839da
4 changed files with 84 additions and 0 deletions
38
LibC/sys/socket.cpp
Normal file
38
LibC/sys/socket.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
int socket(int domain, int type, int protocol)
|
||||
{
|
||||
int rc = syscall(SC_socket, domain, type, protocol);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int bind(int sockfd, const sockaddr* addr, socklen_t addrlen)
|
||||
{
|
||||
int rc = syscall(SC_bind, sockfd, addr, addrlen);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int listen(int sockfd, int backlog)
|
||||
{
|
||||
int rc = syscall(SC_listen, sockfd, backlog);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int accept(int sockfd, sockaddr* addr, socklen_t* addrlen)
|
||||
{
|
||||
int rc = syscall(SC_accept, sockfd, addr, addrlen);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int connect(int sockfd, const sockaddr* addr, socklen_t addrlen)
|
||||
{
|
||||
int rc = syscall(SC_connect, sockfd, addr, addrlen);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue