summaryrefslogtreecommitdiff
path: root/src/dnsstub/dns_txt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dnsstub/dns_txt.c')
-rw-r--r--src/dnsstub/dns_txt.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/dnsstub/dns_txt.c b/src/dnsstub/dns_txt.c
index 9a1b56a..ce0afc4 100644
--- a/src/dnsstub/dns_txt.c
+++ b/src/dnsstub/dns_txt.c
@@ -1,9 +1,9 @@
-#include "stralloc.h"
-#include "uint_t.h"
#include "byte.h"
#include "dnsresolv.h"
+#include "stralloc.h"
+#include "uint_t.h"
-int dns_txt_packet(stralloc *out,const char *buf,unsigned int len)
+int dns_txt_packet(stralloc *out, const char *buf, unsigned int len)
{
unsigned int pos;
char header[12];
@@ -14,35 +14,40 @@ int dns_txt_packet(stralloc *out,const char *buf,unsigned int len)
int i;
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_TXT))
- 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_TXT))
+ if (byte_equal(header + 2, 2, DNS_C_IN)) {
if (pos + datalen > len) return DNS_ERR;
- txtlen = (unsigned char) buf[pos];
+ txtlen = (unsigned char)buf[pos];
for (i = 1; i < datalen; ++i) {
ch = buf[pos + i];
- if (i == txtlen + 1) // next label
- txtlen += (unsigned char) ch + 1;
+ if (i == txtlen + 1) // next label
+ txtlen += (unsigned char)ch + 1;
else {
if (ch < 32) ch = '?';
if (ch > 126) ch = '?';
- if (!stralloc_append(out,&ch)) return DNS_MEM;
+ if (!stralloc_append(out, &ch)) return DNS_MEM;
}
}
}
pos += datalen;
++ranswers;
- if (numanswers) if (!stralloc_append(out,"\n")) return DNS_MEM;
+ if (numanswers)
+ if (!stralloc_append(out, "\n")) return DNS_MEM;
}
return ranswers;
@@ -50,13 +55,13 @@ int dns_txt_packet(stralloc *out,const char *buf,unsigned int len)
static char *q = 0;
-int dns_txt(stralloc *out,const stralloc *fqdn)
+int dns_txt(stralloc *out, const stralloc *fqdn)
{
- int rc;
+ int rc;
- if (dns_domain_fromdot(&q,fqdn->s,fqdn->len) <= 0) return DNS_ERR;
- if (dns_resolve(q,DNS_T_TXT) < 0) return DNS_ERR;
- if ((rc = dns_txt_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_TXT) < 0) return DNS_ERR;
+ if ((rc = dns_txt_packet(out, dns_resolve_tx.packet, dns_resolve_tx.packetlen)) < 0) return DNS_ERR;
dns_transmit_free(&dns_resolve_tx);
dns_domain_free(&q);