mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 09:39:20 +02:00
#3 fix issue with topdomain. Also make sure ping packet is type NULL
This commit is contained in:
parent
46d3053540
commit
da636b1f47
24
src/dns.c
24
src/dns.c
|
@ -37,11 +37,6 @@
|
|||
#include "encoding.h"
|
||||
#include "read.h"
|
||||
|
||||
static int decodepacket(const char*, char*, int);
|
||||
|
||||
/* XXX: remove this (used by server) and make topdomain static in iodine[d].c */
|
||||
extern char *topdomain;
|
||||
|
||||
int
|
||||
dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_t datalen)
|
||||
{
|
||||
|
@ -194,7 +189,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
|||
q->type = type;
|
||||
q->id = id;
|
||||
|
||||
rv = decodepacket(name, buf, buflen);
|
||||
rv = strlen(q->name);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -269,20 +264,3 @@ dnsd_send(int fd, struct query *q, char *data, int datalen)
|
|||
sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen);
|
||||
}
|
||||
|
||||
static int
|
||||
decodepacket(const char *name, char *buf, int buflen)
|
||||
{
|
||||
/*
|
||||
int len;
|
||||
char *domain;
|
||||
|
||||
domain = strstr(name, topdomain);
|
||||
|
||||
len = decode_data(buf, buflen, name, domain);
|
||||
if (len == buflen)
|
||||
return -1;
|
||||
return len;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,6 +174,11 @@ decode_data(char *dest, int size, const char *src, char *srcend)
|
|||
char *ep;
|
||||
|
||||
memset(encoded, 0, sizeof(encoded));
|
||||
memset(dest, 0, size);
|
||||
|
||||
// The first char is not Base32-encoded, just pass it through
|
||||
*dest++ = *src++;
|
||||
|
||||
ep = encoded;
|
||||
while(len < size && src < srcend) {
|
||||
if(*src == '.') {
|
||||
|
|
|
@ -269,6 +269,7 @@ send_ping(int fd)
|
|||
}
|
||||
|
||||
q.id = rand_seed;
|
||||
q.type = T_NULL;
|
||||
|
||||
data[0] = (rand_seed >> 8) & 0xff;
|
||||
data[1] = (rand_seed >> 0) & 0xff;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "dns.h"
|
||||
#include "login.h"
|
||||
#include "tun.h"
|
||||
#include "encoding.h"
|
||||
#include "version.h"
|
||||
|
||||
int running = 1;
|
||||
|
@ -246,8 +247,8 @@ read_dns(int fd, struct query *q, char *buf, int buflen)
|
|||
{
|
||||
struct sockaddr_in from;
|
||||
char packet[64*1024];
|
||||
char *domain;
|
||||
socklen_t addrlen;
|
||||
int len;
|
||||
int rv;
|
||||
int r;
|
||||
|
||||
|
@ -255,11 +256,11 @@ read_dns(int fd, struct query *q, char *buf, int buflen)
|
|||
r = recvfrom(fd, packet, sizeof(packet), 0, (struct sockaddr*)&from, &addrlen);
|
||||
|
||||
if (r > 0) {
|
||||
len = dns_decode(buf, buflen, q, QR_QUERY, packet, r);
|
||||
|
||||
dns_decode(buf, buflen, q, QR_QUERY, packet, r);
|
||||
domain = strstr(q->name, topdomain);
|
||||
rv = decode_data(buf, buflen, q->name, domain);
|
||||
q->fromlen = addrlen;
|
||||
memcpy((struct sockaddr*)&q->from, (struct sockaddr*)&from, addrlen);
|
||||
rv = len;
|
||||
} else if (r < 0) {
|
||||
/* Error */
|
||||
perror("recvfrom");
|
||||
|
|
|
@ -159,7 +159,6 @@ START_TEST(test_decode_query)
|
|||
q.id = 0;
|
||||
len = sizeof(queryPacket) - 1;
|
||||
|
||||
dns_set_topdomain("kryo.se");
|
||||
ret = dns_decode(buf, sizeof(buf), &q, QR_QUERY, queryPacket, len);
|
||||
|
||||
fail_unless(strncmp(buf, recData, ret) == 0, "Did not extract expected host: '%s'", buf);
|
||||
|
|
Loading…
Reference in New Issue