From 00513a7d282ba2e92bd02ef78bf4c5d2a743c662 Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Wed, 12 Jul 2023 17:21:46 +0300 Subject: [PATCH] eliminate redundant code in previous fix --- src/socks.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/socks.c b/src/socks.c index 9a8f4c9..35cfc15 100644 --- a/src/socks.c +++ b/src/socks.c @@ -15,6 +15,17 @@ unsigned char * commands[] = {(unsigned char *)"UNKNOWN", (unsigned char *)"CONN #define BUFSIZE 1024 #define LARGEBUFSIZE 67000 +static void printcommand(unsigned char * buf, int command, struct clientparam *param){ + sprintf((char *)buf, "%s ", commands[command]); + if(param->hostname){ + sprintf((char *)buf + strlen((char *)buf), "%.265s", param->hostname); + } + else + myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)buf + strlen((char *)buf), 64); + sprintf((char *)buf+strlen((char *)buf), ":%hu", ntohs(*SAPORT(¶m->req))); + +} + void * sockschild(struct clientparam* param) { int res; unsigned i=0; @@ -207,13 +218,8 @@ void * sockschild(struct clientparam* param) { #ifndef WITHMAIN if(param->nreqfilters && buf){ int reqbufsize = BUFSIZE, reqsize, action; - sprintf((char *)buf, "%s ", commands[command]); - if(param->hostname){ - sprintf((char *)buf + strlen((char *)buf), "%.265s", param->hostname); - } - else - myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)buf + strlen((char *)buf), 64); - sprintf((char *)buf+strlen((char *)buf), ":%hu", ntohs(*SAPORT(¶m->req))); + + printcommand(buf, command, param); reqsize = strlen((char *)buf); action = handlereqfilters(param, &buf, &reqbufsize, 0, &reqsize); if(action == HANDLED){ @@ -488,13 +494,8 @@ fflush(stderr); if(command > 3) command = 0; if(buf){ - sprintf((char *)buf, "%s ", commands[command]); - if(param->hostname){ - sprintf((char *)buf + strlen((char *)buf), "%.265s", param->hostname); - } - else - myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)buf + strlen((char *)buf), 64); - sprintf((char *)buf+strlen((char *)buf), ":%hu", ntohs(*SAPORT(¶m->req))); + printcommand(buf, command, param); + dolog(param, buf); myfree(buf); }