File network.cpp

namespace wasm

SYSCALL NUMBERING

Have a look in the sysroot at include/bits/syscall.h to determine the system call numbering.

Functions

void setSockAddr(sockaddr nativeSockAddr, I32 addrPtr)

Writes changes to a native sockaddr back to a wasm sockaddr. This is important in several networking syscalls that receive responses and modify arguments in place

void setSockLen(socklen_t nativeValue, I32 wasmPtr)
I32 s__socketcall(I32 call, I32 argsPtr)

When properly isolated, functions will run in their own network namespace, therefore we can be relatively comfortable passing some of the syscalls straight through.

WAVM_DEFINE_INTRINSIC_FUNCTION (env, "gethostbyname", I32, _gethostbyname, I32 hostnamePtr)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "gethostname", I32, gethostname, I32 buffer, I32 bufferLen)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "socket", I32, socket, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "sock_accept", I32, sock_accept, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "sock_send", I32, wasi_sock_send, I32 a, I32 b, I32 c, I32 d, I32 e)
WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "sock_recv", I32, wasi_sock_recv, I32 a, I32 b, I32 c, I32 d, I32 e, I32 f)
WAVM_DEFINE_INTRINSIC_FUNCTION (wasi, "sock_shutdown", I32, wasi_sock_shutdown, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "bind", I32, bind, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "listen", I32, listen, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "setsockopt", I32, setsockopt, I32 a, I32 b, I32 c, I32 d, I32 e)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "accept", I32, accept, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "inet_addr", I32, inet_addr, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "connect", I32, connect, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "recvfrom", I32, recvfrom, I32 a, I32 b, I32 c, I32 d, I32 e, I32 f)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "sendto", I32, sendto, I32 a, I32 b, I32 c, I32 d, I32 e, I32 f)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "inet_ntoa", I32, inet_ntoa, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "getprotobyname", I32, getprotobyname, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "getservbyname", I32, s__getservbyname, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "gethostbyaddr", I32, s__gethostbyaddr, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "getservbyport", I32, s__getservbyport, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "getsockname", I32, s__getsockname, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "atoi", I32, atoi, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "htons", I32, _htons, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "ntohl", I32, _ntohl, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "ntohs", I32, _ntohs, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "htonl", I32, _htonl, I32 a)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "inet_aton", I32, _inet_aton, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "shutdown", I32, _shutdown, I32 a, I32 b)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "inet_pton", I32, _inet_pton, I32 a, I32 b, I32 c)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "inet_ntop", I32, _inet_ntop, I32 a, I32 b, I32 c, I32 d)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "recv", I32, _recv, I32 a, I32 b, I32 c, I32 d)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "send", I32, _send, I32 a, I32 b, I32 c, I32 d)
WAVM_DEFINE_INTRINSIC_FUNCTION (env, "getsockopt", I32, getsockopt, I32 a, I32 b, I32 c, I32 d, I32 e)
void networkLink()