Move readname() and READ macros out of dns[d].c

This commit is contained in:
Erik Ekman 2006-06-08 18:57:57 +00:00
parent b93577fbc0
commit b6d2d3a6bc
3 changed files with 4 additions and 100 deletions

View file

@ -1,8 +1,8 @@
CC = gcc
DNS = dnstun
DNSOBJS = dnstun.o tun.o dns.o
DNSOBJS = dnstun.o tun.o dns.o read.o
DNSD = dnstund
DNSDOBJS = dnstund.o tun.o dnsd.o
DNSDOBJS = dnstund.o tun.o dnsd.o read.o
OS = `uname | tr "a-z" "A-Z"`

50
dns.c
View file

@ -29,6 +29,7 @@
#include <ctype.h>
#include "dns.h"
#include "read.h"
static int host2dns(const char *, char *, int);
@ -44,55 +45,6 @@ uint16_t chunkid;
uint16_t pingid;
static int
readname(char *packet, char *dst, char *src)
{
char l;
int len;
int offset;
len = 0;
while(*src) {
l = *src++;
len++;
if(l & 0x80 && l & 0x40) {
offset = ((src[-1] & 0x3f) << 8) | src[0];
readname(packet, dst, packet + offset);
dst += strlen(dst);
break;
}
while(l) {
*dst++ = *src++;
l--;
len++;
}
*dst++ = '.';
}
*dst = '\0';
src++;
len++;
return len;
}
#define READNAME(packet, dst, src) (src) += readname((packet), (dst), (src));
#define READSHORT(dst, src) \
memcpy(&dst, src, 2); \
(dst) = ntohs(dst); (src)+=2;
#define READLONG(dst, src) \
memcpy(&dst, src, 2); \
(dst) = ntohl(dst); (src)+=4;
#define READDATA(dst, src, len) \
memcpy((dst), (src), (len)); (src)+=(len);
int
open_dns(const char *host, const char *domain)
{

50
dnsd.c
View file

@ -31,6 +31,7 @@
#include <fcntl.h>
#include "dns.h"
#include "read.h"
static int host2dns(const char *, char *, int);
@ -50,55 +51,6 @@ short delayed_q_id;
struct sockaddr_in delayed_q_from;
int delayed_q_fromlen;
static int
readname(char *packet, char *dst, char *src)
{
char l;
int len;
int offset;
len = 0;
while(*src) {
l = *src++;
len++;
if(l & 0x80 && l & 0x40) {
offset = ((src[-1] & 0x3f) << 8) | src[0];
readname(packet, dst, packet + offset);
dst += strlen(dst);
break;
}
while(l) {
*dst++ = *src++;
l--;
len++;
}
*dst++ = '.';
}
*dst = '\0';
src++;
len++;
return len;
}
#define READNAME(packet, dst, src) (src) += readname((packet), (dst), (src));
#define READSHORT(dst, src) \
memcpy(&dst, src, 2); \
(dst) = ntohs(dst); (src)+=2;
#define READLONG(dst, src) \
memcpy(&dst, src, 2); \
(dst) = ntohl(dst); (src)+=4;
#define READDATA(dst, src, len) \
memcpy((dst), (src), (len)); (src)+=(len);
int
open_dnsd(const char *domain)
{