mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-27 12:05:15 +00:00
server
This commit is contained in:
parent
8695b82cdf
commit
558a29f79c
19
dnsd.c
19
dnsd.c
@ -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
3
dnsd.h
@ -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_ */
|
||||
|
23
dnstund.c
23
dnstund.c
@ -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);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user