Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

socks5-proxy won't compile under windows #1293

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions samples/socks5-proxy/build.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
{
'targets': [
{
'dependencies': ['../../uv.gyp:libuv'],
'target_name': 's5-proxy',
'type': 'executable',
'sources': [
'variables': {'uv_library': 'static'},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably try placing this above the targets:

'variables': {
  'uv_library': 'static'
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all right

'dependencies': ['../../uv.gyp:libuv'],
'target_name': 's5-proxy',
'type': 'executable',
'sources': [
'client.c',
'defs.h',
'main.c',
Expand Down
16 changes: 7 additions & 9 deletions samples/socks5-proxy/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int do_kill(client_ctx *cx);
static int do_almost_dead(client_ctx *cx);
static int conn_cycle(const char *who, conn *a, conn *b);
static void conn_timer_reset(conn *c);
static void conn_timer_expire(uv_timer_t *handle, int status);
static void conn_timer_expire(uv_timer_t *handle);
static void conn_getaddrinfo(conn *c, const char *hostname);
static void conn_getaddrinfo_done(uv_getaddrinfo_t *req,
int status,
Expand Down Expand Up @@ -530,7 +530,7 @@ static int do_kill(client_ctx *cx) {
new_state = s_almost_dead_1;
if (cx->state == s_req_lookup) {
new_state = s_almost_dead_0;
uv_cancel(&cx->outgoing.t.req);
uv_cancel(&cx->outgoing.req);
}

conn_close(&cx->incoming);
Expand Down Expand Up @@ -582,10 +582,8 @@ static void conn_timer_reset(conn *c) {
0));
}

static void conn_timer_expire(uv_timer_t *handle, int status) {
static void conn_timer_expire(uv_timer_t *handle) {
conn *c;

CHECK(0 == status);
c = CONTAINER_OF(handle, conn, timer_handle);
c->result = UV_ETIMEDOUT;
do_next(c->client);
Expand All @@ -599,7 +597,7 @@ static void conn_getaddrinfo(conn *c, const char *hostname) {
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
CHECK(0 == uv_getaddrinfo(c->client->sx->loop,
&c->t.addrinfo_req,
&c->addrinfo_req,
conn_getaddrinfo_done,
hostname,
NULL,
Expand All @@ -612,7 +610,7 @@ static void conn_getaddrinfo_done(uv_getaddrinfo_t *req,
struct addrinfo *ai) {
conn *c;

c = CONTAINER_OF(req, conn, t.addrinfo_req);
c = CONTAINER_OF(req, conn, addrinfo_req);
c->result = status;

if (status == 0) {
Expand All @@ -635,7 +633,7 @@ static int conn_connect(conn *c) {
ASSERT(c->t.addr.sa_family == AF_INET ||
c->t.addr.sa_family == AF_INET6);
conn_timer_reset(c);
return uv_tcp_connect(&c->t.connect_req,
return uv_tcp_connect(&c->connect_req,
&c->handle.tcp,
&c->t.addr,
conn_connect_done);
Expand All @@ -648,7 +646,7 @@ static void conn_connect_done(uv_connect_t *req, int status) {
return; /* Handle has been closed. */
}

c = CONTAINER_OF(req, conn, t.connect_req);
c = CONTAINER_OF(req, conn, connect_req);
c->result = status;
do_next(c->client);
}
Expand Down
10 changes: 6 additions & 4 deletions samples/socks5-proxy/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
#include "uv.h"

#include <assert.h>
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */
#include <stddef.h> /* size_t, ssize_t */
#include <stdint.h>
#if !defined(_WIN32)
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */
#include <sys/socket.h> /* sockaddr */
#endif

struct client_ctx;

Expand Down Expand Up @@ -59,11 +61,11 @@ typedef struct {
} handle;
uv_timer_t timer_handle; /* For detecting timeouts. */
uv_write_t write_req;
uv_getaddrinfo_t addrinfo_req;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function conn_connect (client.c@634) calls
return uv_tcp_connect(&c->t.connect_req,
&c->handle.tcp,
&c->t.addr,
conn_connect_done);

uv_tcp_connect will reset the connect_req struct (tcp.c@725) but this memory address is share with addr,addr4,addr6, doing so will leads in rewritting the tcp address with junk data, that's why I moved the three req structs outside the union to prevent this behavior.

uv_connect_t connect_req;
uv_req_t req;
/* We only need one of these at a time so make them share memory. */
union {
uv_getaddrinfo_t addrinfo_req;
uv_connect_t connect_req;
uv_req_t req;
struct sockaddr_in6 addr6;
struct sockaddr_in addr4;
struct sockaddr addr;
Expand Down
3 changes: 2 additions & 1 deletion samples/socks5-proxy/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(_WIN32)
#include <unistd.h>

#endif
extern const char *_getprogname(void);

int opterr = 1, /* if error message should be printed */
Expand Down
4 changes: 2 additions & 2 deletions samples/socks5-proxy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ const char *_getprogname(void) {
static void parse_opts(server_config *cf, int argc, char **argv) {
int opt;

while (-1 != (opt = getopt(argc, argv, "H:hp:"))) {
while (-1 != (opt = getopt(argc, argv, "b:hp:"))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D:...\socks5-proxy\build\Debug>s5-proxy.exe -h
Usage:

s5-proxy.exe [-b

] [-h] [-p ]

Options:

-b <hostname|address> Bind to this address or hostname.
Default: "127.0.0.1"
-h Show this help message.
-p Bind to this port number. Default: 1080

switch (opt) {
case 'H':
case 'b':
cf->bind_host = optarg;
break;

Expand Down
2 changes: 2 additions & 0 deletions samples/socks5-proxy/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
*/

#include "defs.h"
#if !defined(_WIN32)
#include <netinet/in.h> /* INET6_ADDRSTRLEN */
#endif
#include <stdlib.h>
#include <string.h>

Expand Down
1 change: 1 addition & 0 deletions samples/socks5-proxy/vcbuild.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python ..\..\gyp_uv.py build.gyp --generator-output=build