コード例 #1
0
        // Read(u32 socket) -> (i32 ret, u32 bsd_errno, buffer<i8, 0x22, 0> message)
        public long Read(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();

            (long ReceivePosition, long ReceiveLength) = Context.Request.GetBufferType0x22();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);
            int        Result = -1;

            if (Socket != null)
            {
                byte[] ReceivedBuffer = new byte[ReceiveLength];

                try
                {
                    Result = Socket.Handle.Receive(ReceivedBuffer);
                    Errno  = SetResultErrno(Socket.Handle, Result);
                }
                catch (SocketException Exception)
                {
                    Errno = ConvertError((WSAError)Exception.ErrorCode);
                }
            }

            return(WriteBsdResult(Context, Result, Errno));
        }
コード例 #2
0
        // Write(u32 socket, buffer<i8, 0x21, 0> message) -> (i32 ret, u32 bsd_errno)
        public long Write(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();

            (long SendPosition, long SendSize) = Context.Request.GetBufferType0x21();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);
            int        Result = -1;

            if (Socket != null)
            {
                byte[] SendBuffer = Context.Memory.ReadBytes(SendPosition, SendSize);

                try
                {
                    Result = Socket.Handle.Send(SendBuffer);
                    Errno  = SetResultErrno(Socket.Handle, Result);
                }
                catch (SocketException Exception)
                {
                    Errno = ConvertError((WSAError)Exception.ErrorCode);
                }
            }

            return(WriteBsdResult(Context, Result, Errno));
        }
コード例 #3
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // Write(u32 socket, buffer<i8, 0x21, 0> message) -> (i32 ret, u32 bsd_errno)
        public ResultCode Write(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();

            (long sendPosition, long sendSize) = context.Request.GetBufferType0x21();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);
            int        result = -1;

            if (socket != null)
            {
                byte[] sendBuffer = new byte[sendSize];

                context.Memory.Read((ulong)sendPosition, sendBuffer);

                try
                {
                    result = socket.Handle.Send(sendBuffer);
                    errno  = SetResultErrno(socket.Handle, result);
                }
                catch (SocketException exception)
                {
                    errno = ConvertError((WsaError)exception.ErrorCode);
                }
            }

            return(WriteBsdResult(context, result, errno));
        }
コード例 #4
0
        // Shutdown(u32 socket, u32 how) -> (i32 ret, u32 bsd_errno)
        public long Shutdown(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();
            int How      = Context.RequestData.ReadInt32();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                Errno = LinuxError.EINVAL;

                if (How >= 0 && How <= 2)
                {
                    Errno = LinuxError.SUCCESS;

                    try
                    {
                        Socket.Handle.Shutdown((SocketShutdown)How);
                    }
                    catch (SocketException Exception)
                    {
                        Errno = ConvertError((WSAError)Exception.ErrorCode);
                    }
                }
            }

            return(WriteBsdResult(Context, 0, Errno));
        }
コード例 #5
0
        // ShutdownAllSockets(u32 how) -> (i32 ret, u32 bsd_errno)
        public long ShutdownAllSockets(ServiceCtx Context)
        {
            int How = Context.RequestData.ReadInt32();

            LinuxError Errno = LinuxError.EINVAL;

            if (How >= 0 && How <= 2)
            {
                Errno = LinuxError.SUCCESS;

                foreach (BsdSocket Socket in Sockets)
                {
                    if (Socket != null)
                    {
                        try
                        {
                            Socket.Handle.Shutdown((SocketShutdown)How);
                        }
                        catch (SocketException Exception)
                        {
                            Errno = ConvertError((WSAError)Exception.ErrorCode);
                            break;
                        }
                    }
                }
            }

            return(WriteBsdResult(Context, 0, Errno));
        }
コード例 #6
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // Connect(u32 socket, buffer<nn::socket::sockaddr_in, 0x21, 0x10>) -> (i32 ret, u32 bsd_errno)
        public ResultCode Connect(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();

            (long bufferPos, long bufferSize) = context.Request.GetBufferType0x21();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                errno = LinuxError.SUCCESS;
                try
                {
                    IPEndPoint endPoint = ParseSockAddr(context, bufferPos, bufferSize);

                    socket.Handle.Connect(endPoint);
                }
                catch (SocketException exception)
                {
                    errno = ConvertError((WsaError)exception.ErrorCode);
                }
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #7
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // Ioctl(u32 fd, u32 request, u32 bufcount, buffer<unknown, 0x21, 0>, buffer<unknown, 0x21, 0>, buffer<unknown, 0x21, 0>, buffer<unknown, 0x21, 0>) -> (i32 ret, u32 bsd_errno, buffer<unknown, 0x22, 0>, buffer<unknown, 0x22, 0>, buffer<unknown, 0x22, 0>, buffer<unknown, 0x22, 0>)
        public ResultCode Ioctl(ServiceCtx context)
        {
            int      socketFd    = context.RequestData.ReadInt32();
            BsdIoctl cmd         = (BsdIoctl)context.RequestData.ReadInt32();
            int      bufferCount = context.RequestData.ReadInt32();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                switch (cmd)
                {
                case BsdIoctl.AtMark:
                    errno = LinuxError.SUCCESS;

                    (long bufferPosition, long bufferSize) = context.Request.GetBufferType0x22();

                    // FIXME: OOB not implemented.
                    context.Memory.Write((ulong)bufferPosition, 0);
                    break;

                default:
                    errno = LinuxError.EOPNOTSUPP;

                    Logger.Warning?.Print(LogClass.ServiceBsd, $"Unsupported Ioctl Cmd: {cmd}");
                    break;
                }
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #8
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // Fcntl(u32 socket, u32 cmd, u32 arg) -> (i32 ret, u32 bsd_errno)
        public ResultCode Fcntl(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();
            int cmd      = context.RequestData.ReadInt32();
            int arg      = context.RequestData.ReadInt32();

            int        result = 0;
            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                errno = LinuxError.SUCCESS;

                if (cmd == 0x3)
                {
                    result = !socket.Handle.Blocking ? 0x800 : 0;
                }
                else if (cmd == 0x4 && arg == 0x800)
                {
                    socket.Handle.Blocking = false;
                    result = 0;
                }
                else
                {
                    errno = LinuxError.EOPNOTSUPP;
                }
            }

            return(WriteBsdResult(context, result, errno));
        }
コード例 #9
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // Shutdown(u32 socket, u32 how) -> (i32 ret, u32 bsd_errno)
        public ResultCode Shutdown(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();
            int how      = context.RequestData.ReadInt32();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                errno = LinuxError.EINVAL;

                if (how >= 0 && how <= 2)
                {
                    errno = LinuxError.SUCCESS;

                    try
                    {
                        socket.Handle.Shutdown((SocketShutdown)how);
                    }
                    catch (SocketException exception)
                    {
                        errno = ConvertError((WsaError)exception.ErrorCode);
                    }
                }
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #10
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // GetSockOpt(u32 socket, u32 level, u32 option_name) -> (i32 ret, u32 bsd_errno, u32, buffer<unknown, 0x22, 0>)
        public ResultCode GetSockOpt(ServiceCtx context)
        {
            int socketFd   = context.RequestData.ReadInt32();
            int level      = context.RequestData.ReadInt32();
            int optionName = context.RequestData.ReadInt32();

            (long bufferPosition, long bufferSize) = context.Request.GetBufferType0x22();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                errno = LinuxError.ENOPROTOOPT;

                if (level == 0xFFFF)
                {
                    errno = HandleGetSocketOption(context, socket, (SocketOptionName)optionName, bufferPosition, bufferSize);
                }
                else
                {
                    Logger.Warning?.Print(LogClass.ServiceBsd, $"Unsupported GetSockOpt Level: {(SocketOptionLevel)level}");
                }
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #11
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // ShutdownAllSockets(u32 how) -> (i32 ret, u32 bsd_errno)
        public ResultCode ShutdownAllSockets(ServiceCtx context)
        {
            int how = context.RequestData.ReadInt32();

            LinuxError errno = LinuxError.EINVAL;

            if (how >= 0 && how <= 2)
            {
                errno = LinuxError.SUCCESS;

                foreach (BsdSocket socket in _sockets)
                {
                    if (socket != null)
                    {
                        try
                        {
                            socket.Handle.Shutdown((SocketShutdown)how);
                        }
                        catch (SocketException exception)
                        {
                            errno = ConvertError((WsaError)exception.ErrorCode);
                            break;
                        }
                    }
                }
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #12
0
        // SetSockOpt(u32 socket, u32 level, u32 option_name, buffer<unknown, 0x21, 0> option_value) -> (i32 ret, u32 bsd_errno)
        public long SetSockOpt(ServiceCtx Context)
        {
            int SocketFd   = Context.RequestData.ReadInt32();
            int Level      = Context.RequestData.ReadInt32();
            int OptionName = Context.RequestData.ReadInt32();

            (long BufferPos, long BufferSize) = Context.Request.GetBufferType0x21();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                Errno = LinuxError.ENOPROTOOPT;

                if (Level == 0xFFFF)
                {
                    Errno = HandleSetSocketOption(Context, Socket, (SocketOptionName)OptionName, BufferPos, BufferSize);
                }
                else
                {
                    Logger.PrintWarning(LogClass.ServiceBsd, $"Unsupported SetSockOpt Level: {(SocketOptionLevel)Level}");
                }
            }

            return(WriteBsdResult(Context, 0, Errno));
        }
コード例 #13
0
        // Fcntl(u32 socket, u32 cmd, u32 arg) -> (i32 ret, u32 bsd_errno)
        public long Fcntl(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();
            int Cmd      = Context.RequestData.ReadInt32();
            int Arg      = Context.RequestData.ReadInt32();

            int        Result = 0;
            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                Errno = LinuxError.SUCCESS;

                if (Cmd == 0x3)
                {
                    Result = !Socket.Handle.Blocking ? 0x800 : 0;
                }
                else if (Cmd == 0x4 && Arg == 0x800)
                {
                    Socket.Handle.Blocking = false;
                    Result = 0;
                }
                else
                {
                    Errno = LinuxError.EOPNOTSUPP;
                }
            }

            return(WriteBsdResult(Context, Result, Errno));
        }
コード例 #14
0
        // Ioctl(u32 fd, u32 request, u32 bufcount, buffer<unknown, 0x21, 0>, buffer<unknown, 0x21, 0>, buffer<unknown, 0x21, 0>, buffer<unknown, 0x21, 0>) -> (i32 ret, u32 bsd_errno, buffer<unknown, 0x22, 0>, buffer<unknown, 0x22, 0>, buffer<unknown, 0x22, 0>, buffer<unknown, 0x22, 0>)
        public long Ioctl(ServiceCtx Context)
        {
            int      SocketFd    = Context.RequestData.ReadInt32();
            BsdIoctl Cmd         = (BsdIoctl)Context.RequestData.ReadInt32();
            int      BufferCount = Context.RequestData.ReadInt32();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                switch (Cmd)
                {
                case BsdIoctl.AtMark:
                    Errno = LinuxError.SUCCESS;

                    (long BufferPosition, long BufferSize) = Context.Request.GetBufferType0x22();

                    // FIXME: OOB not implemented.
                    Context.Memory.WriteInt32(BufferPosition, 0);
                    break;

                default:
                    Errno = LinuxError.EOPNOTSUPP;

                    Logger.PrintWarning(LogClass.ServiceBsd, $"Unsupported Ioctl Cmd: {Cmd}");
                    break;
                }
            }

            return(WriteBsdResult(Context, 0, Errno));
        }
コード例 #15
0
        // Connect(u32 socket, buffer<nn::socket::sockaddr_in, 0x21, 0x10>) -> (i32 ret, u32 bsd_errno)
        public long Connect(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();

            (long BufferPos, long BufferSize) = Context.Request.GetBufferType0x21();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                Errno = LinuxError.SUCCESS;
                try
                {
                    IPEndPoint EndPoint = ParseSockAddr(Context, BufferPos, BufferSize);

                    Socket.Handle.Connect(EndPoint);
                }
                catch (SocketException Exception)
                {
                    Errno = ConvertError((WSAError)Exception.ErrorCode);
                }
            }

            return(WriteBsdResult(Context, 0, Errno));
        }
コード例 #16
0
ファイル: IClient.cs プロジェクト: venhow/Ryujinx
        // Read(u32 socket) -> (i32 ret, u32 bsd_errno, buffer<i8, 0x22, 0> message)
        public ResultCode Read(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();

            (long receivePosition, long receiveLength) = context.Request.GetBufferType0x22();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);
            int        result = -1;

            if (socket != null)
            {
                byte[] receivedBuffer = new byte[receiveLength];

                try
                {
                    result = socket.Handle.Receive(receivedBuffer);
                    errno  = SetResultErrno(socket.Handle, result);
                    context.Memory.Write((ulong)receivePosition, receivedBuffer);
                }
                catch (SocketException exception)
                {
                    errno = ConvertError((WsaError)exception.ErrorCode);
                }
            }

            return(WriteBsdResult(context, result, errno));
        }
コード例 #17
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        private ResultCode SocketInternal(ServiceCtx context, bool exempt)
        {
            BsdAddressFamily domain   = (BsdAddressFamily)context.RequestData.ReadInt32();
            BsdSocketType    type     = (BsdSocketType)context.RequestData.ReadInt32();
            ProtocolType     protocol = (ProtocolType)context.RequestData.ReadInt32();

            BsdSocketCreationFlags creationFlags = (BsdSocketCreationFlags)((int)type >> (int)BsdSocketCreationFlags.FlagsShift);

            type &= BsdSocketType.TypeMask;

            if (domain == BsdAddressFamily.Unknown)
            {
                return(WriteBsdResult(context, -1, LinuxError.EPROTONOSUPPORT));
            }
            else if ((type == BsdSocketType.Seqpacket || type == BsdSocketType.Raw) && !_isPrivileged)
            {
                if (domain != BsdAddressFamily.InterNetwork || type != BsdSocketType.Raw || protocol != ProtocolType.Icmp)
                {
                    return(WriteBsdResult(context, -1, LinuxError.ENOENT));
                }
            }

            AddressFamily netDomain = ConvertBsdAddressFamily(domain);

            if (protocol == ProtocolType.IP)
            {
                if (type == BsdSocketType.Stream)
                {
                    protocol = ProtocolType.Tcp;
                }
                else if (type == BsdSocketType.Dgram)
                {
                    protocol = ProtocolType.Udp;
                }
            }

            ISocket newBsdSocket = new ManagedSocket(netDomain, (SocketType)type, protocol);

            newBsdSocket.Blocking = !creationFlags.HasFlag(BsdSocketCreationFlags.NonBlocking);

            LinuxError errno = LinuxError.SUCCESS;

            int newSockFd = _context.RegisterFileDescriptor(newBsdSocket);

            if (newSockFd == -1)
            {
                errno = LinuxError.EBADF;
            }

            if (exempt)
            {
                newBsdSocket.Disconnect();
            }

            return(WriteBsdResult(context, newSockFd, errno));
        }
コード例 #18
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        private ResultCode WriteBsdResult(ServiceCtx context, int result, LinuxError errorCode = LinuxError.SUCCESS)
        {
            if (errorCode != LinuxError.SUCCESS)
            {
                result = -1;
            }

            context.ResponseData.Write(result);
            context.ResponseData.Write((int)errorCode);

            return(ResultCode.Success);
        }
コード例 #19
0
        private long WriteBsdResult(ServiceCtx Context, int Result, LinuxError ErrorCode = 0)
        {
            if (ErrorCode != LinuxError.SUCCESS)
            {
                Result = -1;
            }

            Context.ResponseData.Write(Result);
            Context.ResponseData.Write((int)ErrorCode);

            return(0);
        }
コード例 #20
0
        // Accept(u32 socket) -> (i32 ret, u32 bsd_errno, u32 addrlen, buffer<nn::socket::sockaddr_in, 0x22, 0x10> addr)
        public long Accept(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();

            (long BufferPos, long BufferSize) = Context.Request.GetBufferType0x22();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                Errno = LinuxError.SUCCESS;

                Socket NewSocket = null;

                try
                {
                    NewSocket = Socket.Handle.Accept();
                }
                catch (SocketException Exception)
                {
                    Errno = ConvertError((WSAError)Exception.ErrorCode);
                }

                if (NewSocket == null && Errno == LinuxError.SUCCESS)
                {
                    Errno = LinuxError.EWOULDBLOCK;
                }
                else if (Errno == LinuxError.SUCCESS)
                {
                    BsdSocket NewBsdSocket = new BsdSocket
                    {
                        Family   = (int)NewSocket.AddressFamily,
                        Type     = (int)NewSocket.SocketType,
                        Protocol = (int)NewSocket.ProtocolType,
                        Handle   = NewSocket,
                    };

                    Sockets.Add(NewBsdSocket);

                    WriteSockAddr(Context, BufferPos, NewBsdSocket, true);

                    WriteBsdResult(Context, Sockets.Count - 1, Errno);

                    Context.ResponseData.Write(0x10);

                    return(0);
                }
            }

            return(WriteBsdResult(Context, -1, Errno));
        }
コード例 #21
0
ファイル: IClient.cs プロジェクト: wangyu0426/Ryujinx
        // Accept(u32 socket) -> (i32 ret, u32 bsd_errno, u32 addrlen, buffer<nn::socket::sockaddr_in, 0x22, 0x10> addr)
        public ResultCode Accept(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();

            (long bufferPos, long bufferSize) = context.Request.GetBufferType0x22();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                errno = LinuxError.SUCCESS;

                Socket newSocket = null;

                try
                {
                    newSocket = socket.Handle.Accept();
                }
                catch (SocketException exception)
                {
                    errno = ConvertError((WsaError)exception.ErrorCode);
                }

                if (newSocket == null && errno == LinuxError.SUCCESS)
                {
                    errno = LinuxError.EWOULDBLOCK;
                }
                else if (errno == LinuxError.SUCCESS)
                {
                    BsdSocket newBsdSocket = new BsdSocket
                    {
                        Family   = (int)newSocket.AddressFamily,
                        Type     = (int)newSocket.SocketType,
                        Protocol = (int)newSocket.ProtocolType,
                        Handle   = newSocket
                    };

                    _sockets.Add(newBsdSocket);

                    WriteSockAddr(context, bufferPos, newBsdSocket, true);

                    WriteBsdResult(context, _sockets.Count - 1, errno);

                    context.ResponseData.Write(0x10);

                    return(ResultCode.Success);
                }
            }

            return(WriteBsdResult(context, -1, errno));
        }
コード例 #22
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        // ShutdownAllSockets(u32 how) -> (i32 ret, u32 bsd_errno)
        public ResultCode ShutdownAllSockets(ServiceCtx context)
        {
            int how = context.RequestData.ReadInt32();

            LinuxError errno = LinuxError.EINVAL;

            if (how >= 0 && how <= 2)
            {
                errno = _context.ShutdownAllSockets((BsdSocketShutdownFlags)how);
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #23
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        // Close(u32 fd) -> (i32 ret, u32 bsd_errno)
        public ResultCode Close(ServiceCtx context)
        {
            int fd = context.RequestData.ReadInt32();

            LinuxError errno = LinuxError.EBADF;

            if (_context.CloseFileDescriptor(fd))
            {
                errno = LinuxError.SUCCESS;
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #24
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        // Listen(u32 socket, u32 backlog) -> (i32 ret, u32 bsd_errno)
        public ResultCode Listen(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();
            int backlog  = context.RequestData.ReadInt32();

            LinuxError errno  = LinuxError.EBADF;
            ISocket    socket = _context.RetrieveSocket(socketFd);

            if (socket != null)
            {
                errno = socket.Listen(backlog);
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #25
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        // Connect(u32 socket, buffer<nn::socket::sockaddr_in, 0x21, 0x10>) -> (i32 ret, u32 bsd_errno)
        public ResultCode Connect(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();

            (ulong bufferPosition, ulong bufferSize) = context.Request.GetBufferType0x21();

            LinuxError errno  = LinuxError.EBADF;
            ISocket    socket = _context.RetrieveSocket(socketFd);

            if (socket != null)
            {
                IPEndPoint endPoint = context.Memory.Read <BsdSockAddr>(bufferPosition).ToIPEndPoint();

                errno = socket.Connect(endPoint);
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #26
0
ファイル: IClient.cs プロジェクト: wangyu0426/Ryujinx
        // Close(u32 socket) -> (i32 ret, u32 bsd_errno)
        public ResultCode Close(ServiceCtx context)
        {
            int socketFd = context.RequestData.ReadInt32();

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);

            if (socket != null)
            {
                socket.Handle.Close();

                _sockets[socketFd] = null;

                errno = LinuxError.SUCCESS;
            }

            return(WriteBsdResult(context, 0, errno));
        }
コード例 #27
0
ファイル: IClient.cs プロジェクト: mailwl/Ryujinx
        [CommandHipc(31)] // 7.0.0+
        // EventFd(u64 initval, nn::socket::EventFdFlags flags) -> (i32 ret, u32 bsd_errno)
        public ResultCode EventFd(ServiceCtx context)
        {
            ulong        initialValue = context.RequestData.ReadUInt64();
            EventFdFlags flags        = (EventFdFlags)context.RequestData.ReadUInt32();

            EventFileDescriptor newEventFile = new EventFileDescriptor(initialValue, flags);

            LinuxError errno = LinuxError.SUCCESS;

            int newSockFd = _context.RegisterFileDescriptor(newEventFile);

            if (newSockFd == -1)
            {
                errno = LinuxError.EBADF;
            }

            return(WriteBsdResult(context, newSockFd, errno));
        }
コード例 #28
0
        // Close(u32 socket) -> (i32 ret, u32 bsd_errno)
        public long Close(ServiceCtx Context)
        {
            int SocketFd = Context.RequestData.ReadInt32();

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);

            if (Socket != null)
            {
                Socket.Handle.Close();

                Sockets[SocketFd] = null;

                Errno = LinuxError.SUCCESS;
            }

            return(WriteBsdResult(Context, 0, Errno));
        }
コード例 #29
0
        // 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 long RecvFrom(ServiceCtx Context)
        {
            int         SocketFd    = Context.RequestData.ReadInt32();
            SocketFlags SocketFlags = (SocketFlags)Context.RequestData.ReadInt32();

            (long ReceivePosition, long ReceiveLength)       = Context.Request.GetBufferType0x22();
            (long SockAddrInPosition, long SockAddrInSize)   = Context.Request.GetBufferType0x21();
            (long SockAddrOutPosition, long SockAddrOutSize) = Context.Request.GetBufferType0x22(1);

            LinuxError Errno  = LinuxError.EBADF;
            BsdSocket  Socket = RetrieveSocket(SocketFd);
            int        Result = -1;

            if (Socket != null)
            {
                if (SocketFlags != SocketFlags.None && (SocketFlags & SocketFlags.OutOfBand) == 0 &&
                    (SocketFlags & SocketFlags.Peek) == 0)
                {
                    Logger.PrintWarning(LogClass.ServiceBsd, $"Unsupported Recv flags: {SocketFlags}");

                    return(WriteBsdResult(Context, -1, LinuxError.EOPNOTSUPP));
                }

                byte[]   ReceivedBuffer = new byte[ReceiveLength];
                EndPoint EndPoint       = ParseSockAddr(Context, SockAddrInPosition, SockAddrInSize);

                try
                {
                    Result = Socket.Handle.ReceiveFrom(ReceivedBuffer, ReceivedBuffer.Length, SocketFlags, ref EndPoint);
                    Errno  = SetResultErrno(Socket.Handle, Result);

                    Context.Memory.WriteBytes(ReceivePosition, ReceivedBuffer);
                    WriteSockAddr(Context, SockAddrOutPosition, (IPEndPoint)EndPoint);
                }
                catch (SocketException Exception)
                {
                    Errno = ConvertError((WSAError)Exception.ErrorCode);
                }
            }

            return(WriteBsdResult(Context, Result, Errno));
        }
コード例 #30
0
ファイル: IClient.cs プロジェクト: reuniware/Ryujinx
        // 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 long RecvFrom(ServiceCtx context)
        {
            int         socketFd    = context.RequestData.ReadInt32();
            SocketFlags socketFlags = (SocketFlags)context.RequestData.ReadInt32();

            (long receivePosition, long receiveLength)       = context.Request.GetBufferType0x22();
            (long sockAddrInPosition, long sockAddrInSize)   = context.Request.GetBufferType0x21();
            (long sockAddrOutPosition, long sockAddrOutSize) = context.Request.GetBufferType0x22(1);

            LinuxError errno  = LinuxError.EBADF;
            BsdSocket  socket = RetrieveSocket(socketFd);
            int        result = -1;

            if (socket != null)
            {
                if (socketFlags != SocketFlags.None && (socketFlags & SocketFlags.OutOfBand) == 0 &&
                    (socketFlags & SocketFlags.Peek) == 0)
                {
                    Logger.PrintWarning(LogClass.ServiceBsd, $"Unsupported Recv flags: {socketFlags}");

                    return(WriteBsdResult(context, -1, LinuxError.EOPNOTSUPP));
                }

                byte[]   receivedBuffer = new byte[receiveLength];
                EndPoint endPoint       = ParseSockAddr(context, sockAddrInPosition, sockAddrInSize);

                try
                {
                    result = socket.Handle.ReceiveFrom(receivedBuffer, receivedBuffer.Length, socketFlags, ref endPoint);
                    errno  = SetResultErrno(socket.Handle, result);

                    context.Memory.WriteBytes(receivePosition, receivedBuffer);
                    WriteSockAddr(context, sockAddrOutPosition, (IPEndPoint)endPoint);
                }
                catch (SocketException exception)
                {
                    errno = ConvertError((WsaError)exception.ErrorCode);
                }
            }

            return(WriteBsdResult(context, result, errno));
        }