summaryrefslogtreecommitdiff
path: root/src/dns_tlsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dns_tlsa.c')
-rw-r--r--src/dns_tlsa.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/dns_tlsa.c b/src/dns_tlsa.c
index 4b674c1..52f7d83 100644
--- a/src/dns_tlsa.c
+++ b/src/dns_tlsa.c
@@ -1,12 +1,13 @@
#include "byte.h"
+#include "logmsg.h"
#include "stralloc.h"
#include "uint_t.h"
+
#include "dns.h"
-#include "logmsg.h"
static char *q = 0;
-int dns_tlsa_packet(stralloc *out,const char *buf,unsigned int len)
+int dns_tlsa_packet(stralloc *out, const char *buf, unsigned int len)
{
unsigned int pos;
char header[12];
@@ -14,21 +15,25 @@ int dns_tlsa_packet(stralloc *out,const char *buf,unsigned int len)
uint16 numanswers;
int ranswers = 0;
- if (!stralloc_copys(out,"")) return DNS_MEM;
+ if (!stralloc_copys(out, "")) return DNS_MEM;
- pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return DNS_ERR;
- uint16_unpack_big(header + 6,&numanswers);
- pos = dns_packet_skipname(buf,len,pos); if (!pos) return DNS_ERR;
+ pos = dns_packet_copy(buf, len, 0, header, 12);
+ if (!pos) return DNS_ERR;
+ uint16_unpack_big(header + 6, &numanswers);
+ pos = dns_packet_skipname(buf, len, pos);
+ if (!pos) return DNS_ERR;
pos += 4;
while (numanswers--) {
- pos = dns_packet_skipname(buf,len,pos); if (!pos) return DNS_ERR;
- pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return DNS_ERR;
- uint16_unpack_big(header + 8,&datalen);
- if (byte_equal(header,2,DNS_T_TLSA))
- if (byte_equal(header + 2,2,DNS_C_IN)) {
+ pos = dns_packet_skipname(buf, len, pos);
+ if (!pos) return DNS_ERR;
+ pos = dns_packet_copy(buf, len, pos, header, 10);
+ if (!pos) return DNS_ERR;
+ uint16_unpack_big(header + 8, &datalen);
+ if (byte_equal(header, 2, DNS_T_TLSA))
+ if (byte_equal(header + 2, 2, DNS_C_IN)) {
if (pos + datalen > len) return DNS_ERR;
- if (!stralloc_catb(out,buf + pos,datalen)) return DNS_MEM;
+ if (!stralloc_catb(out, buf + pos, datalen)) return DNS_MEM;
}
pos += datalen;
++ranswers;
@@ -38,13 +43,13 @@ int dns_tlsa_packet(stralloc *out,const char *buf,unsigned int len)
return ranswers;
}
-int dns_tlsa(stralloc *out,const stralloc *fqdn)
+int dns_tlsa(stralloc *out, const stralloc *fqdn)
{
int rc = 0;
- if (dns_domain_fromdot(&q,fqdn->s,fqdn->len) <= 0) return DNS_ERR;
- if (dns_resolve(q,DNS_T_TLSA) >= 0) {
- if ((rc = dns_tlsa_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen)) < 0) return DNS_ERR;
+ if (dns_domain_fromdot(&q, fqdn->s, fqdn->len) <= 0) return DNS_ERR;
+ if (dns_resolve(q, DNS_T_TLSA) >= 0) {
+ if ((rc = dns_tlsa_packet(out, dns_resolve_tx.packet, dns_resolve_tx.packetlen)) < 0) return DNS_ERR;
dns_transmit_free(&dns_resolve_tx);
dns_domain_free(&q);
}