Skip to content

Commit

Permalink
fix vhook
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyao-lin committed Dec 12, 2018
1 parent ebd7bf3 commit 860ede5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/config/socks-vmess.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

[outbound]
proto = "vmess"
proxy = "127.0.0.1"
port = "3134"
proxy = "vm0"
port = "3133"
pass = "123456"
4 changes: 3 additions & 1 deletion app/vhook/hook.def
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ HOOK(connect, fd_t, (fd_t fd, const struct sockaddr *addr, socklen_t addrlen), {
flags = fcntl(fd, F_GETFL, 0);
fake_flags = fcntl(fake_fd, F_GETFL, 0);

// TRACE("%d %d", flags, fake_flags);

if (flags == -1 || fake_flags == -1) {
TRACE("unable to get fd flags");
return -1;
}

if (flags & O_NONBLOCK) {
fcntl(fake_fd, F_SETFL, fake_flags | O_NONBLOCK);
}
Expand Down
7 changes: 5 additions & 2 deletions proto/socks/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ _socks_tcp_socket_free(tcp_socket_t *_sock)
if (sock) {
target_id_free(sock->addr.proxy);

if (close(sock->sock)) {
perror("close");
if (sock->sock != -1) {
if (close(sock->sock)) {
perror("close");
}
}

free(sock);
Expand Down Expand Up @@ -412,6 +414,7 @@ fd_t
socks_to_socket(socks_tcp_socket_t *sock)
{
fd_t fd = sock->sock;
sock->sock = -1;
tcp_socket_free(sock);
return fd;
}

0 comments on commit 860ede5

Please sign in to comment.