mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
@ -220,7 +220,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Waiting for TCP connection on %s:%d...\n",
|
fprintf(stderr, "Waiting for TCP connection on %s:%d...\n",
|
||||||
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
|
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
|
||||||
|
|
||||||
forwardsock = accept(listensock, (struct sockaddr *)&sin, &sinlen);
|
forwardsock = accept(listensock, (struct sockaddr *)&sin, &sinlen);
|
||||||
if(forwardsock == LIBSSH2_INVALID_SOCKET) {
|
if(forwardsock == LIBSSH2_INVALID_SOCKET) {
|
||||||
@ -232,7 +232,7 @@ int main(int argc, char *argv[])
|
|||||||
sport = ntohs(sin.sin_port);
|
sport = ntohs(sin.sin_port);
|
||||||
|
|
||||||
fprintf(stderr, "Forwarding connection from %s:%d here to remote %s:%d\n",
|
fprintf(stderr, "Forwarding connection from %s:%d here to remote %s:%d\n",
|
||||||
shost, sport, remote_desthost, remote_destport);
|
shost, sport, remote_desthost, remote_destport);
|
||||||
|
|
||||||
channel = libssh2_channel_direct_tcpip_ex(session, remote_desthost,
|
channel = libssh2_channel_direct_tcpip_ex(session, remote_desthost,
|
||||||
remote_destport, shost, sport);
|
remote_destport, shost, sport);
|
||||||
@ -264,7 +264,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if(len == 0) {
|
else if(len == 0) {
|
||||||
fprintf(stderr, "The client at %s:%d disconnected.\n", shost,
|
fprintf(stderr, "The client at %s:%d disconnected.\n", shost,
|
||||||
sport);
|
sport);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr = 0;
|
wr = 0;
|
||||||
@ -301,7 +301,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if(libssh2_channel_eof(channel)) {
|
if(libssh2_channel_eof(channel)) {
|
||||||
fprintf(stderr, "The server at %s:%d disconnected.\n",
|
fprintf(stderr, "The server at %s:%d disconnected.\n",
|
||||||
remote_desthost, remote_destport);
|
remote_desthost, remote_destport);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,13 +243,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fprintf(stderr, "Sending NETCONF client <hello>\n");
|
fprintf(stderr, "Sending NETCONF client <hello>\n");
|
||||||
len = snprintf(buf, sizeof(buf),
|
len = snprintf(buf, sizeof(buf),
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
"<hello>"
|
"<hello>"
|
||||||
"<capabilities>"
|
"<capabilities>"
|
||||||
"<capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>"
|
"<capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>"
|
||||||
"</capabilities>"
|
"</capabilities>"
|
||||||
"</hello>\n"
|
"</hello>\n"
|
||||||
"]]>]]>\n");
|
"]]>]]>\n");
|
||||||
if(-1 == netconf_write(channel, buf, len))
|
if(-1 == netconf_write(channel, buf, len))
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
|
|
||||||
@ -263,11 +263,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
fprintf(stderr, "Sending NETCONF <rpc>\n");
|
fprintf(stderr, "Sending NETCONF <rpc>\n");
|
||||||
len = snprintf(buf, sizeof(buf),
|
len = snprintf(buf, sizeof(buf),
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
|
"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
|
||||||
"<get-interface-information><terse/></get-interface-information>"
|
"<get-interface-information><terse/></get-interface-information>"
|
||||||
"</rpc>\n"
|
"</rpc>\n"
|
||||||
"]]>]]>\n");
|
"]]>]]>\n");
|
||||||
if(-1 == netconf_write(channel, buf, len))
|
if(-1 == netconf_write(channel, buf, len))
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Asking server to listen on remote %s:%d\n",
|
fprintf(stderr, "Asking server to listen on remote %s:%d\n",
|
||||||
remote_listenhost, remote_wantport);
|
remote_listenhost, remote_wantport);
|
||||||
|
|
||||||
listener = libssh2_channel_forward_listen_ex(session, remote_listenhost,
|
listener = libssh2_channel_forward_listen_ex(session, remote_listenhost,
|
||||||
remote_wantport, &remote_listenport, 1);
|
remote_wantport, &remote_listenport, 1);
|
||||||
@ -204,7 +204,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Server is listening on %s:%d\n", remote_listenhost,
|
fprintf(stderr, "Server is listening on %s:%d\n", remote_listenhost,
|
||||||
remote_listenport);
|
remote_listenport);
|
||||||
|
|
||||||
fprintf(stderr, "Waiting for remote connection\n");
|
fprintf(stderr, "Waiting for remote connection\n");
|
||||||
channel = libssh2_channel_forward_accept(listener);
|
channel = libssh2_channel_forward_accept(listener);
|
||||||
@ -216,8 +216,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Accepted remote connection. Connecting to local server %s:%d\n",
|
"Accepted remote connection. Connecting to local server %s:%d\n",
|
||||||
local_destip, local_destport);
|
local_destip, local_destport);
|
||||||
forwardsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
forwardsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if(forwardsock == LIBSSH2_INVALID_SOCKET) {
|
if(forwardsock == LIBSSH2_INVALID_SOCKET) {
|
||||||
fprintf(stderr, "failed to open forward socket.\n");
|
fprintf(stderr, "failed to open forward socket.\n");
|
||||||
@ -237,7 +237,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Forwarding connection from remote %s:%d to local %s:%d\n",
|
fprintf(stderr, "Forwarding connection from remote %s:%d to local %s:%d\n",
|
||||||
remote_listenhost, remote_listenport, local_destip, local_destport);
|
remote_listenhost, remote_listenport, local_destip, local_destport);
|
||||||
|
|
||||||
/* Must use non-blocking IO hereafter due to the current libssh2 API */
|
/* Must use non-blocking IO hereafter due to the current libssh2 API */
|
||||||
libssh2_session_set_blocking(session, 0);
|
libssh2_session_set_blocking(session, 0);
|
||||||
@ -261,7 +261,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if(len == 0) {
|
else if(len == 0) {
|
||||||
fprintf(stderr, "The local server at %s:%d disconnected.\n",
|
fprintf(stderr, "The local server at %s:%d disconnected.\n",
|
||||||
local_destip, local_destport);
|
local_destip, local_destport);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
wr = 0;
|
wr = 0;
|
||||||
@ -296,7 +296,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
if(libssh2_channel_eof(channel)) {
|
if(libssh2_channel_eof(channel)) {
|
||||||
fprintf(stderr, "The remote client at %s:%d disconnected.\n",
|
fprintf(stderr, "The remote client at %s:%d disconnected.\n",
|
||||||
remote_listenhost, remote_listenport);
|
remote_listenhost, remote_listenport);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user