summaryrefslogtreecommitdiff
path: root/src/dnsstub/dns_packet.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 14:41:53 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 14:41:53 +0200
commit5fadc0cbb8577c61d66bd6f19ceaf0507c11e23b (patch)
tree684758441f5b431d0008253243034b6a4a29417c /src/dnsstub/dns_packet.c
parent249866e3d1e11dc72eaa1305f4bb479ded92ef38 (diff)
initial clang-format
Diffstat (limited to 'src/dnsstub/dns_packet.c')
-rw-r--r--src/dnsstub/dns_packet.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/dnsstub/dns_packet.c b/src/dnsstub/dns_packet.c
index ce322ea..2b2040f 100644
--- a/src/dnsstub/dns_packet.c
+++ b/src/dnsstub/dns_packet.c
@@ -1,5 +1,5 @@
-#include "error.h"
#include "dnsresolv.h"
+#include "error.h"
/**
@file dns_packet.c
@@ -9,17 +9,22 @@
@brief DNS should have used LZ77 instead of its own sophomoric compression algorithm.
*/
-unsigned int dns_packet_copy(const char *buf,unsigned int len,unsigned int pos,char *out,unsigned int outlen)
+unsigned int dns_packet_copy(
+ const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
{
while (outlen) {
- if (pos >= len) { errno = EPROTO; return 0; }
+ if (pos >= len) {
+ errno = EPROTO;
+ return 0;
+ }
*out = buf[pos++];
- ++out; --outlen;
+ ++out;
+ --outlen;
}
return pos;
}
-unsigned int dns_packet_skipname(const char *buf,unsigned int len,unsigned int pos)
+unsigned int dns_packet_skipname(const char *buf, unsigned int len, unsigned int pos)
{
unsigned char ch;
@@ -36,7 +41,7 @@ unsigned int dns_packet_skipname(const char *buf,unsigned int len,unsigned int p
return 0;
}
-unsigned int dns_packet_getname(const char *buf,unsigned int len,unsigned int pos,char **d)
+unsigned int dns_packet_getname(const char *buf, unsigned int len, unsigned int pos, char **d)
{
unsigned int loop = 0;
unsigned int state = 0;
@@ -47,39 +52,41 @@ unsigned int dns_packet_getname(const char *buf,unsigned int len,unsigned int po
unsigned int namelen = 0;
for (;;) {
- if (pos >= len) goto PROTO;
+ if (pos >= len) goto PROTO;
ch = buf[pos++];
if (++loop >= 1000) goto PROTO;
if (state) {
- if (namelen + 1 > sizeof(name)) goto PROTO;
+ if (namelen + 1 > sizeof(name)) goto PROTO;
name[namelen++] = ch;
--state;
} else {
while (ch >= 192) {
- where = ch; where -= 192; where <<= 8;
- if (pos >= len) goto PROTO;
+ where = ch;
+ where -= 192;
+ where <<= 8;
+ if (pos >= len) goto PROTO;
ch = buf[pos++];
if (!firstcompress) firstcompress = pos;
pos = where + ch;
- if (pos >= len) goto PROTO;
+ if (pos >= len) goto PROTO;
ch = buf[pos++];
if (++loop >= 1000) goto PROTO;
}
if (ch >= 64) goto PROTO;
- if (namelen + 1 > sizeof(name)) goto PROTO;
+ if (namelen + 1 > sizeof(name)) goto PROTO;
name[namelen++] = ch;
if (!ch) break;
state = ch;
}
}
- if (!dns_domain_copy(d,name)) return 0;
+ if (!dns_domain_copy(d, name)) return 0;
if (firstcompress) return firstcompress;
return pos;
- PROTO:
+PROTO:
errno = EPROTO;
return 0;
}