From c7ea350724f44c614df513c7fc80b34367bb7260 Mon Sep 17 00:00:00 2001 From: Mark Janssen Date: Fri, 9 Mar 2007 00:25:30 +0000 Subject: [PATCH] cygwin/daemon_mode related changes by Marc (dot) Heuse (at) ecb (dot) int git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@149 bc163920-b10d-0410-b2c5-a5491ca2ceef --- Makefile | 7 +++++-- proxytunnel.c | 16 +++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 0fd8ac3..a86742f 100755 --- a/Makefile +++ b/Makefile @@ -4,11 +4,14 @@ CC ?= cc CFLAGS ?= -Wall -O2 -ggdb -CFLAGS += -DHAVE_GETOPT_LONG # Comment on non-gnu systems -CFLAGS += -DUSE_SSL # Comment if you don't have/want ssl +CFLAGS += -DHAVE_GETOPT_LONG # Comment on non-gnu systems +CFLAGS += -DUSE_SSL # Comment if you don't have/want ssl # Most systems CFLAGS += -DSETPROCTITLE -DSPT_TYPE=2 +# Testing new flags +CFLAGS += -DSO_REUSEPORT # Comment if you don't have this flag + # System dependant blocks... if your system is listed below, uncomment # the relevant lines diff --git a/proxytunnel.c b/proxytunnel.c index 5939a49..d669ee7 100755 --- a/proxytunnel.c +++ b/proxytunnel.c @@ -165,6 +165,7 @@ void closeall() { void do_daemon() { int listen_sd; + int one = 1; struct sockaddr_in sa_serv; struct sockaddr_in sa_cli; socklen_t client_len; @@ -176,19 +177,24 @@ void do_daemon() /* Socket descriptor */ int sd; - - if ( ( listen_sd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) + if ( ( listen_sd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) < 0 ) { my_perror( "Server socket creation failed" ); exit(1); } +#ifdef SO_REUSEPORT /* doesnt exist everywhere... */ + setsockopt(listen_sd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof (one)); +#endif + setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + + memset( &sa_serv, '\0', sizeof( sa_serv ) ); sa_serv.sin_family = AF_INET; - sa_serv.sin_addr.s_addr = INADDR_ANY; + sa_serv.sin_addr.s_addr = htonl(INADDR_ANY); sa_serv.sin_port = htons( args_info.standalone_arg ); - if ( bind( listen_sd, (struct sockaddr * )&sa_serv, sizeof( sa_serv ) ) < 0) + if ( bind( listen_sd, (struct sockaddr * )&sa_serv, sizeof( struct sockaddr ) ) < 0) { my_perror("Server socket bind failed"); exit(1); @@ -228,7 +234,7 @@ void do_daemon() i_am_daemon = 1; #endif /* CYGWIN */ atexit( closeall ); - listen( listen_sd, 5 ); + listen( listen_sd, 8 ); while (1==1) {