Skip to content

Commit e3e0f2a

Browse files
authored
Merge pull request #2390 from rivoreo/ss-local-verbose
Make ss-local(1) more verbose in verbose mode
2 parents dc4742b + 63a991c commit e3e0f2a

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/local.c

+27-5
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ server_handshake(EV_P_ ev_io *w, buffer_t *buf)
353353
}
354354
return server_handshake_reply(EV_A_ w, 1, &response);
355355
} else if (request->cmd != SOCKS5_CMD_CONNECT) {
356-
LOGE("unsupported cmd: %d", request->cmd);
356+
LOGE("unsupported command: %d", request->cmd);
357357
response.rep = SOCKS5_REP_CMD_NOT_SUPPORTED;
358358
char *send_buf = (char *)&response;
359359
send(server->fd, send_buf, 4, 0);
@@ -876,6 +876,13 @@ server_recv_cb(EV_P_ ev_io *w, int revents)
876876
// all processed
877877
return;
878878
} else if (server->stage == STAGE_INIT) {
879+
if(verbose) {
880+
struct sockaddr_in peer_addr;
881+
socklen_t peer_addr_len = sizeof peer_addr;
882+
if(getpeername(server->fd, (struct sockaddr *)&peer_addr, &peer_addr_len) == 0) {
883+
LOGI("connection from %s:%hu", inet_ntoa(peer_addr.sin_addr), ntohs(peer_addr.sin_port));
884+
}
885+
}
879886
if (buf->len < 1)
880887
return;
881888
if (buf->data[0] != SVERSION) {
@@ -1359,6 +1366,11 @@ create_remote(listen_ctx_t *listener,
13591366
memcpy(&(remote->addr), remote_addr, remote->addr_len);
13601367
remote->direct = direct;
13611368

1369+
if(verbose) {
1370+
struct sockaddr_in *sockaddr = (struct sockaddr_in *)&remote->addr;
1371+
LOGI("remote: %s:%hu", inet_ntoa(sockaddr->sin_addr), ntohs(sockaddr->sin_port));
1372+
}
1373+
13621374
return remote;
13631375
}
13641376

@@ -1685,12 +1697,22 @@ main(int argc, char **argv)
16851697
}
16861698
}
16871699

1688-
if (remote_num == 0 || remote_port == NULL ||
1700+
if(remote_num == 0) {
1701+
fprintf(stderr, "remote_num is 0\n");
1702+
exit(EXIT_FAILURE);
1703+
}
1704+
if(!remote_port) {
1705+
fprintf(stderr, "remote_port is NULL\n");
1706+
exit(EXIT_FAILURE);
1707+
}
16891708
#ifndef HAVE_LAUNCHD
1690-
local_port == NULL ||
1709+
if(!local_port) {
1710+
fprintf(stderr, "local_port is NULL\n");
1711+
exit(EXIT_FAILURE);
1712+
}
16911713
#endif
1692-
(password == NULL && key == NULL)) {
1693-
usage();
1714+
if(!password && !key) {
1715+
fprintf(stderr, "both password and key are NULL\n");
16941716
exit(EXIT_FAILURE);
16951717
}
16961718

0 commit comments

Comments
 (0)