Move dns_build_hostname to iodine.c

This commit is contained in:
Erik Ekman 2007-06-07 18:57:18 +00:00
parent 1d6d8287fe
commit faea33eaae
3 changed files with 29 additions and 28 deletions

View File

@ -188,27 +188,3 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
return rv; return rv;
} }
int
dns_build_hostname(char *buf, size_t buflen,
const char *data, const size_t datalen,
const char *topdomain)
{
int consumed;
int avail;
char *b;
avail = MIN(0xFF, buflen) - strlen(topdomain) - 2;
memset(buf, 0, buflen);
b = buf;
consumed = encode_data(data, datalen, avail, b);
b += strlen(buf);
if (*b != '.')
*b++ = '.';
strncpy(b, topdomain, strlen(topdomain)+1);
return consumed;
}

View File

@ -24,8 +24,6 @@ typedef enum {
QR_ANSWER = 1 QR_ANSWER = 1
} qr_t; } qr_t;
int dns_build_hostname(char *, size_t, const char *, const size_t, const char *);
int dns_encode(char *, size_t, struct query *, qr_t, char *, size_t); int dns_encode(char *, size_t, struct query *, qr_t, char *, size_t);
int dns_decode(char *, size_t, struct query *, qr_t, char *, size_t); int dns_decode(char *, size_t, struct query *, qr_t, char *, size_t);

View File

@ -42,6 +42,9 @@
static void send_ping(int fd); static void send_ping(int fd);
static void send_chunk(int fd); static void send_chunk(int fd);
static int build_hostname(char *buf, size_t buflen,
const char *data, const size_t datalen,
const char *topdomain);
int running = 1; int running = 1;
char password[33]; char password[33];
@ -78,12 +81,36 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
buf[0] = cmd; buf[0] = cmd;
len = dns_build_hostname(buf + 1, sizeof(buf) - 1, data, datalen, topdomain); len = build_hostname(buf + 1, sizeof(buf) - 1, data, datalen, topdomain);
len = dns_encode(packet, sizeof(packet), &q, QR_QUERY, buf, strlen(buf)); len = dns_encode(packet, sizeof(packet), &q, QR_QUERY, buf, strlen(buf));
sendto(fd, packet, len, 0, (struct sockaddr*)&peer, sizeof(peer)); sendto(fd, packet, len, 0, (struct sockaddr*)&peer, sizeof(peer));
} }
static int
build_hostname(char *buf, size_t buflen,
const char *data, const size_t datalen,
const char *topdomain)
{
int consumed;
int avail;
char *b;
avail = MIN(0xFF, buflen) - strlen(topdomain) - 2;
memset(buf, 0, buflen);
b = buf;
consumed = encode_data(data, datalen, avail, b);
b += strlen(buf);
if (*b != '.')
*b++ = '.';
strncpy(b, topdomain, strlen(topdomain)+1);
return consumed;
}
int int
is_sending() is_sending()
{ {
@ -239,7 +266,7 @@ send_chunk(int fd)
p += packetpos; p += packetpos;
avail = packetlen - packetpos; avail = packetlen - packetpos;
lastlen = dns_build_hostname(buf + 1, sizeof(buf) - 1, p, avail, topdomain); lastlen = build_hostname(buf + 1, sizeof(buf) - 1, p, avail, topdomain);
if (lastlen == avail) if (lastlen == avail)
code = 1; code = 1;