wutsocket: implement missing functions

This commit is contained in:
GaryOderNichts
2021-02-09 17:22:24 +01:00
committed by fincs
parent efc1bd47ff
commit f1e9cbd58a
11 changed files with 446 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#include "wut_socket.h"
#include <nsysnet/_netdb.h>
#include <netdb.h>
int
getaddrinfo(const char *node,
const char *service,
const struct addrinfo *hints,
struct addrinfo **res)
{
int rc;
if (!node && !service) {
return EAI_NONAME;
}
if (!res) {
errno = EINVAL;
return EAI_SYSTEM;
}
rc = RPLWRAP(getaddrinfo)(node, service, hints, res);
return rc;
}
void
freeaddrinfo(struct addrinfo *res)
{
RPLWRAP(freeaddrinfo)(res);
}
int
getnameinfo(const struct sockaddr *addr,
socklen_t addrlen,
char *host,
socklen_t hostlen,
char *serv,
socklen_t servlen,
int flags)
{
int rc;
rc = RPLWRAP(getnameinfo)(addr, addrlen, host, hostlen, serv, servlen, flags);
return rc;
}
const char *
gai_strerror(int ecode)
{
return RPLWRAP(gai_strerror)(ecode);
}

View File

@@ -0,0 +1,40 @@
#include "wut_socket.h"
#include <netdb.h>
#include <nsysnet/_netdb.h>
struct hostent *
gethostbyaddr(const void *addr,
socklen_t len,
int type)
{
if (!addr || !len) {
h_errno = HOST_NOT_FOUND;
return NULL;
}
if (type != AF_INET) {
h_errno = HOST_NOT_FOUND;
return NULL;
}
struct hostent *ent = RPLWRAP(gethostbyaddr)(addr, len, type);
h_errno = *RPLWRAP(get_h_errno)();
return ent;
}
struct hostent *
gethostbyname(const char *name)
{
if (!name) {
h_errno = HOST_NOT_FOUND;
return NULL;
}
struct hostent *ent = RPLWRAP(gethostbyname)(name);
h_errno = *RPLWRAP(get_h_errno)();
return ent;
}

View File

@@ -0,0 +1,60 @@
#include "wut_socket.h"
#include <sys/ioctl.h>
int
ioctl(int fd,
int request,
...)
{
void *data;
va_list args;
int sockfd;
int rc;
va_start(args, request);
data = (request & IOC_INOUT) ? va_arg(args, void *) : NULL;
va_end(args);
if(data == NULL && (request & IOC_INOUT) && IOCPARM_LEN(request) != 0) {
errno = EFAULT;
return -1;
}
sockfd = __wut_get_nsysnet_fd(fd);
if (sockfd == -1) {
return -1;
}
switch(request) {
case FIONBIO: {
int flags = fcntl(fd, F_GETFL, 0);
if(flags == -1) {
return -1;
}
flags = *(int *)data != 0 ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
return fcntl(fd, F_SETFL, flags);
}
case FIONREAD: {
socklen_t optlen = sizeof(int32_t);
rc = RPLWRAP(getsockopt)(sockfd,
SOL_SOCKET,
SO_RXDATA,
data,
&optlen);
return __wut_get_nsysnet_result(NULL, rc);
}
case FIONWRITE: {
socklen_t optlen = sizeof(int32_t);
rc = RPLWRAP(getsockopt)(sockfd,
SOL_SOCKET,
SO_TXDATA,
data,
&optlen);
return __wut_get_nsysnet_result(NULL, rc);
}
default:
break;
}
return -1;
}

View File

@@ -0,0 +1,36 @@
#include "wut_socket.h"
#include <netdb.h>
struct servent *
getservbyname(const char *name,
const char *proto)
{
h_errno = NO_RECOVERY;
errno = ENOSYS;
return NULL;
}
struct servent *
getservbyport(int port,
const char *proto)
{
h_errno = NO_RECOVERY;
errno = ENOSYS;
return NULL;
}
struct servent *
getservent(void)
{
h_errno = NO_RECOVERY;
errno = ENOSYS;
return NULL;
}
struct hostent *
gethostent(void)
{
h_errno = NO_RECOVERY;
errno = ENOSYS;
return NULL;
}

View File

@@ -2,6 +2,8 @@
#define NSYSNET_UNKNOWN_ERROR_OFFSET 10000
int h_errno;
static BOOL
__wut_socket_initialised = FALSE;