Skip to content

Commit

Permalink
Resolve problems connectings coming in via SOCKS
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwartzenberg committed Dec 22, 2023
1 parent 149d916 commit fe8dd28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ int prepare_http_connect(int sd, struct auth_s *credentials, const char *thost)
rr_data_t data2;
int rc = 0;
hlist_t tl;
char *pos;

if (!sd || !thost || !strlen(thost))
return 0;
Expand All @@ -519,6 +520,13 @@ int prepare_http_connect(int sd, struct auth_s *credentials, const char *thost)
data1->req = 1;
data1->method = strdup("CONNECT");
data1->url = strdup(thost);
data1->hostname = strdup(thost);
if ((pos = strchr(data1->hostname, ':')) != NULL) { // separate port
*pos = 0;
data1->port = atoi(pos + 1);
}
else
data1->port = 0;
data1->http = strdup("HTTP/1.1");
data1->headers = hlist_mod(data1->headers, "Proxy-Connection", "keep-alive", 1);

Expand Down Expand Up @@ -586,11 +594,15 @@ int forward_tunnel(void *thread_data) {
assert(thread_data != NULL);
int cd = ((struct thread_arg_s *)thread_data)->fd;
char *thost = ((struct thread_arg_s *)thread_data)->target;
char *thost_noport = strdup(thost);
char *pos;
char saddr[INET6_ADDRSTRLEN] = {0};
INET_NTOP(&((struct thread_arg_s *)thread_data)->addr, saddr, INET6_ADDRSTRLEN);

tcreds = new_auth();
sd = proxy_connect(tcreds, "/", thost);
if ((pos = strchr(thost_noport, ':')) != NULL) // separate port
*pos = 0;
sd = proxy_connect(tcreds, thost, thost_noport);

if (sd < 0)
goto bailout;
Expand Down
3 changes: 2 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,12 @@ void *socks5_thread(void *thread_data) {
i = (sd >= 0);
} else {
snprintf(tport, MINIBUF_SIZE, "%d", ntohs(port));
char *thost_noport = strdup(thost);
strlcat(thost, ":", HOST_BUFSIZE);
strlcat(thost, tport, HOST_BUFSIZE);

tcreds = new_auth();
sd = proxy_connect(tcreds, "/", thost);
sd = proxy_connect(tcreds, thost, thost_noport);
if (sd == -2) {
// remove previously added port to thost
char* t = thost;
Expand Down

0 comments on commit fe8dd28

Please sign in to comment.