rfc1035.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /*
10  * Low level DNS protocol routines
11  *
12  * KNOWN BUGS:
13  *
14  * UDP replies with TC set should be retried via TCP
15  */
16 
17 #include "squid.h"
18 #include "dns/rfc1035.h"
19 #include "dns/rfc2671.h"
20 #include "util.h"
21 
22 #include <cassert>
23 #include <cstring>
24 #if HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #if HAVE_MEMORY_H
28 #include <memory.h>
29 #endif
30 #if HAVE_NETINET_IN_H
31 #include <netinet/in.h>
32 #endif
33 #if HAVE_ARPA_INET_H
34 #include <arpa/inet.h>
35 #endif
36 #if HAVE_STRINGS_H
37 #include <strings.h>
38 #endif
39 
40 #define RFC1035_MAXLABELSZ 63
41 #define rfc1035_unpack_error 15
42 
43 #if 0
44 #define RFC1035_UNPACK_DEBUG fprintf(stderr, "unpack error at %s:%d\n", __FILE__,__LINE__)
45 #else
46 #define RFC1035_UNPACK_DEBUG (void)0
47 #endif
48 
49 /*
50  * rfc1035HeaderPack()
51  *
52  * Packs a rfc1035_header structure into a buffer.
53  * Returns number of octets packed (should always be 12)
54  */
55 int
56 rfc1035HeaderPack(char *buf, size_t sz, rfc1035_message * hdr)
57 {
58  int off = 0;
59  unsigned short s;
60  unsigned short t;
61  assert(sz >= 12);
62  s = htons(hdr->id);
63  memcpy(buf + off, &s, sizeof(s));
64  off += sizeof(s);
65  t = 0;
66  t |= hdr->qr << 15;
67  t |= (hdr->opcode << 11);
68  t |= (hdr->aa << 10);
69  t |= (hdr->tc << 9);
70  t |= (hdr->rd << 8);
71  t |= (hdr->ra << 7);
72  t |= hdr->rcode;
73  s = htons(t);
74  memcpy(buf + off, &s, sizeof(s));
75  off += sizeof(s);
76  s = htons(hdr->qdcount);
77  memcpy(buf + off, &s, sizeof(s));
78  off += sizeof(s);
79  s = htons(hdr->ancount);
80  memcpy(buf + off, &s, sizeof(s));
81  off += sizeof(s);
82  s = htons(hdr->nscount);
83  memcpy(buf + off, &s, sizeof(s));
84  off += sizeof(s);
85  s = htons(hdr->arcount);
86  memcpy(buf + off, &s, sizeof(s));
87  off += sizeof(s);
88  assert(off == 12);
89  return off;
90 }
91 
92 /*
93  * rfc1035LabelPack()
94  *
95  * Packs a label into a buffer. The format of
96  * a label is one octet specifying the number of character
97  * bytes to follow. Labels must be smaller than 64 octets.
98  * Returns number of octets packed.
99  */
100 static int
101 rfc1035LabelPack(char *buf, size_t sz, const char *label)
102 {
103  assert(label);
104  assert(!strchr(label, '.'));
105 
106  int off = 0;
107  auto len = strlen(label);
108  if (len > RFC1035_MAXLABELSZ)
109  len = RFC1035_MAXLABELSZ;
110  assert(sz >= len + 1);
111  *(buf + off) = (char) len;
112  off++;
113  memcpy(buf + off, label, len);
114  off += len;
115  return off;
116 }
117 
118 /*
119  * rfc1035NamePack()
120  *
121  * Packs a name into a buffer. Names are packed as a
122  * sequence of labels, terminated with NULL label.
123  * Note message compression is not supported here.
124  * Returns number of octets packed.
125  */
126 static int
127 rfc1035NamePack(char *buf, size_t sz, const char *name)
128 {
129  unsigned int off = 0;
130  char *copy = xstrdup(name);
131  char *t;
132  /*
133  * NOTE: use of strtok here makes names like foo....com valid.
134  */
135  for (t = strtok(copy, "."); t; t = strtok(nullptr, "."))
136  off += rfc1035LabelPack(buf + off, sz - off, t);
137  xfree(copy);
138 
139  // add a terminating root (i.e. zero length) label
140  assert(off < sz);
141  buf[off] = 0;
142  ++off;
143 
144  return off;
145 }
146 
147 /*
148  * rfc1035QuestionPack()
149  *
150  * Packs a QUESTION section of a message.
151  * Returns number of octets packed.
152  */
153 int
155  const size_t sz,
156  const char *name,
157  const unsigned short type,
158  const unsigned short _class)
159 {
160  unsigned int off = 0;
161  unsigned short s;
162  off += rfc1035NamePack(buf + off, sz - off, name);
163  s = htons(type);
164  memcpy(buf + off, &s, sizeof(s));
165  off += sizeof(s);
166  s = htons(_class);
167  memcpy(buf + off, &s, sizeof(s));
168  off += sizeof(s);
169  assert(off <= sz);
170  return off;
171 }
172 
173 /*
174  * rfc1035HeaderUnpack()
175  *
176  * Unpacks a RFC1035 message header buffer into the header fields
177  * of the rfc1035_message structure.
178  *
179  * Updates the buffer offset, which is the same as number of
180  * octets unpacked since the header starts at offset 0.
181  *
182  * Returns 0 (success) or 1 (error)
183  */
184 int
185 rfc1035HeaderUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_message * h)
186 {
187  unsigned short s;
188  unsigned short t;
189  assert(*off == 0);
190  /*
191  * The header is 12 octets. This is a bogus message if the size
192  * is less than that.
193  */
194  if (sz < 12)
195  return 1;
196  memcpy(&s, buf + (*off), sizeof(s));
197  (*off) += sizeof(s);
198  h->id = ntohs(s);
199  memcpy(&s, buf + (*off), sizeof(s));
200  (*off) += sizeof(s);
201  t = ntohs(s);
202  h->qr = (t >> 15) & 0x01;
203  h->opcode = (t >> 11) & 0x0F;
204  h->aa = (t >> 10) & 0x01;
205  h->tc = (t >> 9) & 0x01;
206  h->rd = (t >> 8) & 0x01;
207  h->ra = (t >> 7) & 0x01;
208  /*
209  * We might want to check that the reserved 'Z' bits (6-4) are
210  * all zero as per RFC 1035. If not the message should be
211  * rejected.
212  * NO! RFCs say ignore inbound reserved, they may be used in future.
213  * NEW messages need to be set 0, that's all.
214  */
215  h->rcode = t & 0x0F;
216  memcpy(&s, buf + (*off), sizeof(s));
217  (*off) += sizeof(s);
218  h->qdcount = ntohs(s);
219  memcpy(&s, buf + (*off), sizeof(s));
220  (*off) += sizeof(s);
221  h->ancount = ntohs(s);
222  memcpy(&s, buf + (*off), sizeof(s));
223  (*off) += sizeof(s);
224  h->nscount = ntohs(s);
225  memcpy(&s, buf + (*off), sizeof(s));
226  (*off) += sizeof(s);
227  h->arcount = ntohs(s);
228  assert((*off) == 12);
229  return 0;
230 }
231 
232 /*
233  * rfc1035NameUnpack()
234  *
235  * Unpacks a Name in a message buffer into a char*.
236  * Note 'buf' points to the beginning of the whole message,
237  * 'off' points to the spot where the Name begins, and 'sz'
238  * is the size of the whole message. 'name' must be allocated
239  * by the caller.
240  *
241  * Supports the RFC1035 message compression through recursion.
242  *
243  * Updates the new buffer offset.
244  *
245  * Returns 0 (success) or 1 (error)
246  */
247 static int
248 rfc1035NameUnpack(const char *buf, size_t sz, unsigned int *off, unsigned short *rdlength, char *name, size_t ns, int rdepth)
249 {
250  unsigned int no = 0;
251  unsigned char c;
252  size_t len;
253  assert(ns > 0);
254  do {
255  if ((*off) >= sz) {
257  return 1;
258  }
259  c = *(buf + (*off));
260  if (c > 191) {
261  /* blasted compression */
262  unsigned short s;
263  unsigned int ptr;
264  if (rdepth > 64) { /* infinite pointer loop */
266  return 1;
267  }
268  /* before copying compression offset value, ensure it is inside the buffer */
269  if ((*off) + sizeof(s) > sz) {
271  return 1;
272  }
273  memcpy(&s, buf + (*off), sizeof(s));
274  s = ntohs(s);
275  (*off) += sizeof(s);
276  ptr = s & 0x3FFF;
277  /* Make sure the pointer is inside this message */
278  if (ptr >= sz) {
280  return 1;
281  }
282  return rfc1035NameUnpack(buf, sz, &ptr, rdlength, name + no, ns - no, rdepth + 1);
283  } else if (c > RFC1035_MAXLABELSZ) {
284  /*
285  * "(The 10 and 01 combinations are reserved for future use.)"
286  */
288  return 1;
289  } else {
290  (*off)++;
291  len = (size_t) c;
292  if (len == 0)
293  break;
294  if (len > (ns - no - 1)) { /* label won't fit */
296  return 1;
297  }
298  if ((*off) + len >= sz) { /* message is too short */
300  return 1;
301  }
302  memcpy(name + no, buf + (*off), len);
303  (*off) += len;
304  no += len;
305  *(name + (no++)) = '.';
306  if (rdlength)
307  *rdlength += len + 1;
308  }
309  } while (c > 0 && no < ns);
310  if (no)
311  *(name + no - 1) = '\0';
312  else
313  *name = '\0';
314  /* make sure we didn't allow someone to overflow the name buffer */
315  assert(no <= ns);
316  return 0;
317 }
318 
319 /*
320  * rfc1035RRPack()
321  *
322  * Packs a RFC1035 Resource Record into a message buffer from 'RR'.
323  * The caller must allocate and free RR->rdata and RR->name!
324  *
325  * Updates the new message buffer.
326  *
327  * Returns the number of bytes added to the buffer or 0 for error.
328  */
329 int
330 rfc1035RRPack(char *buf, const size_t sz, const rfc1035_rr * RR)
331 {
332  unsigned int off;
333  uint16_t s;
334  uint32_t i;
335 
336  off = rfc1035NamePack(buf, sz, RR->name);
337 
338  /*
339  * Make sure the remaining message has enough octets for the
340  * rest of the RR fields.
341  */
342  if ((off + sizeof(s)*3 + sizeof(i) + RR->rdlength) > sz) {
343  return 0;
344  }
345  s = htons(RR->type);
346  memcpy(buf + off, &s, sizeof(s));
347  off += sizeof(s);
348  s = htons(RR->_class);
349  memcpy(buf + off, &s, sizeof(s));
350  off += sizeof(s);
351  i = htonl(RR->ttl);
352  memcpy(buf + off, &i, sizeof(i));
353  off += sizeof(i);
354  s = htons(RR->rdlength);
355  memcpy(buf + off, &s, sizeof(s));
356  off += sizeof(s);
357  memcpy(buf + off, RR->rdata, RR->rdlength);
358  off += RR->rdlength;
359  assert(off <= sz);
360  return off;
361 }
362 
363 /*
364  * rfc1035RRUnpack()
365  *
366  * Unpacks a RFC1035 Resource Record into 'RR' from a message buffer.
367  * The caller must free RR->rdata!
368  *
369  * Updates the new message buffer offset.
370  *
371  * Returns 0 (success) or 1 (error)
372  */
373 static int
374 rfc1035RRUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_rr * RR)
375 {
376  unsigned short s;
377  unsigned int i;
378  unsigned short rdlength;
379  unsigned int rdata_off;
380  if (rfc1035NameUnpack(buf, sz, off, nullptr, RR->name, RFC1035_MAXHOSTNAMESZ, 0)) {
382  memset(RR, '\0', sizeof(*RR));
383  return 1;
384  }
385  /*
386  * Make sure the remaining message has enough octets for the
387  * rest of the RR fields.
388  */
389  if ((*off) + 10 > sz) {
391  memset(RR, '\0', sizeof(*RR));
392  return 1;
393  }
394  memcpy(&s, buf + (*off), sizeof(s));
395  (*off) += sizeof(s);
396  RR->type = ntohs(s);
397  memcpy(&s, buf + (*off), sizeof(s));
398  (*off) += sizeof(s);
399  RR->_class = ntohs(s);
400  memcpy(&i, buf + (*off), sizeof(i));
401  (*off) += sizeof(i);
402  RR->ttl = ntohl(i);
403  memcpy(&s, buf + (*off), sizeof(s));
404  (*off) += sizeof(s);
405  rdlength = ntohs(s);
406  if ((*off) + rdlength > sz) {
407  /*
408  * We got a truncated packet. 'dnscache' truncates UDP
409  * replies at 512 octets, as per RFC 1035.
410  */
412  memset(RR, '\0', sizeof(*RR));
413  return 1;
414  }
415  RR->rdlength = rdlength;
416  switch (RR->type) {
417  case RFC1035_TYPE_PTR:
418  RR->rdata = (char*)xmalloc(RFC1035_MAXHOSTNAMESZ);
419  rdata_off = *off;
420  RR->rdlength = 0; /* Filled in by rfc1035NameUnpack */
421  if (rfc1035NameUnpack(buf, sz, &rdata_off, &RR->rdlength, RR->rdata, RFC1035_MAXHOSTNAMESZ, 0)) {
423  xfree(RR->rdata);
424  memset(RR, '\0', sizeof(*RR));
425  return 1;
426  }
427  if (rdata_off > ((*off) + rdlength)) {
428  /*
429  * This probably doesn't happen for valid packets, but
430  * I want to make sure that NameUnpack doesn't go beyond
431  * the RDATA area.
432  */
434  xfree(RR->rdata);
435  memset(RR, '\0', sizeof(*RR));
436  return 1;
437  }
438  break;
439  case RFC1035_TYPE_A:
440  default:
441  RR->rdata = (char*)xmalloc(rdlength);
442  memcpy(RR->rdata, buf + (*off), rdlength);
443  break;
444  }
445  (*off) += rdlength;
446  assert((*off) <= sz);
447  return 0;
448 }
449 
450 const char *
452 {
453  if (n < 0)
454  n = -n;
455  switch (n) {
456  case 0:
457  return "No error condition";
458  break;
459  case 1:
460  return "Format Error: The name server was "
461  "unable to interpret the query.";
462  break;
463  case 2:
464  return "Server Failure: The name server was "
465  "unable to process this query.";
466  break;
467  case 3:
468  return "Name Error: The domain name does "
469  "not exist.";
470  break;
471  case 4:
472  return "Not Implemented: The name server does "
473  "not support the requested kind of query.";
474  break;
475  case 5:
476  return "Refused: The name server refuses to "
477  "perform the specified operation.";
478  break;
480  return "The DNS reply message is corrupt or could "
481  "not be safely parsed.";
482  break;
483  default:
484  return "Unknown Error";
485  break;
486  }
487 }
488 
489 void
491 {
492  if (*rr == nullptr) {
493  return;
494  }
495 
496  while (n-- > 0) {
497  if ((*rr)[n].rdata)
498  xfree((*rr)[n].rdata);
499  }
500  xfree(*rr);
501  *rr = nullptr;
502 }
503 
504 /*
505  * rfc1035QueryUnpack()
506  *
507  * Unpacks a RFC1035 Query Record into 'query' from a message buffer.
508  *
509  * Updates the new message buffer offset.
510  *
511  * Returns 0 (success) or 1 (error)
512  */
513 static int
514 rfc1035QueryUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_query * query)
515 {
516  uint16_t s;
517  if (rfc1035NameUnpack(buf, sz, off, nullptr, query->name, RFC1035_MAXHOSTNAMESZ, 0)) {
519  memset(query, '\0', sizeof(*query));
520  return 1;
521  }
522  if (*off + 4 > sz) {
524  memset(query, '\0', sizeof(*query));
525  return 1;
526  }
527  memcpy(&s, buf + *off, sizeof(s));
528  *off += sizeof(s);
529  query->qtype = ntohs(s);
530  memcpy(&s, buf + *off, sizeof(s));
531  *off += sizeof(s);
532  query->qclass = ntohs(s);
533  return 0;
534 }
535 
536 void
538 {
539  if (!*msg)
540  return;
541  if ((*msg)->query)
542  xfree((*msg)->query);
543  if ((*msg)->answer)
544  rfc1035RRDestroy(&(*msg)->answer, (*msg)->ancount);
545  xfree(*msg);
546  *msg = nullptr;
547 }
548 
549 /*
550  * rfc1035QueryCompare()
551  *
552  * Compares two rfc1035_query entries
553  *
554  * Returns 0 (equal) or !=0 (different)
555  */
556 int
558 {
559  size_t la, lb;
560  if (a->qtype != b->qtype)
561  return 1;
562  if (a->qclass != b->qclass)
563  return 1;
564  la = strlen(a->name);
565  lb = strlen(b->name);
566  if (la != lb) {
567  /* Trim root label(s) */
568  while (la > 0 && a->name[la - 1] == '.')
569  la--;
570  while (lb > 0 && b->name[lb - 1] == '.')
571  lb--;
572  }
573  if (la != lb)
574  return 1;
575 
576  return strncasecmp(a->name, b->name, la);
577 }
578 
579 /*
580  * rfc1035MessageUnpack()
581  *
582  * Takes the contents of a DNS reply and fills in an array
583  * of resource record structures. The records array is allocated
584  * here, and should be freed by calling rfc1035RRDestroy().
585  *
586  * Returns number of records unpacked, zero if DNS reply indicates
587  * zero answers, or an error number < 0.
588  */
589 
590 int
591 rfc1035MessageUnpack(const char *buf,
592  size_t sz,
593  rfc1035_message ** answer)
594 {
595  unsigned int off = 0;
596  unsigned int i, j;
597  unsigned int nr = 0;
598  rfc1035_message *msg = nullptr;
599  rfc1035_rr *recs = nullptr;
600  rfc1035_query *querys = nullptr;
601  msg = (rfc1035_message*)xcalloc(1, sizeof(*msg));
602  if (rfc1035HeaderUnpack(buf + off, sz - off, &off, msg)) {
604  xfree(msg);
605  return -rfc1035_unpack_error;
606  }
607  i = (unsigned int) msg->qdcount;
608  if (i != 1) {
609  /* This can not be an answer to our queries.. */
611  xfree(msg);
612  return -rfc1035_unpack_error;
613  }
614  querys = msg->query = (rfc1035_query*)xcalloc(i, sizeof(*querys));
615  for (j = 0; j < i; j++) {
616  if (rfc1035QueryUnpack(buf, sz, &off, &querys[j])) {
618  rfc1035MessageDestroy(&msg);
619  return -rfc1035_unpack_error;
620  }
621  }
622  *answer = msg;
623  if (msg->rcode) {
625  return -msg->rcode;
626  }
627  if (msg->ancount == 0)
628  return 0;
629  i = (unsigned int) msg->ancount;
630  recs = msg->answer = (rfc1035_rr*)xcalloc(i, sizeof(*recs));
631  for (j = 0; j < i; j++) {
632  if (off >= sz) { /* corrupt packet */
634  break;
635  }
636  if (rfc1035RRUnpack(buf, sz, &off, &recs[j])) { /* corrupt RR */
638  break;
639  }
640  nr++;
641  }
642  if (nr == 0) {
643  /*
644  * we expected to unpack some answers (ancount != 0), but
645  * didn't actually get any.
646  */
647  rfc1035MessageDestroy(&msg);
648  *answer = nullptr;
649  return -rfc1035_unpack_error;
650  }
651  return nr;
652 }
653 
654 /*
655  * rfc1035BuildAQuery()
656  *
657  * Builds a message buffer with a QUESTION to lookup A records
658  * for a hostname. Caller must allocate 'buf' which should
659  * probably be at least 512 octets. The 'szp' initially
660  * specifies the size of the buffer, on return it contains
661  * the size of the message (i.e. how much to write).
662  * Returns the size of the query
663  */
664 ssize_t
665 rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz)
666 {
667  static rfc1035_message h;
668  size_t offset = 0;
669  memset(&h, '\0', sizeof(h));
670  h.id = qid;
671  h.qr = 0;
672  h.rd = 1;
673  h.opcode = 0; /* QUERY */
674  h.qdcount = (unsigned int) 1;
675  h.arcount = (edns_sz > 0 ? 1 : 0);
676  offset += rfc1035HeaderPack(buf + offset, sz - offset, &h);
677  offset += rfc1035QuestionPack(buf + offset,
678  sz - offset,
679  hostname,
682  if (edns_sz > 0)
683  offset += rfc2671RROptPack(buf + offset, sz - offset, edns_sz);
684  if (query) {
685  query->qtype = RFC1035_TYPE_A;
686  query->qclass = RFC1035_CLASS_IN;
687  xstrncpy(query->name, hostname, sizeof(query->name));
688  }
689  assert(offset <= sz);
690  return offset;
691 }
692 
693 /*
694  * rfc1035BuildPTRQuery()
695  *
696  * Builds a message buffer with a QUESTION to lookup PTR records
697  * for an address. Caller must allocate 'buf' which should
698  * probably be at least 512 octets. The 'szp' initially
699  * specifies the size of the buffer, on return it contains
700  * the size of the message (i.e. how much to write).
701  * Returns the size of the query
702  */
703 ssize_t
704 rfc1035BuildPTRQuery(const struct in_addr addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, ssize_t edns_sz)
705 {
706  static rfc1035_message h;
707  size_t offset = 0;
708  static char rev[32];
709  unsigned int i;
710  memset(&h, '\0', sizeof(h));
711  i = (unsigned int) ntohl(addr.s_addr);
712  snprintf(rev, 32, "%u.%u.%u.%u.in-addr.arpa.",
713  i & 255,
714  (i >> 8) & 255,
715  (i >> 16) & 255,
716  (i >> 24) & 255);
717  h.id = qid;
718  h.qr = 0;
719  h.rd = 1;
720  h.opcode = 0; /* QUERY */
721  h.qdcount = (unsigned int) 1;
722  h.arcount = (edns_sz > 0 ? 1 : 0);
723  offset += rfc1035HeaderPack(buf + offset, sz - offset, &h);
724  offset += rfc1035QuestionPack(buf + offset,
725  sz - offset,
726  rev,
729  if (edns_sz > 0)
730  offset += rfc2671RROptPack(buf + offset, sz - offset, edns_sz);
731  if (query) {
732  query->qtype = RFC1035_TYPE_PTR;
733  query->qclass = RFC1035_CLASS_IN;
734  xstrncpy(query->name, rev, sizeof(query->name));
735  }
736  assert(offset <= sz);
737  return offset;
738 }
739 
740 /*
741  * We're going to retry a former query, but we
742  * just need a new ID for it. Lucky for us ID
743  * is the first field in the message buffer.
744  */
745 void
746 rfc1035SetQueryID(char *buf, unsigned short qid)
747 {
748  unsigned short s = htons(qid);
749  memcpy(buf, &s, sizeof(s));
750 }
751 
rfc1035_query * query
Definition: rfc1035.h:68
void * xcalloc(size_t n, size_t sz)
Definition: xalloc.cc:71
#define xmalloc
unsigned short type
Definition: rfc1035.h:40
unsigned short rdlength
Definition: rfc1035.h:43
int rfc1035RRPack(char *buf, const size_t sz, const rfc1035_rr *RR)
Definition: rfc1035.cc:330
static int rfc1035RRUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_rr *RR)
Definition: rfc1035.cc:374
rfc1035_rr * answer
Definition: rfc1035.h:69
unsigned int opcode
Definition: rfc1035.h:58
#define xstrdup
int rfc2671RROptPack(char *buf, size_t sz, ssize_t edns_sz)
Definition: rfc2671.cc:14
int rfc1035HeaderPack(char *buf, size_t sz, rfc1035_message *hdr)
Definition: rfc1035.cc:56
char * xstrncpy(char *dst, const char *src, size_t n)
Definition: xstring.cc:37
unsigned int tc
Definition: rfc1035.h:60
#define rfc1035_unpack_error
Definition: rfc1035.cc:41
unsigned short qdcount
Definition: rfc1035.h:64
int const char size_t
Definition: stub_liblog.cc:83
int rfc1035QueryCompare(const rfc1035_query *a, const rfc1035_query *b)
Definition: rfc1035.cc:557
void rfc1035RRDestroy(rfc1035_rr **rr, int n)
Definition: rfc1035.cc:490
unsigned int ra
Definition: rfc1035.h:62
#define RFC1035_TYPE_A
Definition: rfc1035.h:93
#define RFC1035_MAXHOSTNAMESZ
Definition: rfc1035.h:32
#define RFC1035_TYPE_PTR
Definition: rfc1035.h:95
char * rdata
Definition: rfc1035.h:44
unsigned short _class
Definition: rfc1035.h:41
static int rfc1035QueryUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_query *query)
Definition: rfc1035.cc:514
#define assert(EX)
Definition: assert.h:17
void rfc1035SetQueryID(char *buf, unsigned short qid)
Definition: rfc1035.cc:746
ssize_t rfc1035BuildPTRQuery(const struct in_addr addr, char *buf, size_t sz, unsigned short qid, rfc1035_query *query, ssize_t edns_sz)
Definition: rfc1035.cc:704
unsigned short qtype
Definition: rfc1035.h:50
int rfc1035MessageUnpack(const char *buf, size_t sz, rfc1035_message **answer)
Definition: rfc1035.cc:591
#define xfree
unsigned short id
Definition: rfc1035.h:56
unsigned int ttl
Definition: rfc1035.h:42
char name[RFC1035_MAXHOSTNAMESZ]
Definition: rfc1035.h:49
const char * rfc1035ErrorMessage(int n)
Definition: rfc1035.cc:451
static int rfc1035LabelPack(char *buf, size_t sz, const char *label)
Definition: rfc1035.cc:101
unsigned short qclass
Definition: rfc1035.h:51
unsigned int rcode
Definition: rfc1035.h:63
unsigned short nscount
Definition: rfc1035.h:66
unsigned short ancount
Definition: rfc1035.h:65
static int rfc1035NamePack(char *buf, size_t sz, const char *name)
Definition: rfc1035.cc:127
unsigned int aa
Definition: rfc1035.h:59
unsigned int rd
Definition: rfc1035.h:61
int rfc1035QuestionPack(char *buf, const size_t sz, const char *name, const unsigned short type, const unsigned short _class)
Definition: rfc1035.cc:154
ssize_t rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query *query, ssize_t edns_sz)
Definition: rfc1035.cc:665
#define RFC1035_UNPACK_DEBUG
Definition: rfc1035.cc:46
#define RFC1035_MAXLABELSZ
Definition: rfc1035.cc:40
static int rfc1035NameUnpack(const char *buf, size_t sz, unsigned int *off, unsigned short *rdlength, char *name, size_t ns, int rdepth)
Definition: rfc1035.cc:248
unsigned short arcount
Definition: rfc1035.h:67
char name[RFC1035_MAXHOSTNAMESZ]
Definition: rfc1035.h:39
#define RFC1035_CLASS_IN
Definition: rfc1035.h:96
int rfc1035HeaderUnpack(const char *buf, size_t sz, unsigned int *off, rfc1035_message *h)
Definition: rfc1035.cc:185
unsigned int qr
Definition: rfc1035.h:57
int unsigned int
Definition: stub_fd.cc:19
void rfc1035MessageDestroy(rfc1035_message **msg)
Definition: rfc1035.cc:537

 

Introduction

Documentation

Support

Miscellaneous