From c869546ad8688dbb43329bd19e06e6ed8ac1e754 Mon Sep 17 00:00:00 2001 From: fadhil riyanto Date: Tue, 8 Oct 2024 16:31:12 +0700 Subject: add socks5 err code Signed-off-by: fadhil riyanto --- main2.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main2.c b/main2.c index 5d3ba02..9a49a56 100644 --- a/main2.c +++ b/main2.c @@ -617,6 +617,19 @@ static int start_unpack_packet(int fd, void* reserved, struct socks5_session *so return 1; } +/* + o X'00' succeeded + o X'01' general SOCKS server failure + o X'02' connection not allowed by ruleset + o X'03' Network unreachable + o X'04' Host unreachable + o X'05' Connection refused + o X'06' TTL expired + o X'07' Command not supported + o X'08' Address type not supported + o X'09' to X'FF' unassigned +*/ + static int create_server2server_conn(int *fdptr, int atyp, u_int8_t *addr, u_int16_t port) { int ret = 0; @@ -642,8 +655,15 @@ static int create_server2server_conn(int *fdptr, int atyp, u_int8_t *addr, u_int ret = connect(tcpfd, (struct sockaddr*)&serv_addr, len); if (ret == -1) { + ret = errno; + perror("connect()"); - return -1; + log_error("errno: %d", ret); + + if (ret == 101) { + return 3; + } + // return -1; } *fdptr = tcpfd; @@ -1061,6 +1081,9 @@ static int start_unpack_packet_no_epl(int fd, void* reserved, struct socks5_sess close(fd); return 0; } + } else { + socks5_send_connstate(fd, 3, next_req->atyp, next_req->dest, + next_req->port); } } } -- cgit v1.2.3 From 4ffdd52f3e02c8c1810f949813610ac0510aed5e Mon Sep 17 00:00:00 2001 From: fadhil riyanto Date: Tue, 8 Oct 2024 18:40:41 +0700 Subject: fix bug tcp transport fail Signed-off-by: fadhil riyanto --- main2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main2.c b/main2.c index 9a49a56..f661ec9 100644 --- a/main2.c +++ b/main2.c @@ -660,7 +660,7 @@ static int create_server2server_conn(int *fdptr, int atyp, u_int8_t *addr, u_int perror("connect()"); log_error("errno: %d", ret); - if (ret == 101) { + if (ret == 111) { return 3; } // return -1; -- cgit v1.2.3 From b7eccb556bee7d172fb1426ab51e36e441242835 Mon Sep 17 00:00:00 2001 From: fadhil riyanto Date: Tue, 8 Oct 2024 18:41:10 +0700 Subject: test timeout Signed-off-by: fadhil riyanto --- test/connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/connect.c b/test/connect.c index 5b2ddf3..94fcd07 100644 --- a/test/connect.c +++ b/test/connect.c @@ -14,8 +14,8 @@ int main(int argc, char *argv) struct sockaddr_in serv_addr; memset(&serv_addr, 0, sizeof(struct sockaddr_in)); - serv_addr.sin_addr.s_addr = inet_addr("93.184.215.14"); - serv_addr.sin_port = htons(443); + serv_addr.sin_addr.s_addr = inet_addr("192.168.2.2"); + serv_addr.sin_port = htons(3080); serv_addr.sin_family = AF_INET; socklen_t len = sizeof(struct sockaddr_in); -- cgit v1.2.3