Opening channel to localhost with libssh
I'm working on a program that creates a reverse SSH tunnel to a middleman server so that computers in a local network, to which a direct connection is not possible, can still be accessed from outside that local network. I have chosen for the libssh library for this and I'm having problems opening a channel to localhost to forward the incoming data to the local application. Opening the SSH session and requesting the forwarding of data to the local computer seems to work fine. However I can't open a channel to the localhost to read and write data from/to the local application. The way I'm currently trying to open a connection to localhost:
ssh_channel localhost_channel = ssh_channel_new(my_ssh_session);
rc = ssh_channel_open_forward(localhost_channel, "127.0.0.1", 5900,
"localhost", 5555);
if (rc != SSH_OK) {
myLog << "Could not open channel to localhost";
exit(-1);
}
My program does not exit, so SSH_OK is set. The logs however say that the connection was refused. And there is a working VNC server running on port 5900. I can see the connection request coming in. So I'm pretty sure the problem comes from the connection with localhost. I would really appreciate any advice/tips.
I'm using libssh 0.7.2 on Windows 10 and compiling with msvc.
c ssh libssh
add a comment |
I'm working on a program that creates a reverse SSH tunnel to a middleman server so that computers in a local network, to which a direct connection is not possible, can still be accessed from outside that local network. I have chosen for the libssh library for this and I'm having problems opening a channel to localhost to forward the incoming data to the local application. Opening the SSH session and requesting the forwarding of data to the local computer seems to work fine. However I can't open a channel to the localhost to read and write data from/to the local application. The way I'm currently trying to open a connection to localhost:
ssh_channel localhost_channel = ssh_channel_new(my_ssh_session);
rc = ssh_channel_open_forward(localhost_channel, "127.0.0.1", 5900,
"localhost", 5555);
if (rc != SSH_OK) {
myLog << "Could not open channel to localhost";
exit(-1);
}
My program does not exit, so SSH_OK is set. The logs however say that the connection was refused. And there is a working VNC server running on port 5900. I can see the connection request coming in. So I'm pretty sure the problem comes from the connection with localhost. I would really appreciate any advice/tips.
I'm using libssh 0.7.2 on Windows 10 and compiling with msvc.
c ssh libssh
Did you find a solution?
– Robben_Ford_Fan_boy
Apr 24 '17 at 15:58
Yes, but probably not the one you are looking for. We decided to switch to C# for this application.
– larzz11
Apr 25 '17 at 9:57
Cool. Is there a good library in .Net for this stuff?
– Robben_Ford_Fan_boy
Apr 25 '17 at 10:07
Multiple ones, but we went with the one from Rebex. I costs $550, but we needed .NET 2.0 support. If you do not have that requirement there are open source libraries (like ssh.net) that will work fine)
– larzz11
Apr 26 '17 at 6:37
add a comment |
I'm working on a program that creates a reverse SSH tunnel to a middleman server so that computers in a local network, to which a direct connection is not possible, can still be accessed from outside that local network. I have chosen for the libssh library for this and I'm having problems opening a channel to localhost to forward the incoming data to the local application. Opening the SSH session and requesting the forwarding of data to the local computer seems to work fine. However I can't open a channel to the localhost to read and write data from/to the local application. The way I'm currently trying to open a connection to localhost:
ssh_channel localhost_channel = ssh_channel_new(my_ssh_session);
rc = ssh_channel_open_forward(localhost_channel, "127.0.0.1", 5900,
"localhost", 5555);
if (rc != SSH_OK) {
myLog << "Could not open channel to localhost";
exit(-1);
}
My program does not exit, so SSH_OK is set. The logs however say that the connection was refused. And there is a working VNC server running on port 5900. I can see the connection request coming in. So I'm pretty sure the problem comes from the connection with localhost. I would really appreciate any advice/tips.
I'm using libssh 0.7.2 on Windows 10 and compiling with msvc.
c ssh libssh
I'm working on a program that creates a reverse SSH tunnel to a middleman server so that computers in a local network, to which a direct connection is not possible, can still be accessed from outside that local network. I have chosen for the libssh library for this and I'm having problems opening a channel to localhost to forward the incoming data to the local application. Opening the SSH session and requesting the forwarding of data to the local computer seems to work fine. However I can't open a channel to the localhost to read and write data from/to the local application. The way I'm currently trying to open a connection to localhost:
ssh_channel localhost_channel = ssh_channel_new(my_ssh_session);
rc = ssh_channel_open_forward(localhost_channel, "127.0.0.1", 5900,
"localhost", 5555);
if (rc != SSH_OK) {
myLog << "Could not open channel to localhost";
exit(-1);
}
My program does not exit, so SSH_OK is set. The logs however say that the connection was refused. And there is a working VNC server running on port 5900. I can see the connection request coming in. So I'm pretty sure the problem comes from the connection with localhost. I would really appreciate any advice/tips.
I'm using libssh 0.7.2 on Windows 10 and compiling with msvc.
c ssh libssh
c ssh libssh
edited Jan 2 at 3:38
Cœur
19k9112154
19k9112154
asked Sep 28 '15 at 9:29
larzz11larzz11
577520
577520
Did you find a solution?
– Robben_Ford_Fan_boy
Apr 24 '17 at 15:58
Yes, but probably not the one you are looking for. We decided to switch to C# for this application.
– larzz11
Apr 25 '17 at 9:57
Cool. Is there a good library in .Net for this stuff?
– Robben_Ford_Fan_boy
Apr 25 '17 at 10:07
Multiple ones, but we went with the one from Rebex. I costs $550, but we needed .NET 2.0 support. If you do not have that requirement there are open source libraries (like ssh.net) that will work fine)
– larzz11
Apr 26 '17 at 6:37
add a comment |
Did you find a solution?
– Robben_Ford_Fan_boy
Apr 24 '17 at 15:58
Yes, but probably not the one you are looking for. We decided to switch to C# for this application.
– larzz11
Apr 25 '17 at 9:57
Cool. Is there a good library in .Net for this stuff?
– Robben_Ford_Fan_boy
Apr 25 '17 at 10:07
Multiple ones, but we went with the one from Rebex. I costs $550, but we needed .NET 2.0 support. If you do not have that requirement there are open source libraries (like ssh.net) that will work fine)
– larzz11
Apr 26 '17 at 6:37
Did you find a solution?
– Robben_Ford_Fan_boy
Apr 24 '17 at 15:58
Did you find a solution?
– Robben_Ford_Fan_boy
Apr 24 '17 at 15:58
Yes, but probably not the one you are looking for. We decided to switch to C# for this application.
– larzz11
Apr 25 '17 at 9:57
Yes, but probably not the one you are looking for. We decided to switch to C# for this application.
– larzz11
Apr 25 '17 at 9:57
Cool. Is there a good library in .Net for this stuff?
– Robben_Ford_Fan_boy
Apr 25 '17 at 10:07
Cool. Is there a good library in .Net for this stuff?
– Robben_Ford_Fan_boy
Apr 25 '17 at 10:07
Multiple ones, but we went with the one from Rebex. I costs $550, but we needed .NET 2.0 support. If you do not have that requirement there are open source libraries (like ssh.net) that will work fine)
– larzz11
Apr 26 '17 at 6:37
Multiple ones, but we went with the one from Rebex. I costs $550, but we needed .NET 2.0 support. If you do not have that requirement there are open source libraries (like ssh.net) that will work fine)
– larzz11
Apr 26 '17 at 6:37
add a comment |
1 Answer
1
active
oldest
votes
For reverse port forwarding, use ssh_channel_listen_forward
and ssh_channel_accept_forward
.
The ssh_channel_open_forward
is for direct port forwarding.
See Doing reverse port forwarding with libssh.
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
As the next step you usessh_channel_accept_forward
. The example I've linked shows how to do that.
– Martin Prikryl
Sep 29 '15 at 7:42
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32819678%2fopening-channel-to-localhost-with-libssh%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For reverse port forwarding, use ssh_channel_listen_forward
and ssh_channel_accept_forward
.
The ssh_channel_open_forward
is for direct port forwarding.
See Doing reverse port forwarding with libssh.
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
As the next step you usessh_channel_accept_forward
. The example I've linked shows how to do that.
– Martin Prikryl
Sep 29 '15 at 7:42
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
add a comment |
For reverse port forwarding, use ssh_channel_listen_forward
and ssh_channel_accept_forward
.
The ssh_channel_open_forward
is for direct port forwarding.
See Doing reverse port forwarding with libssh.
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
As the next step you usessh_channel_accept_forward
. The example I've linked shows how to do that.
– Martin Prikryl
Sep 29 '15 at 7:42
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
add a comment |
For reverse port forwarding, use ssh_channel_listen_forward
and ssh_channel_accept_forward
.
The ssh_channel_open_forward
is for direct port forwarding.
See Doing reverse port forwarding with libssh.
For reverse port forwarding, use ssh_channel_listen_forward
and ssh_channel_accept_forward
.
The ssh_channel_open_forward
is for direct port forwarding.
See Doing reverse port forwarding with libssh.
edited Sep 29 '15 at 7:42
answered Sep 29 '15 at 5:18
Martin PrikrylMartin Prikryl
90.2k22179384
90.2k22179384
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
As the next step you usessh_channel_accept_forward
. The example I've linked shows how to do that.
– Martin Prikryl
Sep 29 '15 at 7:42
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
add a comment |
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
As the next step you usessh_channel_accept_forward
. The example I've linked shows how to do that.
– Martin Prikryl
Sep 29 '15 at 7:42
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
Alright, this is however not an answer to my question: how to create a channel to localhost.the function ssh_channel_listen_forward does not Redirect it to anywhere once it's received.
– larzz11
Sep 29 '15 at 7:25
As the next step you use
ssh_channel_accept_forward
. The example I've linked shows how to do that.– Martin Prikryl
Sep 29 '15 at 7:42
As the next step you use
ssh_channel_accept_forward
. The example I've linked shows how to do that.– Martin Prikryl
Sep 29 '15 at 7:42
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
I have read that tutorial about a hundred times before posting this question. That also does not answer my question. I believe I have found the answer. LibSSH is not capable o0f forwarding the data received by the forwarded channel. To actually forward the data a socket must be used.
– larzz11
Sep 29 '15 at 14:21
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
So post your solution as an answer.
– Martin Prikryl
Sep 29 '15 at 15:30
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
I will once I have a working solution. I will then add all the source code, because I have seen this question in other places without answer.
– larzz11
Sep 30 '15 at 7:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32819678%2fopening-channel-to-localhost-with-libssh%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you find a solution?
– Robben_Ford_Fan_boy
Apr 24 '17 at 15:58
Yes, but probably not the one you are looking for. We decided to switch to C# for this application.
– larzz11
Apr 25 '17 at 9:57
Cool. Is there a good library in .Net for this stuff?
– Robben_Ford_Fan_boy
Apr 25 '17 at 10:07
Multiple ones, but we went with the one from Rebex. I costs $550, but we needed .NET 2.0 support. If you do not have that requirement there are open source libraries (like ssh.net) that will work fine)
– larzz11
Apr 26 '17 at 6:37