djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
printpacket.c
Go to the documentation of this file.
1#include "uint_t.h"
2#include "error.h"
3#include "byte.h"
4#include "dns.h"
5#include "printrecord.h"
6#include "printpacket.h"
7#include "stralloc.h"
8
9static char *d;
10
11#define X(s) if (!stralloc_cats(out,s)) return 0;
12#define NUM(u) if (!stralloc_catulong0(out,u,0)) return 0;
13
14unsigned int printpacket_cat(stralloc *out,char *buf,unsigned int len)
15{
16 uint16 numqueries;
17 uint16 numanswers;
18 uint16 numauthority;
19 uint16 numglue;
20 unsigned int pos;
21 char data[12];
22 uint16 type;
23
24 pos = dns_packet_copy(buf,len,0,data,12);
25 if (!pos) return 0;
26
27 uint16_unpack_big(data + 4,&numqueries);
28 uint16_unpack_big(data + 6,&numanswers);
29 uint16_unpack_big(data + 8,&numauthority);
30 uint16_unpack_big(data + 10,&numglue);
31
32 NUM(len)
33 X(" bytes, ")
35 X("+")
36 NUM(numanswers)
37 X("+")
38 NUM(numauthority)
39 X("+")
40 NUM(numglue)
41 X(" records")
42
43 if (data[2] & 128) X(", response")
44 if (data[2] & 120) X(", weird op")
45 if (data[2] & 4) X(", authoritative")
46 if (data[2] & 2) X(", truncated")
47 if (data[2] & 1) X(", weird rd")
48 if (data[3] & 128) X(", weird ra")
49
50 switch (data[3] & 15) {
51 case 0: X(", noerror"); break;
52 case 3: X(", nxdomain"); break;
53 case 4: X(", notimp"); break;
54 case 5: X(", refused"); break;
55 default: X(", weird rcode");
56 }
57 if (data[3] & 112) X(", weird z")
58
59 X("\n")
60
61 while (numqueries) {
62 --numqueries;
63 X("query: ")
64
65 pos = dns_packet_getname(buf,len,pos,&d); if (!pos) return 0;
66 pos = dns_packet_copy(buf,len,pos,data,4); if (!pos) return 0;
67
68 if (byte_diff(data + 2,2,DNS_C_IN)) {
69 X("weird class")
70 }
71 else {
72 uint16_unpack_big(data,&type);
73 NUM(type)
74 X(" ")
75 if (dns_domain_todot_cat(out,d) <= 0) return 0;
76 }
77 X("\n")
78 }
79
80 for (;;) {
81 if (numanswers) { --numanswers; X("answer: ") }
82 else if (numauthority) { --numauthority; X("authority: ") }
83 else if (numglue) { --numglue; X("additional: ") }
84 else break;
85
86 pos = printrecord_cat(out,buf,len,pos,0,0);
87 if (!pos) return 0;
88 }
89
90 if (pos != len) { errno = EPROTO; return 0; }
91
92 return 1;
93}
char data[32767]
Definition: axfrdns.c:130
uint16 len
Definition: axfrdns.c:319
char buf[MSGSIZE]
Definition: axfrdns.c:318
#define DNS_C_IN
Definition: dns.h:53
int dns_domain_todot_cat(stralloc *out, const char *d)
Definition: dns_dtda.c:11
unsigned int dns_packet_getname(const char *buf, unsigned int len, unsigned int pos, char **d)
Definition: dns_packet.c:35
unsigned int dns_packet_copy(const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
Definition: dns_packet.c:8
uint64 numqueries
Definition: dnscache.c:68
char type[2]
Definition: dnsq.c:56
void out(const char *s, unsigned int len)
Definition: generic-conf.c:54
unsigned int printpacket_cat(stralloc *out, char *buf, unsigned int len)
Definition: printpacket.c:14
#define X(s)
Definition: printpacket.c:11
#define NUM(u)
Definition: printpacket.c:12
unsigned int printrecord_cat(stralloc *, const char *, unsigned int, unsigned int, const char *, const char *)