2024-02-01 23:39:09 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2024-02-07 02:12:42 +02:00
|
|
|
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
|
|
|
{
|
|
|
|
return syscall(SYS_ACCEPT, socket, address, address_len);
|
|
|
|
}
|
|
|
|
|
2024-02-02 01:31:58 +02:00
|
|
|
int bind(int socket, const struct sockaddr* address, socklen_t address_len)
|
|
|
|
{
|
|
|
|
return syscall(SYS_BIND, socket, address, address_len);
|
|
|
|
}
|
|
|
|
|
2024-02-07 02:12:42 +02:00
|
|
|
int connect(int socket, const struct sockaddr* address, socklen_t address_len)
|
|
|
|
{
|
|
|
|
return syscall(SYS_CONNECT, socket, address, address_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
int listen(int socket, int backlog)
|
|
|
|
{
|
|
|
|
return syscall(SYS_LISTEN, socket, backlog);
|
|
|
|
}
|
|
|
|
|
2024-02-07 02:13:21 +02:00
|
|
|
ssize_t recv(int socket, void* __restrict buffer, size_t length, int flags)
|
2024-02-07 02:12:42 +02:00
|
|
|
{
|
|
|
|
return recvfrom(socket, buffer, length, flags, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2024-02-02 13:50:00 +02:00
|
|
|
ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
|
|
|
{
|
|
|
|
sys_recvfrom_t arguments {
|
|
|
|
.socket = socket,
|
|
|
|
.buffer = buffer,
|
|
|
|
.length = length,
|
|
|
|
.flags = flags,
|
|
|
|
.address = address,
|
|
|
|
.address_len = address_len
|
|
|
|
};
|
|
|
|
return syscall(SYS_RECVFROM, &arguments);
|
|
|
|
}
|
|
|
|
|
2024-02-07 02:12:42 +02:00
|
|
|
ssize_t send(int socket, const void* message, size_t length, int flags)
|
|
|
|
{
|
|
|
|
return sendto(socket, message, length, flags, nullptr, 0);
|
|
|
|
}
|
2024-02-02 13:50:00 +02:00
|
|
|
|
2024-02-02 03:16:01 +02:00
|
|
|
ssize_t sendto(int socket, const void* message, size_t length, int flags, const struct sockaddr* dest_addr, socklen_t dest_len)
|
|
|
|
{
|
|
|
|
sys_sendto_t arguments {
|
|
|
|
.socket = socket,
|
|
|
|
.message = message,
|
|
|
|
.length = length,
|
|
|
|
.flags = flags,
|
|
|
|
.dest_addr = dest_addr,
|
|
|
|
.dest_len = dest_len
|
|
|
|
};
|
|
|
|
return syscall(SYS_SENDTO, &arguments);
|
|
|
|
}
|
|
|
|
|
2024-02-01 23:39:09 +02:00
|
|
|
int socket(int domain, int type, int protocol)
|
|
|
|
{
|
|
|
|
return syscall(SYS_SOCKET, domain, type, protocol);
|
|
|
|
}
|