Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dnsmessage.h
Go to the documentation of this file.
1 /*
2  Posadis - A DNS Server
3  Dns Message handling
4  Copyright (C) 2002 Meilof Veeningen <meilof@users.sourceforge.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 
21 class DnsRR;
22 
23 #ifndef __POSLIB_DNSMESSAGE_H
24 #define __POSLIB_DNSMESSAGE_H
25 
26 class message_buff;
27 
28 #include <time.h>
29 #include "dnsdefs.h"
30 #include "types.h"
31 #include "sysstl.h"
32 #include "domainfn.h"
33 
34 /* when constructed with the message and length, the data is regarded static
35  and not cleaned up on destruction */
36 
53 class message_buff {
54  public:
66  message_buff(unsigned char *_msg, int _len, bool is_dynamic = false);
75  message_buff(const message_buff& buff);
83  message_buff();
90  ~message_buff();
98  message_buff& operator=(const message_buff& buff);
106  bool is_static;
112  int len;
118  unsigned char *msg;
119 };
120 
127 class DnsQuestion {
128  public:
134  DnsQuestion();
141  DnsQuestion(const DnsQuestion& q);
148  DnsQuestion& operator=(const DnsQuestion& q);
149 
159  DnsQuestion(domainname qname, u_int16 qtype, u_int16 qclass = CLASS_IN);
160 
166  ~DnsQuestion();
167 
174 
193 };
194 
202 class DnsRR {
203  public:
209  DnsRR();
210 
214  bool operator==(const DnsRR& other);
215 
226  int compareTo(const DnsRR& other) const;
227  bool operator<(const DnsRR& rr) const;
228  bool operator<=(const DnsRR& rr) const;
229  bool operator>(const DnsRR& rr) const;
230  bool operator>=(const DnsRR& rr) const;
231 
243 
256  DnsRR(domainname NAME, u_int16 TYPE, u_int16 CLASS, u_int32 TTL, uint16_t RDLENGTH, const unsigned char *RDATA);
257 
265  DnsRR(const DnsRR& rr);
266 
273  DnsRR& operator=(const DnsRR& rr);
274 
280  ~DnsRR();
281 
289 
297 
305 
313 
320 
328  unsigned char *RDATA;
329 
330 
331  // RDLENGTH copy of data before TSIG_RR is signed
333 
334  // RDATA copy of data before TSIG_RR is signed
335  unsigned char *presign_RDATA;
336 };
337 
345 class DnsMessage {
346  public:
352  DnsMessage();
353 
359  ~DnsMessage();
360 
371 
377  bool QR;
378 
387 
396  bool AA;
397 
405  bool TC;
406 
414  bool RD;
415 
423  bool RA;
424 
433 
443 
451 
459 
468 
477 
496  int read_from_data(unsigned char *data, int len);
497 
509  message_buff compile(int maxlen);
510 
511  static void write_rr(DnsRR &rr, stl_string &message, stl_slist(dom_compr_info) *comprinfo,
512  int flags = 0);
513  void write_section(stl_list(DnsRR)& section, int lenpos, stl_string& message, stl_slist(dom_compr_info) &comprinfo, int maxlen, bool is_additional = false);
514  void read_section(stl_list(DnsRR)& section, int count, message_buff &buff, int &pos, unsigned int *tsig_pos = NULL);
515  static DnsRR read_rr(message_buff &buff, int &pos, int flags = 0);
516 
533 
536 
543 
553 };
554 
555 u_int16 uint16_value(const unsigned char *buff);
556 u_int32 uint32_value(const unsigned char *buff);
557 u_int48 uint48_value(const unsigned char *buff);
558 
559 unsigned char *uint16_buff(uint16_t val);
560 unsigned char *uint32_buff(uint32_t val);
561 unsigned char *uint48_buff(u_int48 val);
562 
576 DnsMessage *create_query(domainname qname, uint16_t qtype = DNS_TYPE_A, bool rd = true,
577  uint16_t qclass = CLASS_IN);
578 
584 class a_record {
585 public:
586  char address[4];
587 };
588 
591 
593 stl_list(a_record) get_a_records(DnsMessage *a, bool fail_if_none = false);
594 
600 class aaaa_record {
601 public:
602  char address[16];
603 };
604 
607 
609 stl_list(aaaa_record) get_aaaa_records(DnsMessage *a, bool fail_if_none = false);
610 
616 class mx_record {
617  public:
620 };
621 
624 
626 stl_list(mx_record) get_mx_records(DnsMessage *a, bool fail_if_none = false);
627 
630 
632 stl_list(domainname) get_ns_records(DnsMessage *a, bool fail_if_none = false);
633 
636 
638 stl_list(domainname) get_ptr_records(DnsMessage *a, bool fail_if_none = false);
639 
641 class rrdat {
642  public:
643  rrdat(uint16_t, uint16_t, unsigned char *);
646  unsigned char *msg;
647 };
648 
655 stl_list(rrdat) get_records(DnsMessage *a, bool fail_if_none = false, bool follow_cname = true,
656  stl_list(domainname) *followed_cnames = NULL);
657 
666 };
667 
676 
684 bool has_rrset(stl_list(DnsRR) &rrlist, domainname &name, uint16_t type = QTYPE_ANY);
685 
686 #endif /* __POSLIB_DNSMESSAGE_H */
687