Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ libc is not even 50 KB. that's easily usable even on the cheapest routers.
command line options
------------------------

microsocks -1 -i listenip -p port -u user -P password -b bindaddr
microsocks -1 -i listenip -p port -u user -P password -b bindaddr -B bindiface

all arguments are optional.
by default listenip is 0.0.0.0 and port 1080.
Expand Down
9 changes: 8 additions & 1 deletion sockssrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static sblist* auth_ips;
static pthread_mutex_t auth_ips_mutex = PTHREAD_MUTEX_INITIALIZER;
static const struct server* server;
static union sockaddr_union bind_addr = {.v4.sin_family = AF_UNSPEC};
static const char* bind_interface;

enum socksstate {
SS_1_CONNECTED,
Expand Down Expand Up @@ -165,6 +166,8 @@ static int connect_socks_target(unsigned char *buf, size_t n, struct client *cli
return -EC_GENERAL_FAILURE;
}
}
if(bind_interface && setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, bind_interface, strlen(bind_interface)) == -1)
goto eval_errno;
if(SOCKADDR_UNION_AF(&bind_addr) != AF_UNSPEC && bindtoip(fd, &bind_addr) == -1)
goto eval_errno;
if(connect(fd, remote->ai_addr, remote->ai_addrlen) == -1)
Expand Down Expand Up @@ -384,14 +387,18 @@ int main(int argc, char** argv) {
int ch;
const char *listenip = "0.0.0.0";
unsigned port = 1080;
while((ch = getopt(argc, argv, ":1b:i:p:u:P:")) != -1) {
while((ch = getopt(argc, argv, ":1b:B:i:p:u:P:")) != -1) {
switch(ch) {
case '1':
auth_ips = sblist_new(sizeof(union sockaddr_union), 8);
break;
case 'b':
resolve_sa(optarg, 0, &bind_addr);
break;
case 'B':
bind_interface = strdup(optarg);
zero_arg(optarg);
break;
case 'u':
auth_user = strdup(optarg);
zero_arg(optarg);
Expand Down