#include <sys_defs.h>
#include <string.h>
#include <vstring.h>
#include <msg.h>
#include <dns.h>
char *dns_strrecord(VSTRING *buf, DNS_RR *rr)
{
const char myname[] = "dns_strrecord";
MAI_HOSTADDR_STR host;
UINT32_TYPE soa_buf[5];
vstring_sprintf(buf, "%s. %u IN %s ",
rr->rname, rr->ttl, dns_strtype(rr->type));
switch (rr->type) {
case T_A:
#ifdef T_AAAA
case T_AAAA:
#endif
if (dns_rr_to_pa(rr, &host) == 0)
msg_fatal("%s: conversion error for resource record type %s: %m",
myname, dns_strtype(rr->type));
vstring_sprintf_append(buf, "%s", host.buf);
break;
case T_CNAME:
case T_DNAME:
case T_MB:
case T_MG:
case T_MR:
case T_NS:
case T_PTR:
vstring_sprintf_append(buf, "%s.", rr->data);
break;
case T_TXT:
vstring_sprintf_append(buf, "%s", rr->data);
break;
case T_MX:
vstring_sprintf_append(buf, "%u %s.", rr->pref, rr->data);
break;
case T_TLSA:
if (rr->data_len >= 3) {
uint8_t *ip = (uint8_t *) rr->data;
uint8_t usage = *ip++;
uint8_t selector = *ip++;
uint8_t mtype = *ip++;
unsigned i;
vstring_sprintf_append(buf, "%d %d %d ", usage, selector, mtype);
for (i = 3; i < rr->data_len; ++i)
vstring_sprintf_append(buf, "%02x", *ip++);
} else {
vstring_sprintf_append(buf, "[truncated record]");
}
case T_SOA:
memcpy(soa_buf, rr->data, sizeof(soa_buf));
vstring_sprintf_append(buf, "- - %u %u %u %u %u",
soa_buf[0], soa_buf[1], soa_buf[2],
soa_buf[3], soa_buf[4]);
break;
default:
msg_fatal("%s: don't know how to print type %s",
myname, dns_strtype(rr->type));
}
return (vstring_str(buf));
}