1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-22 13:06:06 +03:00
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];
// Current IP packet
char activepacket[4096];
int packetlen;
char activepacket[4096];
int outbuflen;
char outbuf[64*1024];
static int
readname(char *packet, char *dst, char *src)
@ -159,6 +162,20 @@ host2dns(const char *host, char *buffer, int size)
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
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_haspacket();
void dnsd_queuepacket(const char *, const int);
#endif /* _DNSD_H_ */

View File

@ -21,6 +21,8 @@
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <err.h>
#include "tun.h"
@ -31,6 +33,7 @@
int running = 1;
static void
sigint(int sig) {
running = 0;
@ -42,7 +45,7 @@ tunnel(int tun_fd, int dns_fd)
int i;
int read;
fd_set fds;
char buf[1024];
char buf[64*1024];
struct timeval tv;
while (running) {
@ -50,7 +53,8 @@ tunnel(int tun_fd, int dns_fd)
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(tun_fd, &fds);
if(!dnsd_haspacket())
FD_SET(tun_fd, &fds);
FD_SET(dns_fd, &fds);
i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv);
@ -64,10 +68,23 @@ tunnel(int tun_fd, int dns_fd)
if(i != 0) {
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)) {
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)
{
if (write(tun_fd, buf, len) != len) {
warn("write_tun: %s", strerror(errno));
warn("write_tun");
return 1;
}