This commit is contained in:
Bjorn Andersson 2006-06-05 22:36:05 +00:00
parent 8695b82cdf
commit 558a29f79c
4 changed files with 42 additions and 5 deletions

19
dnsd.c
View file

@ -36,8 +36,11 @@ struct sockaddr_in peer;
char topdomain[256]; char topdomain[256];
// Current IP packet // Current IP packet
char activepacket[4096];
int packetlen; int packetlen;
char activepacket[4096];
int outbuflen;
char outbuf[64*1024];
static int static int
readname(char *packet, char *dst, char *src) readname(char *packet, char *dst, char *src)
@ -159,6 +162,20 @@ host2dns(const char *host, char *buffer, int size)
return p - buffer; return p - buffer;
} }
int
dnsd_haspacket()
{
return (outbuflen > 0);
}
void
dnsd_queuepacket(const char *buf, const int buflen)
{
memcpy(outbuf, buf, buflen);
outbuflen = buflen;
}
static void static void
dnsd_respond(int fd, short id, struct sockaddr_in from) dnsd_respond(int fd, short id, struct sockaddr_in from)
{ {

3
dnsd.h
View file

@ -24,5 +24,8 @@ void close_dnsd(int);
int dnsd_read(int, char *, int); int dnsd_read(int, char *, int);
int dnsd_haspacket();
void dnsd_queuepacket(const char *, const int);
#endif /* _DNSD_H_ */ #endif /* _DNSD_H_ */

View file

@ -21,6 +21,8 @@
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h> #include <err.h>
#include "tun.h" #include "tun.h"
@ -31,6 +33,7 @@
int running = 1; int running = 1;
static void static void
sigint(int sig) { sigint(int sig) {
running = 0; running = 0;
@ -42,7 +45,7 @@ tunnel(int tun_fd, int dns_fd)
int i; int i;
int read; int read;
fd_set fds; fd_set fds;
char buf[1024]; char buf[64*1024];
struct timeval tv; struct timeval tv;
while (running) { while (running) {
@ -50,6 +53,7 @@ tunnel(int tun_fd, int dns_fd)
tv.tv_usec = 0; tv.tv_usec = 0;
FD_ZERO(&fds); FD_ZERO(&fds);
if(!dnsd_haspacket())
FD_SET(tun_fd, &fds); FD_SET(tun_fd, &fds);
FD_SET(dns_fd, &fds); FD_SET(dns_fd, &fds);
@ -64,10 +68,23 @@ tunnel(int tun_fd, int dns_fd)
if(i != 0) { if(i != 0) {
if(FD_ISSET(tun_fd, &fds)) { if(FD_ISSET(tun_fd, &fds)) {
read = read_tun(tun_fd, buf, sizeof(buf));
if(read > 0)
dnsd_queuepacket(buf, read);
} }
if(FD_ISSET(dns_fd, &fds)) { if(FD_ISSET(dns_fd, &fds)) {
read = dnsd_read(dns_fd, buf, sizeof(buf)); read = dnsd_read(dns_fd, buf, sizeof(buf));
int fd;
if(read > 0) {
fd = open("moo", O_WRONLY | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH);
write(fd, buf, read);
close(fd);
}
/*
if(read > 0)
write_tun(tun_fd, buf, read);
*/
} }
} }
} }

2
tun.c
View file

@ -121,7 +121,7 @@ int
write_tun(int tun_fd, uint8_t *buf, int len) write_tun(int tun_fd, uint8_t *buf, int len)
{ {
if (write(tun_fd, buf, len) != len) { if (write(tun_fd, buf, len) != len) {
warn("write_tun: %s", strerror(errno)); warn("write_tun");
return 1; return 1;
} }