优化
This commit is contained in:
parent
fd34266843
commit
1ea21b7bc6
BIN
forward-tunnel
BIN
forward-tunnel
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#include "forward-tunnel.h"
|
#include "forward-tunnel.h"
|
||||||
|
|
||||||
|
|
||||||
const char *keyfile1 = "/home/aixiao/.ssh/id_rsa.pub";
|
const char *keyfile1 = "/home/aixiao/.ssh/id_rsa.pub";
|
||||||
const char *keyfile2 = "/home/aixiao/.ssh/id_rsa";
|
const char *keyfile2 = "/home/aixiao/.ssh/id_rsa";
|
||||||
|
|
||||||
@ -199,8 +198,6 @@ void *forward_tunnel(void *sock_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
close(forwardsock);
|
close(forwardsock);
|
||||||
if (channel)
|
if (channel)
|
||||||
@ -211,7 +208,6 @@ shutdown:
|
|||||||
close(sock);
|
close(sock);
|
||||||
libssh2_exit();
|
libssh2_exit();
|
||||||
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -281,7 +277,6 @@ int main(int argc, char *argv[], char **env)
|
|||||||
char *client_ip = NULL;
|
char *client_ip = NULL;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
|
||||||
char optstring[] = ":dr:s:p:l:u:e:h?";
|
char optstring[] = ":dr:s:p:l:u:e:h?";
|
||||||
while (-1 != (opt = getopt(argc, argv, optstring))) {
|
while (-1 != (opt = getopt(argc, argv, optstring))) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
@ -300,8 +295,7 @@ int main(int argc, char *argv[], char **env)
|
|||||||
remote_desthost = optarg;
|
remote_desthost = optarg;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (NULL == (p = strchr(optarg, '.')))
|
if (NULL == (p = strchr(optarg, '.'))) {
|
||||||
{
|
|
||||||
remote_destport = atoi(optarg);
|
remote_destport = atoi(optarg);
|
||||||
remote_desthost = "0.0.0.0";
|
remote_desthost = "0.0.0.0";
|
||||||
} else {
|
} else {
|
||||||
@ -336,8 +330,7 @@ int main(int argc, char *argv[], char **env)
|
|||||||
// 加密参数(账号密码)
|
// 加密参数(账号密码)
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
|
|
||||||
if (0 == strcmp(argv[i], "-e") || 0 == strcmp(argv[i], "-u") || 0 == strcmp(argv[i], "-p"))
|
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--) {
|
for (j = strlen(argv[i + 1]) - 1; j >= 0; j--) {
|
||||||
argv[i + 1][j] = 'x';
|
argv[i + 1][j] = 'x';
|
||||||
}
|
}
|
||||||
@ -345,7 +338,6 @@ int main(int argc, char *argv[], char **env)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
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);
|
listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
@ -390,12 +382,10 @@ int main(int argc, char *argv[], char **env)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 进程优先级
|
// 进程优先级
|
||||||
if (-1 == (nice_(-20)))
|
if (-1 == (nice_(-20)))
|
||||||
perror("nice_");
|
perror("nice_");
|
||||||
|
|
||||||
|
|
||||||
// 多线程设置
|
// 多线程设置
|
||||||
pthread_t thread_id = 0;
|
pthread_t thread_id = 0;
|
||||||
pthread_attr_t attr;
|
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) {
|
if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0) {
|
||||||
printf("block sigpipe error\n");
|
printf("block sigpipe error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化线程属性
|
// 初始化线程属性
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
|
|
||||||
@ -438,7 +427,6 @@ int main(int argc, char *argv[], char **env)
|
|||||||
pthread_join(thread_id, NULL);
|
pthread_join(thread_id, NULL);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
close(forwardsock);
|
close(forwardsock);
|
||||||
close(listensock);
|
close(listensock);
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
|
|
||||||
#define MAX_EVENTS 1024
|
#define MAX_EVENTS 1024
|
||||||
|
BIN
forward-tunnel.o
BIN
forward-tunnel.o
Binary file not shown.
Loading…
Reference in New Issue
Block a user