mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-29 09:21:27 +00:00
cleanup
This commit is contained in:
parent
e5d35b57bc
commit
3440a3f378
51
dnsd.c
51
dnsd.c
|
@ -230,7 +230,6 @@ dnsd_send(int fd, char *name, short type, short id, struct sockaddr_in from)
|
||||||
PUTLONG(0, p);
|
PUTLONG(0, p);
|
||||||
|
|
||||||
if(outbuflen > 0) {
|
if(outbuflen > 0) {
|
||||||
printf("%d\n", outid);
|
|
||||||
PUTSHORT(outbuflen, p);
|
PUTSHORT(outbuflen, p);
|
||||||
memcpy(p, outbuf, outbuflen);
|
memcpy(p, outbuf, outbuflen);
|
||||||
p += outbuflen;
|
p += outbuflen;
|
||||||
|
@ -239,7 +238,7 @@ dnsd_send(int fd, char *name, short type, short id, struct sockaddr_in from)
|
||||||
}
|
}
|
||||||
|
|
||||||
len = p - buf;
|
len = p - buf;
|
||||||
printf("Responding with %d\n", len);
|
// printf("Responding with %d\n", len);
|
||||||
sendto(fd, buf, len, 0, (struct sockaddr*)&from, sizeof(from));
|
sendto(fd, buf, len, 0, (struct sockaddr*)&from, sizeof(from));
|
||||||
|
|
||||||
outbuflen = 0;
|
outbuflen = 0;
|
||||||
|
@ -323,17 +322,10 @@ dnsd_read(int fd, char *buf, int buflen)
|
||||||
char packet[64*1024];
|
char packet[64*1024];
|
||||||
struct sockaddr_in from;
|
struct sockaddr_in from;
|
||||||
|
|
||||||
char lastblock;
|
|
||||||
char *np;
|
|
||||||
char *domainstart;
|
|
||||||
int namelen;
|
|
||||||
char *packetp;
|
|
||||||
int datalen;
|
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr);
|
addrlen = sizeof(struct sockaddr);
|
||||||
r = recvfrom(fd, packet, sizeof(packet), 0, (struct sockaddr*)&from, &addrlen);
|
r = recvfrom(fd, packet, sizeof(packet), 0, (struct sockaddr*)&from, &addrlen);
|
||||||
|
|
||||||
printf("Read %d bytes DNS query from %s\n", r, inet_ntoa(from.sin_addr));
|
//printf("Read %d bytes DNS query from %s\n", r, inet_ntoa(from.sin_addr));
|
||||||
|
|
||||||
if(r == -1) {
|
if(r == -1) {
|
||||||
perror("recvfrom");
|
perror("recvfrom");
|
||||||
|
@ -366,48 +358,9 @@ dnsd_read(int fd, char *buf, int buflen)
|
||||||
|
|
||||||
r = decodepacket(name, &packetbuf);
|
r = decodepacket(name, &packetbuf);
|
||||||
|
|
||||||
printf("r is %d\n", r);
|
|
||||||
|
|
||||||
memcpy(buf, packetbuf.data, r);
|
memcpy(buf, packetbuf.data, r);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
lastblock = name[0] - '0';
|
|
||||||
np = name;
|
|
||||||
np++; // skip first byte, it has only fragmentation info
|
|
||||||
domainstart = strstr(np, topdomain);
|
|
||||||
if (!domainstart) {
|
|
||||||
fprintf(stderr, "Resolved domain does not end with %s! Ignoring packet\n", topdomain);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
namelen = (int) domainstart - (int) np;
|
|
||||||
*domainstart = '\0';
|
|
||||||
packetp = activepacket;
|
|
||||||
packetp += packetlen;
|
|
||||||
while (np < domainstart && packetlen < sizeof(activepacket)) {
|
|
||||||
if (*np == '.') {
|
|
||||||
np++;
|
|
||||||
}
|
|
||||||
sscanf(np, "%02X", &r);
|
|
||||||
*packetp = r & 0xFF;
|
|
||||||
np += 2;
|
|
||||||
packetp++;
|
|
||||||
packetlen++;
|
|
||||||
}
|
|
||||||
if (lastblock && packetlen < 2) {
|
|
||||||
// Skipping ping packet
|
|
||||||
packetlen = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (lastblock) {
|
|
||||||
datalen = MIN(packetlen, buflen);
|
|
||||||
memcpy(buf, activepacket, datalen);
|
|
||||||
packetlen = 0;
|
|
||||||
printf("Got full packet, returning %d bytes!\n", datalen);
|
|
||||||
return datalen;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
dnstund.c
11
dnstund.c
|
@ -74,7 +74,10 @@ tunnel(int tun_fd, int dns_fd)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i != 0) {
|
if (i==0) {
|
||||||
|
if (dnsd_hasack())
|
||||||
|
dnsd_forceack(dns_fd);
|
||||||
|
} 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)
|
||||||
|
@ -92,12 +95,6 @@ tunnel(int tun_fd, int dns_fd)
|
||||||
write_tun(tun_fd, frame, read + 4);
|
write_tun(tun_fd, frame, read + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Timeout on select()
|
|
||||||
if (dnsd_hasack()) {
|
|
||||||
printf("Got no data, sending delayed ACK\n");
|
|
||||||
dnsd_forceack(dns_fd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue