From ff67d2568b968d1e2d00a5958c24003f3ad9097d Mon Sep 17 00:00:00 2001 From: aixiao Date: Mon, 13 May 2024 17:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forward-tunnel.c | 15 ++++++++++++--- forward-tunnel.h | 14 +++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/forward-tunnel.c b/forward-tunnel.c index c7ed723..850531d 100644 --- a/forward-tunnel.c +++ b/forward-tunnel.c @@ -52,6 +52,12 @@ void *forward_tunnel(void *sock_) return NULL; } + int optval = SO_REUSEADDR; + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) { + perror("setsockopt"); + return NULL; + } + memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(server_ssh_ip); @@ -283,8 +289,6 @@ int modif_argv(int argc, char *argv[]) int get_threads() { - - pid_t pid; char line[256]; char path[256]; @@ -379,6 +383,12 @@ int main(int argc, char *argv[], char **env) return -1; } + int optval = SO_REUSEADDR; + if (setsockopt(listensock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) { + perror("setsockopt"); + return -1; + } + sin.sin_family = AF_INET; sin.sin_port = htons(local_listenport); sin.sin_addr.s_addr = inet_addr(local_listenip); @@ -415,7 +425,6 @@ int main(int argc, char *argv[], char **env) return -1; } } - // 进程优先级 if (-1 == (nice_(-20))) perror("nice_"); diff --git a/forward-tunnel.h b/forward-tunnel.h index 6325841..a5f310d 100644 --- a/forward-tunnel.h +++ b/forward-tunnel.h @@ -19,11 +19,23 @@ #include #include -#define MAX_EVENTS 1024 +#include +#include +#include +#include +#include +#include +#include +#include +#include + + #define BUILD(fmt...) do { fprintf(stderr,"%s %s ",__DATE__,__TIME__); fprintf(stderr, ##fmt); } while(0) #ifndef INADDR_NONE #define INADDR_NONE (in_addr_t)-1 #endif + + #endif