mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-27 12:05:15 +00:00
zlib
This commit is contained in:
parent
cbfab201b8
commit
f9a2f07e11
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ DNSDOBJS = dnstund.o tun.o dnsd.o
|
|||||||
|
|
||||||
OS = `uname | tr "a-z" "A-Z"`
|
OS = `uname | tr "a-z" "A-Z"`
|
||||||
|
|
||||||
LDFLAGS =
|
LDFLAGS = -lz
|
||||||
CFLAGS = -c -g -Wall -D$(OS)
|
CFLAGS = -c -g -Wall -D$(OS)
|
||||||
|
|
||||||
all: stateos $(DNS) $(DNSD)
|
all: stateos $(DNS) $(DNSD)
|
||||||
|
13
dnstun.c
13
dnstun.c
@ -25,6 +25,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "tun.h"
|
#include "tun.h"
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
@ -50,6 +51,8 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
fd_set fds;
|
fd_set fds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct tun_frame *frame;
|
struct tun_frame *frame;
|
||||||
|
long buflen;
|
||||||
|
char buf[64*1024];
|
||||||
|
|
||||||
frame = malloc(FRAMESIZE);
|
frame = malloc(FRAMESIZE);
|
||||||
|
|
||||||
@ -77,13 +80,17 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
if(FD_ISSET(tun_fd, &fds)) {
|
if(FD_ISSET(tun_fd, &fds)) {
|
||||||
read = read_tun(tun_fd, frame, FRAMESIZE);
|
read = read_tun(tun_fd, frame, FRAMESIZE);
|
||||||
if (read > 0) {
|
if (read > 0) {
|
||||||
printf("Got data on tun! %d bytes\n", read);
|
buflen = sizeof(buf);
|
||||||
dns_handle_tun(dns_fd, frame->data, read - 4);
|
compress2(buf, &buflen, frame->data, read - 4, 9);
|
||||||
|
dns_handle_tun(dns_fd, buf, buflen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(FD_ISSET(dns_fd, &fds)) {
|
if(FD_ISSET(dns_fd, &fds)) {
|
||||||
read = dns_read(dns_fd, frame->data, FRAMESIZE-4);
|
read = dns_read(dns_fd, frame->data, FRAMESIZE-4);
|
||||||
if (read > 0) {
|
if (read > 0) {
|
||||||
|
buflen = 64*1024-4;
|
||||||
|
uncompress(frame->data, &buflen, buf, read);
|
||||||
|
|
||||||
printf("Got data on dns! %d bytes\n", read);
|
printf("Got data on dns! %d bytes\n", read);
|
||||||
|
|
||||||
frame->flags = htons(0x0000);
|
frame->flags = htons(0x0000);
|
||||||
@ -93,7 +100,7 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
frame->proto = htons(0x0002); // BSD wants AF_INET as long word
|
frame->proto = htons(0x0002); // BSD wants AF_INET as long word
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
write_tun(tun_fd, frame, read + 4);
|
write_tun(tun_fd, frame, buflen + 4);
|
||||||
if (!dns_sending()) {
|
if (!dns_sending()) {
|
||||||
dns_ping(dns_fd);
|
dns_ping(dns_fd);
|
||||||
}
|
}
|
||||||
|
17
dnstund.c
17
dnstund.c
@ -25,6 +25,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "tun.h"
|
#include "tun.h"
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
@ -49,6 +50,8 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
fd_set fds;
|
fd_set fds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct tun_frame *frame;
|
struct tun_frame *frame;
|
||||||
|
long buflen;
|
||||||
|
char buf[64*1024];
|
||||||
|
|
||||||
frame = malloc(64*1024);
|
frame = malloc(64*1024);
|
||||||
|
|
||||||
@ -80,19 +83,25 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
} else {
|
} else {
|
||||||
if(FD_ISSET(tun_fd, &fds)) {
|
if(FD_ISSET(tun_fd, &fds)) {
|
||||||
read = read_tun(tun_fd, frame, 64*1024);
|
read = read_tun(tun_fd, frame, 64*1024);
|
||||||
if(read > 0)
|
if(read > 0) {
|
||||||
dnsd_queuepacket(frame->data, read - 4);
|
buflen = sizeof(buf);
|
||||||
|
compress2(buf, &buflen, frame->data, read - 4, 9);
|
||||||
|
dnsd_queuepacket(buf, buflen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(FD_ISSET(dns_fd, &fds)) {
|
if(FD_ISSET(dns_fd, &fds)) {
|
||||||
read = dnsd_read(dns_fd, frame->data, 64*1024-4);
|
read = dnsd_read(dns_fd, buf, 64*1024-4);
|
||||||
if(read > 0) {
|
if(read > 0) {
|
||||||
|
buflen = 64*1024-4;
|
||||||
|
uncompress(frame->data, &buflen, buf, read);
|
||||||
|
|
||||||
frame->flags = htons(0x0000);
|
frame->flags = htons(0x0000);
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
frame->proto = htons(0x0800);
|
frame->proto = htons(0x0800);
|
||||||
#else
|
#else
|
||||||
frame->proto = htons(0x0002);
|
frame->proto = htons(0x0002);
|
||||||
#endif
|
#endif
|
||||||
write_tun(tun_fd, frame, read + 4);
|
write_tun(tun_fd, frame, buflen + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user