aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/pretty-print.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpn/pretty-print.c')
-rw-r--r--src/vpn/pretty-print.c117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/vpn/pretty-print.c b/src/vpn/pretty-print.c
index 096afbf96..90bbe7bea 100644
--- a/src/vpn/pretty-print.c
+++ b/src/vpn/pretty-print.c
@@ -176,3 +176,120 @@ void pkt_printf_ip6udp(struct ip6_udp* pkt) {{{
176 printf("len: %u\n", ntohs(pkt->data.len)); 176 printf("len: %u\n", ntohs(pkt->data.len));
177 printf("crc: 0x%x\n", ntohs(pkt->data.crc)); 177 printf("crc: 0x%x\n", ntohs(pkt->data.crc));
178}}} 178}}}
179
180static char* dns_types(unsigned short type) {{{
181 static char* types[] = { /*{{{*/
182 "",
183 "A", // 1 a host address
184 "NS", // 2 an authoritative name server
185 "MD", // 3 a mail destination (Obsolete - use MX)
186 "MF", // 4 a mail forwarder (Obsolete - use MX)
187 "CNAME", // 5 the canonical name for an alias
188 "SOA", // 6 marks the start of a zone of authority
189 "MB", // 7 a mailbox domain name (EXPERIMENTAL)
190 "MG", // 8 a mail group member (EXPERIMENTAL)
191 "MR", // 9 a mail rename domain name (EXPERIMENTAL)
192 "NULL", // 10 a null RR (EXPERIMENTAL)
193 "WKS", // 11 a well known service description
194 "PTR", // 12 a domain name pointer
195 "HINFO", // 13 host information
196 "MINFO", // 14 mailbox or mail list information
197 "MX", // 15 mail exchange
198 "TXT", // 16 text strings
199 "RP",
200 "AFSDB"
201 }; /*}}}*/
202
203 static char* qtypes[] = { /* + 252! {{{ */
204 "AXFR", // 252 A request for a transfer of an entire zone
205 "MAILB", // 253 A request for mailbox-related records (MB, MG or MR)
206 "MAILA", // 254 A request for mail agent RRs (Obsolete - see MX)
207 "*", // 255 A request for all records
208 }; /*}}}*/
209
210 if (type <= 18) return types[type];
211 if (type >= 252 && type <= 255) return qtypes[type-252];
212
213 switch(type) {
214 case 24: return "SIG";
215 case 25: return "KEY";
216 case 28: return "AAAA";
217 case 29: return "LOC";
218 case 33: return "SRV";
219 case 35: return "NAPTR";
220 case 36: return "KX";
221 case 37: return "CERT";
222 case 39: return "DNAME";
223 case 42: return "APL";
224 case 43: return "DS";
225 case 44: return "SSHFP";
226 case 45: return "IPSECKEY";
227 case 46: return "RRSIG";
228 case 47: return "NSEC";
229 case 48: return "DNSKEY";
230 case 49: return "DHCID";
231 case 50: return "NSEC3";
232 case 51: return "NSEC3PARAM";
233 case 55: return "HIP";
234 case 99: return "SPF";
235 case 249: return "TKEY";
236 case 250: return "TSIG";
237 case 32768: return "TA";
238 case 32769: return "DLV";
239 }
240
241 return 0;
242
243}}}
244
245static char* dns_classes(short class) {{{
246 static char* classes[] = { /*{{{*/
247 "",
248 "IN", // 1 the Internet
249 "CS", // 2 the CSNET class (Obsolete - used only for examples in some obsolete RFCs)
250 "CH", // 3 the CHAOS class
251 "HS", // 4 Hesiod [Dyer 87]
252 }; /*}}}*/
253
254 if (class <= 4) return classes[class];
255 return 0;
256}}}
257
258void pkt_printf_ip6dns(struct ip6_udp_dns* pkt) {{{
259 printf("DNS-Packet:\n");
260 printf("\tid: %d\n", ntohs(pkt->data.id));
261 printf("\t%d: %s\n", pkt->data.qr, pkt->data.qr == 0 ? "query" : "response");
262 printf("\top: %s\n", (char*[]){"query", "inverse q.", "status", "inval"}[pkt->data.op]);
263 printf("\trecursion is%s desired\n", pkt->data.rd == 0 ? " not" : "");
264 unsigned short qdcount = ntohs(pkt->data.qdcount);
265 printf("\t#qd: %d\n", qdcount);
266 printf("\t#an: %d\n", ntohs(pkt->data.ancount));
267 printf("\t#ns: %d\n", ntohs(pkt->data.nscount));
268 printf("\t#ar: %d\n", ntohs(pkt->data.arcount));
269
270 struct dns_query** queries = (struct dns_query**)malloc(qdcount*sizeof(struct dns_query*));
271 unsigned int idx = 0;
272
273 int i;
274 for (i = 0; i < qdcount; i++) {
275 queries[i] = (struct dns_query*)malloc(sizeof(struct dns_query));
276 queries[i]->name = (unsigned char*)malloc(255); // see RFC1035
277 unsigned char* name = queries[i]->name;
278 int len = pkt->data.data[idx++];
279 while (len != 0) {
280 memcpy(name, pkt->data.data+idx, len);
281 idx += len;
282 name += len;
283 *name = '.';
284 name++;
285 len = pkt->data.data[idx++];
286 };
287 printf("%d\n", idx);
288 *name = 0;
289 queries[i]->qtype = *((unsigned short*)(pkt->data.data+idx));
290 idx += 2;
291 queries[i]->qclass = *((unsigned short*)(pkt->data.data+idx));
292 idx += 2;
293 printf("query for %s type=%d (%s) class=%d (%s)\n", queries[i]->name, ntohs(queries[i]->qtype), dns_types(ntohs(queries[i]->qtype)), ntohs(queries[i]->qclass), dns_classes(ntohs(queries[i]->qclass)));
294 }
295}}}