Move dns_build_hostname to iodine.c
This commit is contained in:
parent
1d6d8287fe
commit
faea33eaae
24
src/dns.c
24
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
31
src/iodine.c
31
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;
|
||||
|
|
Loading…
Reference in New Issue