2021-01-18 23:04:07 +01:00
|
|
|
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */
|
|
|
|
|
2020-12-03 18:27:05 +01:00
|
|
|
#include <net/socket.h>
|
|
|
|
|
|
|
|
int socket(int domain, int type, int protocol)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int close(int socket)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(1), "c"(socket)
|
|
|
|
);
|
|
|
|
}
|
2021-01-04 21:24:35 +01:00
|
|
|
int bind(int socket, const struct sockaddr *addres, int addres_len)
|
2020-12-03 18:27:05 +01:00
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int listen(int socket, int backlog)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-04 21:24:35 +01:00
|
|
|
int connect(int socket,const struct sockaddr* address, int socket_len)
|
2020-12-03 18:27:05 +01:00
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-04 21:24:35 +01:00
|
|
|
int accept(int socket, const struct sockaddr *address, int address_len)
|
2020-12-03 18:27:05 +01:00
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int send(int socket, const void *message, size_t msg_len, int flag)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int recv(int socket, void *buffer, size_t buff_len, int flag)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int setsockopt(int socket,const optstruct* opt)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(8), "c"(socket),"d"(opt)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
int getsockopt(int socket, optstruct* opt)
|
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2021-01-15 22:48:24 +01:00
|
|
|
:"=b"(errno)
|
2020-12-03 18:27:05 +01:00
|
|
|
:"a"(75), "b"(9), "c"(socket),"d"(opt)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-08 19:36:23 +01:00
|
|
|
int socketpair(int *sock1, int *sock2)
|
2020-12-03 18:27:05 +01:00
|
|
|
{
|
|
|
|
asm volatile(
|
|
|
|
"int $0x40"
|
2020-12-08 19:36:23 +01:00
|
|
|
:"=b"(*sock2), "=a"(*sock1)
|
2020-12-04 07:40:20 +01:00
|
|
|
:"a"(75), "b"(10)
|
2020-12-08 19:36:23 +01:00
|
|
|
);
|
2021-01-15 22:48:24 +01:00
|
|
|
errno = *sock2;
|
2020-12-08 19:36:23 +01:00
|
|
|
return *sock1;
|
2020-12-03 18:27:05 +01:00
|
|
|
}
|