// SendTo(u32 socket, u32 flags, buffer<i8, 0x21, 0>, buffer<nn::socket::sockaddr_in, 0x21, 0x10>) -> (i32 ret, u32 bsd_errno) public ResultCode SendTo(ServiceCtx context) { int socketFd = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); (ulong sendPosition, ulong sendSize) = context.Request.GetBufferType0x21(0); (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21(1); ReadOnlySpan <byte> sendBuffer = context.Memory.GetSpan(sendPosition, (int)sendSize); LinuxError errno = LinuxError.EBADF; ISocket socket = _context.RetrieveSocket(socketFd); int result = -1; if (socket != null) { IPEndPoint endPoint = context.Memory.Read <BsdSockAddr>(bufferPosition).ToIPEndPoint(); errno = socket.SendTo(out result, sendBuffer, sendBuffer.Length, socketFlags, endPoint); if (errno == LinuxError.SUCCESS) { SetResultErrno(socket, result); } } return(WriteBsdResult(context, result, errno)); }
// RecvFrom(u32 sock, u32 flags) -> (i32 ret, u32 bsd_errno, u32 addrlen, buffer<i8, 0x22, 0> message, buffer<nn::socket::sockaddr_in, 0x22, 0x10>) public ResultCode RecvFrom(ServiceCtx context) { int socketFd = context.RequestData.ReadInt32(); BsdSocketFlags socketFlags = (BsdSocketFlags)context.RequestData.ReadInt32(); (ulong receivePosition, ulong receiveLength) = context.Request.GetBufferType0x22(0); (ulong sockAddrOutPosition, ulong sockAddrOutSize) = context.Request.GetBufferType0x22(1); WritableRegion receiveRegion = context.Memory.GetWritableRegion(receivePosition, (int)receiveLength); LinuxError errno = LinuxError.EBADF; ISocket socket = _context.RetrieveSocket(socketFd); int result = -1; if (socket != null) { errno = socket.ReceiveFrom(out result, receiveRegion.Memory.Span, receiveRegion.Memory.Span.Length, socketFlags, out IPEndPoint endPoint); if (errno == LinuxError.SUCCESS) { SetResultErrno(socket, result); receiveRegion.Dispose(); context.Memory.Write(sockAddrOutPosition, BsdSockAddr.FromIPEndPoint(endPoint)); } } return(WriteBsdResult(context, result, errno)); }