windows 如何在 C/C++ 跨平台中以编程方式创建 ssh 隧道?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5007616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to programmatically create ssh tunnel in C/C++ cross-platform?
提问by Nektarios
I need to connect via TCP to a port that's behind a firewall, accessible through an SSH tunnel. I can achieve connection by opening a tunnel and hittting that port, but I want to build this tunneling in to my application.
我需要通过 TCP 连接到防火墙后面的端口,可通过 SSH 隧道访问。我可以通过打开隧道并点击该端口来实现连接,但我想将此隧道构建到我的应用程序中。
Additionally, I want to be able to provide automatic login by use of having authorized keys on the server
此外,我希望能够通过使用服务器上的授权密钥来提供自动登录
This must work on the following platforms (in order of importance)
这必须适用于以下平台(按重要性排序)
- iOS (trickiest because I can't fork an ssh tunnel like I can on other platforms)
- OS X
- Linux
- Windows
- iOS(最棘手,因为我不能像在其他平台上那样分叉 ssh 隧道)
- 操作系统
- Linux
- 视窗
What's the easy way to do this? I don't want to spend a great deal of effort obviously since this isn't the meat of my application. But I'll reuse it so I may care enough to "do things right"
有什么简单的方法可以做到这一点?显然我不想花费太多精力,因为这不是我申请的重点。但我会重复使用它,所以我可能会足够关心“做正确的事”
采纳答案by Nektarios
But libssh2 is BSD-licensed and appears to have the functionality needed
但是 libssh2 是 BSD 许可的并且似乎具有所需的功能
Looks like: libssh2_channel_direct_tcpip_exwill be the call
看起来像:libssh2_channel_direct_tcpip_ex将被调用
Notethat the LGPL'd libssh is a problem because on iOS apps you MUST statically link and CANNOT dynamically link to libraries. Therefore, using an LGPL'd library means my source becomes open source.
请注意,LGPL 的 libssh 是一个问题,因为在 iOS 应用程序上,您必须静态链接并且不能动态链接到库。因此,使用 LGPL 的库意味着我的源代码成为开放源代码。
回答by Rituparna Kashyap
回答by Waleed
There is a commercial LIB if you want to have a look at, www.chilkatsoft.com/, it is a genric C++ lib for all languages, in it there is a support for SSH tunneling for IOS.
如果你想看看,有一个商业 LIB,www.chilkatsoft.com/,它是一个适用于所有语言的通用 C++ 库,其中支持 IOS 的 SSH 隧道。
回答by sstn
Does the LGPL differentiate between linking dynamically and statically? I don't think so.
LGPL 是否区分动态链接和静态链接?我不这么认为。
The library code (i.e. embedding your own SSH implementation) looks most versatile to me. Except the fact that you might inherit security problems.
库代码(即嵌入您自己的 SSH 实现)对我来说看起来最通用。除了您可能会继承安全问题这一事实。
On MacOSX/Linux/Unix, you can simply invoke 'ssh' and assume it exists (or make it as a precondition). On Windows, you would rely on putty and friends. I don't think that's a good idea.
在 MacOSX/Linux/Unix 上,您可以简单地调用 'ssh' 并假设它存在(或将其作为先决条件)。在 Windows 上,你会依赖腻子和朋友。我不认为这是个好主意。