diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 14:41:53 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-09 14:41:53 +0200 |
commit | 5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (patch) | |
tree | 684758441f5b431d0008253243034b6a4a29417c /src/dnsstub/dns_name.c | |
parent | 249866e3d1e11dc72eaa1305f4bb479ded92ef38 (diff) |
initial clang-format
Diffstat (limited to 'src/dnsstub/dns_name.c')
-rw-r--r-- | src/dnsstub/dns_name.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/dnsstub/dns_name.c b/src/dnsstub/dns_name.c index 0723a8f..db4565a 100644 --- a/src/dnsstub/dns_name.c +++ b/src/dnsstub/dns_name.c @@ -1,8 +1,8 @@ -#include "stralloc.h" -#include "uint_t.h" #include "byte.h" -#include "ip.h" #include "dnsresolv.h" +#include "ip.h" +#include "stralloc.h" +#include "uint_t.h" /** @file dns_name.c @@ -13,28 +13,32 @@ static char *q = 0; -int dns_name_packet(stralloc *out,const char *buf,unsigned int len) +int dns_name_packet(stralloc *out, const char *buf, unsigned int len) { unsigned int pos; char header[12]; uint16 numanswers; uint16 datalen; - 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_PTR)) - if (byte_equal(header + 2,2,DNS_C_IN)) { - if (!dns_packet_getname(buf,len,pos,&q)) return DNS_ERR; - if (dns_domain_todot_cat(out,q) <= 0) return DNS_ERR; + 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_PTR)) + if (byte_equal(header + 2, 2, DNS_C_IN)) { + if (!dns_packet_getname(buf, len, pos, &q)) return DNS_ERR; + if (dns_domain_todot_cat(out, q) <= 0) return DNS_ERR; return 1; } pos += datalen; @@ -43,38 +47,38 @@ int dns_name_packet(stralloc *out,const char *buf,unsigned int len) return 0; } -int dns_name4(stralloc *out,const char ip[4]) +int dns_name4(stralloc *out, const char ip[4]) { int rc; char name[DNS_NAME4_DOMAIN]; - dns_name4_domain(name,ip); - if (dns_resolve(name,DNS_T_PTR) < 0) return DNS_ERR; - if ((rc = dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen)) < 0) return DNS_ERR; + dns_name4_domain(name, ip); + if (dns_resolve(name, DNS_T_PTR) < 0) return DNS_ERR; + if ((rc = dns_name_packet(out, dns_resolve_tx.packet, dns_resolve_tx.packetlen)) < 0) return DNS_ERR; dns_transmit_free(&dns_resolve_tx); dns_domain_free(&q); return rc; } -int dns_name6(stralloc *out,const char ip[16]) +int dns_name6(stralloc *out, const char ip[16]) { int rc; char name[DNS_NAME6_DOMAIN]; - dns_name6_domain(name,ip); - if (dns_resolve(name,DNS_T_PTR) < 0) return DNS_ERR; - if ((rc = dns_name_packet(out,dns_resolve_tx.packet,dns_resolve_tx.packetlen)) < 0) return DNS_ERR; + dns_name6_domain(name, ip); + if (dns_resolve(name, DNS_T_PTR) < 0) return DNS_ERR; + if ((rc = dns_name_packet(out, dns_resolve_tx.packet, dns_resolve_tx.packetlen)) < 0) return DNS_ERR; dns_transmit_free(&dns_resolve_tx); dns_domain_free(&q); return rc; } -int dns_name(stralloc *out,const char ip[16]) +int dns_name(stralloc *out, const char ip[16]) { if (ip6_isv4mapped(ip)) - return dns_name4(out,ip+12); + return dns_name4(out, ip + 12); else - return dns_name6(out,ip); + return dns_name6(out, ip); } |