This commit is contained in:
Bjorn Andersson 2006-08-24 22:12:45 +00:00
parent 432974300f
commit 2e6e493549

View File

@ -40,9 +40,6 @@
int running = 1; int running = 1;
int tun_fd;
int dns_fd;
static void static void
sighandler(int sig) { sighandler(int sig) {
running = 0; running = 0;
@ -51,13 +48,16 @@ sighandler(int sig) {
static int static int
tunnel(int tun_fd, int dns_fd) tunnel(int tun_fd, int dns_fd)
{ {
int i;
int read;
fd_set fds;
struct timeval tv;
char in[64*1024];
long outlen;
char out[64*1024]; char out[64*1024];
char in[64*1024];
struct timeval tv;
long outlen;
fd_set fds;
int read;
int i;
int rv;
rv = 0;
while (running) { while (running) {
tv.tv_sec = 1; tv.tv_sec = 1;
@ -70,11 +70,15 @@ tunnel(int tun_fd, int dns_fd)
i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv); i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv);
if(i < 0) { if (!running) {
if (running) { rv = 1;
warn("select"); break;
} }
return 1;
if(i < 0) {
warn("select");
rv = 1;
break;
} else if (i > 0) { } else if (i > 0) {
if(FD_ISSET(tun_fd, &fds)) { if(FD_ISSET(tun_fd, &fds)) {
read = read_tun(tun_fd, in, sizeof(in)); read = read_tun(tun_fd, in, sizeof(in));
@ -101,7 +105,7 @@ tunnel(int tun_fd, int dns_fd)
dns_ping(dns_fd); dns_ping(dns_fd);
} }
return 0; return rv;
} }
static int static int
@ -140,7 +144,8 @@ handshake(int dns_fd)
} }
if (read > 0) { if (read > 0) {
if (sscanf(in, "%[^-]-%[^-]-%d", server, client, &mtu) == 3) { if (sscanf(in, "%[^-]-%[^-]-%d",
server, client, &mtu) == 3) {
if (tun_setip(client) == 0 && tun_setmtu(mtu) == 0) if (tun_setip(client) == 0 && tun_setmtu(mtu) == 0)
return 0; return 0;
else else
@ -199,6 +204,8 @@ main(int argc, char **argv)
char *newroot; char *newroot;
char *device; char *device;
int choice; int choice;
int tun_fd;
int dns_fd;
username = NULL; username = NULL;
foreground = 0; foreground = 0;