SSH Tunneling using libssh2
<p>I am trying to do a SSH-TUNNEL trough <code>libssh2</code>. Till now i was doing it with this command :</p>

<pre><code>server# sshpass -p password ssh -vvv username@1.2.3.4 -o StrictHostKeyChecking=no -N -D 1.2.3.4:5555
</code></pre>

<p>the <code>-D 1.2.3.4:5555</code> is used to open the tunnel on internet on that port then i go and use it with <code>CURL</code> :</p>

<pre><code>server# curl --SOCKS5 "1.2.3.4:5555" "www.somesite.com"
-- content of the website --
</code></pre>

<p>Now i am trying to do the same, but with <code>libssh2</code>, thus i need to do it in <code>C/C++</code></p>

<p>I tried both examples from <code>libssh2</code></p>

<p><strong>direct_tcpip.c</strong> -> <a href="https://www.libssh2.org/examples/direct_tcpip.html" rel="nofollow">https://www.libssh2.org/examples/direct_tcpip.html</a></p>

<pre><code>Fingerprint: 5D 75 A3 D9 10 65 D5 C4 6B CA 37 98 26 33 53 24 F8 19 1B F9
Authentication methods: publickey,password
Waiting for TCP connection on 1.2.3.4:5555...
Forwarding connection from 1.2.3.4:58595 here to remote 1.2.3.4:22
read: Connection reset by peer &lt;-- When I use curl command
</code></pre>

<p>and</p>

<p><strong>tcpip-forward.c</strong> -> <a href="https://www.libssh2.org/examples/tcpip-forward.html" rel="nofollow">https://www.libssh2.org/examples/tcpip-forward.html</a></p>

<pre><code>Fingerprint: 5D 75 A3 D9 10 65 D5 C4 6B CA 37 98 26 33 53 24 F8 19 1B F9
Authentication methods: publickey,password
Waiting for TCP connection on 1.2.3.4:5555...
Forwarding connection from 1.2.3.4:58595 here to remote 1.2.3.4:22
The remote client at 1.2.3.4:5555 disconnected! &lt;-- When I use curl command
</code></pre>

<p>and curl command :</p>

<p><code>server# curl --SOCKS5 "1.2.3.4:5555" "somesite.com"
 curl: (7) Received invalid version in initial SOCKS5 response.</code></p>

<p>What is the problem? Is <code>libssh2</code> capable of tunneling or not? </p>

<p>P.S. The project is compatible <code>C/C++</code>, that's why I put two tags.</p>