add multi-config support

This commit is contained in:
Max Lv
2013-11-12 03:56:30 +00:00
committed by vagrant
parent 61cb96db3d
commit 4606acd773
7 changed files with 60 additions and 24 deletions
+13 -8
View File
@@ -751,7 +751,11 @@ static void accept_cb (EV_P_ ev_io *w, int revents)
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int index = rand() % listener->remote_num;
int err = getaddrinfo(listener->remote_host[index], listener->remote_port, &hints, &res);
if (verbose)
{
LOGD("connect to %s:%s", listener->remote_addr[index].host, listener->remote_addr[index].port);
}
int err = getaddrinfo(listener->remote_addr[index].host, listener->remote_addr[index].port, &hints, &res);
if (err)
{
ERROR("getaddrinfo");
@@ -804,7 +808,7 @@ int main (int argc, char **argv)
char *iface = NULL;
int remote_num = 0;
char *remote_host[MAX_REMOTE_NUM];
remote_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
opterr = 0;
@@ -814,7 +818,8 @@ int main (int argc, char **argv)
switch (c)
{
case 's':
remote_host[remote_num++] = optarg;
remote_addr[remote_num].host = optarg;
remote_addr[remote_num++].port = NULL;
break;
case 'p':
remote_port = optarg;
@@ -867,7 +872,7 @@ int main (int argc, char **argv)
remote_num = conf->remote_num;
for (i = 0; i < remote_num; i++)
{
remote_host[i] = conf->remote_host[i];
remote_addr[i] = conf->remote_addr[i];
}
}
if (remote_port == NULL) remote_port = conf->remote_port;
@@ -922,13 +927,13 @@ int main (int argc, char **argv)
// Setup proxy context
struct listen_ctx listen_ctx;
listen_ctx.remote_num = remote_num;
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
listen_ctx.remote_addr = malloc(sizeof(remote_addr_t) * remote_num);
while (remote_num > 0)
{
int index = --remote_num;
listen_ctx.remote_host[index] = remote_host[index];
if (remote_addr[index].port == NULL) remote_addr[index].port = remote_port;
listen_ctx.remote_addr[index] = remote_addr[index];
}
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;
listen_ctx.iface = iface;
@@ -946,7 +951,7 @@ int main (int argc, char **argv)
if (udprelay)
{
LOGD("udprelay enabled.");
udprelay_init(local_addr, local_port, remote_host[0], remote_port, m, iface);
udprelay_init(local_addr, local_port, remote_addr[0].host, remote_addr[0].port, m, iface);
}
ev_run (loop, 0);