This commit is contained in:
aixiao 2024-01-03 09:19:09 +08:00
parent fd34266843
commit 1ea21b7bc6
4 changed files with 26 additions and 39 deletions

Binary file not shown.

View File

@ -1,6 +1,5 @@
#include "forward-tunnel.h"
const char *keyfile1 = "/home/aixiao/.ssh/id_rsa.pub";
const char *keyfile2 = "/home/aixiao/.ssh/id_rsa";
@ -136,16 +135,16 @@ void *forward_tunnel(void *sock_)
while (1) {
FD_ZERO(&fds);
FD_SET(forwardsock, &fds); // 设置一个描述符
FD_SET(forwardsock, &fds); // 设置一个描述符
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = select(forwardsock + 1, &fds, NULL, NULL, &tv);
if (-1 == rc) { // 返回-1表示出错
if (-1 == rc) { // 返回-1表示出错
perror("select");
goto shutdown;
}
if (rc && FD_ISSET(forwardsock, &fds)) { // 测试某一个描述符返回值: 若fd在描述符集中则返回非0,否则返回0
if (rc && FD_ISSET(forwardsock, &fds)) { // 测试某一个描述符返回值: 若fd在描述符集中则返回非0,否则返回0
len = read(forwardsock, buffer, sizeof(buffer));
if (len < 0) {
perror("read");
@ -199,8 +198,6 @@ void *forward_tunnel(void *sock_)
}
}
shutdown:
close(forwardsock);
if (channel)
@ -211,7 +208,6 @@ shutdown:
close(sock);
libssh2_exit();
return NULL;
}
@ -261,7 +257,7 @@ static char help_info(void)
return 0;
}
int nice_( int increment)
int nice_(int increment)
{
int oldprio = getpriority(PRIO_PROCESS, getpid());
printf("%d\n", oldprio);
@ -281,7 +277,6 @@ int main(int argc, char *argv[], char **env)
char *client_ip = NULL;
int i, j;
char optstring[] = ":dr:s:p:l:u:e:h?";
while (-1 != (opt = getopt(argc, argv, optstring))) {
switch (opt) {
@ -300,9 +295,8 @@ int main(int argc, char *argv[], char **env)
remote_desthost = optarg;
} else {
if (NULL == (p = strchr(optarg, '.')))
{
remote_destport =atoi(optarg);
if (NULL == (p = strchr(optarg, '.'))) {
remote_destport = atoi(optarg);
remote_desthost = "0.0.0.0";
} else {
help_info();
@ -336,16 +330,14 @@ int main(int argc, char *argv[], char **env)
// 加密参数(账号密码)
for (i = 1; i < argc; i++) {
if (0 == strcmp(argv[i], "-e") || 0 == strcmp(argv[i], "-u") || 0 == strcmp(argv[i], "-p"))
{
for (j = strlen(argv[i+1]) - 1; j >= 0; j--) {
argv[i+1][j] = 'x';
if (0 == strcmp(argv[i], "-e") || 0 == strcmp(argv[i], "-u") || 0 == strcmp(argv[i], "-p")) {
for (j = strlen(argv[i + 1]) - 1; j >= 0; j--) {
argv[i + 1][j] = 'x';
}
}
}
printf("SSH Server: %s:%d, Local listen: %s:%d, User&Passwd: [%s]['%s']\n", server_ssh_ip, remote_destport, local_listenip, local_listenport, server_ssh_user, server_ssh_passwd);
listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
@ -390,12 +382,10 @@ int main(int argc, char *argv[], char **env)
return -1;
}
}
// 进程优先级
if (-1 == (nice_(-20)))
perror("nice_");
// 多线程设置
pthread_t thread_id = 0;
pthread_attr_t attr;
@ -406,7 +396,6 @@ int main(int argc, char *argv[], char **env)
if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0) {
printf("block sigpipe error\n");
}
// 初始化线程属性
pthread_attr_init(&attr);
@ -438,7 +427,6 @@ int main(int argc, char *argv[], char **env)
pthread_join(thread_id, NULL);
pthread_exit(NULL);
shutdown:
close(forwardsock);
close(listensock);

View File

@ -19,7 +19,6 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/poll.h>
#define MAX_EVENTS 1024

Binary file not shown.