Examples of SshdSocketAddress


Examples of org.apache.sshd.client.SshdSocketAddress

    public ChannelDirectTcpip(SshdSocketAddress local, SshdSocketAddress remote) {
        super("direct-tcpip");
        if (local == null) {
            try {
                local = new SshdSocketAddress(InetAddress.getLocalHost().getHostName(), 0);
            } catch (UnknownHostException e) {
                throw new IllegalStateException("Unable to retrieve local host name");
            }
        }
        if (remote == null) {
View Full Code Here

Examples of org.apache.sshd.client.SshdSocketAddress

    @Test
    public void testRemoteForwardingNative() throws Exception {
        ClientSession session = createNativeSession();

        int forwardedPort = getFreePort();
        SshdSocketAddress remote = new SshdSocketAddress("", forwardedPort);
        SshdSocketAddress local = new SshdSocketAddress("localhost", echoPort);

        session.startRemotePortForwarding(remote, local);

        Socket s = new Socket(remote.getHostName(), remote.getPort());
        s.getOutputStream().write("Hello".getBytes());
View Full Code Here

Examples of org.apache.sshd.client.SshdSocketAddress

    @Test
    public void testLocalForwardingNative() throws Exception {
        ClientSession session = createNativeSession();

        int forwardedPort = getFreePort();
        SshdSocketAddress local = new SshdSocketAddress("", forwardedPort);
        SshdSocketAddress remote = new SshdSocketAddress("localhost", echoPort);

        session.startLocalPortForwarding(local, remote);

        Socket s = new Socket(local.getHostName(), local.getPort());
        s.getOutputStream().write("Hello".getBytes());
View Full Code Here

Examples of org.apache.sshd.client.SshdSocketAddress

    @Test
    public void testForwardingChannel() throws Exception {
        ClientSession session = createNativeSession();

        int forwardedPort = getFreePort();
        SshdSocketAddress local = new SshdSocketAddress("", forwardedPort);
        SshdSocketAddress remote = new SshdSocketAddress("localhost", echoPort);

        ChannelDirectTcpip channel = session.createDirectTcpipChannel(local, remote);
        channel.open().await();

        channel.getOut().write("Hello".getBytes());
View Full Code Here

Examples of org.apache.sshd.client.SshdSocketAddress

        }
    }

    @Override
    public void sessionCreated(final IoSession session) throws Exception {
        SshdSocketAddress remote = forwards.get(((InetSocketAddress) session.getLocalAddress()).getPort());
        final ChannelForwardedTcpip channel = new ChannelForwardedTcpip(session, remote);
        session.setAttribute(ChannelForwardedTcpip.class, channel);
        this.session.registerChannel(channel);
        channel.open().addListener(new SshFutureListener<OpenFuture>() {
            public void operationComplete(OpenFuture future) {
View Full Code Here

Examples of org.apache.sshd.client.SshdSocketAddress

        int originatorPort = buffer.getInt();
        log.info("Receiving request for direct tcpip: hostToConnect={}, portToConnect={}, originatorIpAddress={}, originatorPort={}",
                new Object[] { hostToConnect, portToConnect, originatorIpAddress, originatorPort });

        final ClientSessionImpl clientSession = (ClientSessionImpl)getSession();
        SshdSocketAddress address;
        try {
            address = clientSession.getForwardedPort(portToConnect);
        } catch (RuntimeException e) {
            address = null;
        }
        //final ForwardingFilter filter = clientSession.getClientFactoryManager().getForwardingFilter();
        if (address == null /*|| filter == null || !filter.canConnect(address, serverSession)*/) {
            super.close(true);
            f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "connect denied"));
            return f;
        }

        connector = new NioSocketConnector();
        out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
        IoHandler handler = new IoHandlerAdapter() {
            @Override
            public void messageReceived(IoSession session, Object message) throws Exception {
                IoBuffer ioBuffer = (IoBuffer) message;
                int r = ioBuffer.remaining();
                byte[] b = new byte[r];
                ioBuffer.get(b, 0, r);
                out.write(b, 0, r);
                out.flush();
            }

            @Override
            public void sessionClosed(IoSession session) throws Exception {
                if (!closing) {
                    sendEof();
                }
            }
        };
        connector.setHandler(handler);
        ConnectFuture future = connector.connect(address.toInetSocketAddress());
        future.addListener(new IoFutureListener<ConnectFuture>() {
            public void operationComplete(ConnectFuture future) {
                if (future.isConnected()) {
                    ioSession = future.getSession();
                    f.setOpened();
View Full Code Here

Examples of org.apache.sshd.common.SshdSocketAddress

            allowMoreSessions = false;
        } else if (req.equals("tcpip-forward")) {
            String address = buffer.getString();
            int port = buffer.getInt();
            try {
                SshdSocketAddress bound = getTcpipForwarder().localPortForwardingRequested(new SshdSocketAddress(address, port));
                port = bound.getPort();
                if (wantReply){
                    buffer = createBuffer(SshConstants.Message.SSH_MSG_REQUEST_SUCCESS, 0);
                    buffer.putInt(port);
                    writePacket(buffer);
                }
            } catch (Exception e) {
                log.debug("Error starting tcpip forward", e);
                if (wantReply) {
                    buffer = createBuffer(SshConstants.Message.SSH_MSG_REQUEST_FAILURE, 0);
                    writePacket(buffer);
                }
            }
            return;
        } else if (req.equals("cancel-tcpip-forward")) {
            String address = buffer.getString();
            int port = buffer.getInt();
            getTcpipForwarder().localPortForwardingCancelled(new SshdSocketAddress(address, port));
            if (wantReply){
                buffer = createBuffer(SshConstants.Message.SSH_MSG_REQUEST_SUCCESS, 0);
                writePacket(buffer);
            }
            return;
View Full Code Here

Examples of org.apache.sshd.common.SshdSocketAddress

    public ChannelDirectTcpip(SshdSocketAddress local, SshdSocketAddress remote) {
        super("direct-tcpip");
        if (local == null) {
            try {
                local = new SshdSocketAddress(InetAddress.getLocalHost().getHostName(), 0);
            } catch (UnknownHostException e) {
                throw new IllegalStateException("Unable to retrieve local host name");
            }
        }
        if (remote == null) {
View Full Code Here

Examples of org.apache.sshd.common.SshdSocketAddress

            throw new IllegalStateException("TcpipForwarder is closed");
        }
        if (isClosing()) {
            throw new IllegalStateException("TcpipForwarder is closing");
        }
        SshdSocketAddress bound = doBind(local);
        localToRemote.put(bound.getPort(), remote);
        return bound;
    }
View Full Code Here

Examples of org.apache.sshd.common.SshdSocketAddress

            throw new SshException("Tcpip forwarding request denied by server");
        }
        int port = remote.getPort() == 0 ? result.getInt() : remote.getPort();
        // TODO: Is it really safe to only store the local address after the request ?
        remoteToLocal.put(port, local);
        return new SshdSocketAddress(remote.getHostName(), port);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.