6 #include "printrecord.h"
7 #include "printpacket.h"
11 #define X(s) if (!stralloc_cats(out,s)) return 0;
12 #define NUM(u) if (!stralloc_catulong0(out,u,0)) return 0;
14 unsigned int printpacket_cat(stralloc
*out
,char *buf
,unsigned int len
)
24 pos
= dns_packet_copy(buf
,len
,0,data
,12); if (!pos
) return 0;
26 uint16_unpack_big(data
+ 4,&numqueries
);
27 uint16_unpack_big(data
+ 6,&numanswers
);
28 uint16_unpack_big(data
+ 8,&numauthority
);
29 uint16_unpack_big(data
+ 10,&numglue
);
42 if (data
[2] & 128) X(", response")
43 if (data
[2] & 120) X(", weird op")
44 if (data
[2] & 4) X(", authoritative")
45 if (data
[2] & 2) X(", truncated")
46 if (data
[2] & 1) X(", weird rd")
47 if (data
[3] & 128) X(", weird ra")
48 switch(data
[3] & 15) {
49 case 0: X(", noerror"); break;
50 case 3: X(", nxdomain"); break;
51 case 4: X(", notimp"); break;
52 case 5: X(", refused"); break;
53 default: X(", weird rcode");
55 if (data
[3] & 112) X(", weird z")
63 pos
= dns_packet_getname(buf
,len
,pos
,&d
); if (!pos
) return 0;
64 pos
= dns_packet_copy(buf
,len
,pos
,data
,4); if (!pos
) return 0;
66 if (byte_diff(data
+ 2,2,DNS_C_IN
)) {
70 uint16_unpack_big(data
,&type
);
73 if (!dns_domain_todot_cat(out
,d
)) return 0;
79 if (numanswers
) { --numanswers
; X("answer: ") }
80 else if (numauthority
) { --numauthority
; X("authority: ") }
81 else if (numglue
) { --numglue
; X("additional: ") }
84 pos
= printrecord_cat(out
,buf
,len
,pos
,0,0);
88 if (pos
!= len
) { errno
= error_proto
; return 0; }