From faea33eaaef157eda314b5d442246430b2520c3a Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 7 Jun 2007 18:57:18 +0000 Subject: [PATCH] Move dns_build_hostname to iodine.c --- src/dns.c | 24 ------------------------ src/dns.h | 2 -- src/iodine.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/dns.c b/src/dns.c index f50ffc8..6aada4f 100644 --- a/src/dns.c +++ b/src/dns.c @@ -188,27 +188,3 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz 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; -} - diff --git a/src/dns.h b/src/dns.h index 5a96f22..0ced1f1 100644 --- a/src/dns.h +++ b/src/dns.h @@ -24,8 +24,6 @@ typedef enum { QR_ANSWER = 1 } 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_decode(char *, size_t, struct query *, qr_t, char *, size_t); diff --git a/src/iodine.c b/src/iodine.c index 4ab917e..651bc0c 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -42,6 +42,9 @@ static void send_ping(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; char password[33]; @@ -78,12 +81,36 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen) 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)); 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 is_sending() { @@ -239,7 +266,7 @@ send_chunk(int fd) p += 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) code = 1;