mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibC: Add socket(), bind(), listen(), accept() and connect().
This commit is contained in:
parent
54b1d6f57f
commit
a63e8839da
Notes:
sideshowbarker
2024-07-19 15:43:07 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a63e8839da4
4 changed files with 84 additions and 0 deletions
|
@ -201,6 +201,16 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
|
|||
return current->sys$rmdir((const char*)arg1);
|
||||
case Syscall::SC_chmod:
|
||||
return current->sys$chmod((const char*)arg1, (mode_t)arg2);
|
||||
case Syscall::SC_socket:
|
||||
return current->sys$socket((int)arg1, (int)arg2, (int)arg3);
|
||||
case Syscall::SC_bind:
|
||||
return current->sys$bind((int)arg1, (const sockaddr*)arg2, (socklen_t)arg3);
|
||||
case Syscall::SC_listen:
|
||||
return current->sys$listen((int)arg1, (int)arg2);
|
||||
case Syscall::SC_accept:
|
||||
return current->sys$accept((int)arg1, (sockaddr*)arg2, (socklen_t*)arg3);
|
||||
case Syscall::SC_connect:
|
||||
return current->sys$connect((int)arg1, (const sockaddr*)arg2, (socklen_t)arg3);
|
||||
default:
|
||||
kprintf("<%u> int0x80: Unknown function %u requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
|
||||
break;
|
||||
|
|
|
@ -42,6 +42,7 @@ LIBC_OBJS = \
|
|||
math.o \
|
||||
utime.o \
|
||||
sys/select.o \
|
||||
sys/socket.o \
|
||||
poll.o \
|
||||
locale.o \
|
||||
entry.o
|
||||
|
|
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
35
LibC/sys/socket.h
Normal file
35
LibC/sys/socket.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define AF_MASK 0xff
|
||||
#define AF_UNSPEC 0
|
||||
#define AF_LOCAL 1
|
||||
|
||||
#define SOCK_TYPE_MASK 0xff
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_NONBLOCK 04000
|
||||
#define SOCK_CLOEXEC 02000000
|
||||
|
||||
struct sockaddr {
|
||||
unsigned short sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
#define UNIX_PATH_MAX 108
|
||||
struct sockaddr_un {
|
||||
unsigned short sun_family;
|
||||
char sun_path[UNIX_PATH_MAX];
|
||||
};
|
||||
|
||||
int socket(int domain, int type, int protocol);
|
||||
int bind(int sockfd, const sockaddr* addr, socklen_t);
|
||||
int listen(int sockfd, int backlog);
|
||||
int accept(int sockfd, sockaddr*, socklen_t*);
|
||||
int connect(int sockfd, const sockaddr*, socklen_t);
|
||||
|
||||
__END_DECLS
|
||||
|
Loading…
Reference in a new issue