#3 fix issue with topdomain. Also make sure ping packet is type NULL

This commit is contained in:
Erik Ekman 2007-02-04 23:08:09 +00:00
parent 46d3053540
commit da636b1f47
5 changed files with 12 additions and 28 deletions

View file

@ -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;
}

View file

@ -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 == '.') {

View file

@ -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;

View file

@ -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");

View file

@ -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);