Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

poslib/dnsmessage.h

Go to the documentation of this file.

  
00001 /* 00002 Posadis - A DNS Server 00003 Dns Message handling 00004 Copyright (C) 2002 Meilof Veeningen <> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifndef __POSLIB_DNSMESSAGE_H 00022 #define __POSLIB_DNSMESSAGE_H 00023 00024 class message_buff; 00025 00026 #include "dnsdefs.h" 00027 #include "types.h" 00028 #include "sysstl.h" 00029 #include "domainfn.h" 00030 00031 /* when constructed with the message and length, the data is regarded static 00032 and not cleaned up on destruction */ 00033 00050 class message_buff { 00051 public: 00063 message_buff(char *_msg, int _len, bool is_dynamic = false); 00072 message_buff(const message_buff& buff); 00080 message_buff(); 00087 ~message_buff(); 00095 message_buff& operator=(const message_buff& buff); 00103 bool is_static; 00109 int len; 00115 char *msg; 00116 }; 00117 00124 class DnsQuestion { 00125 public: 00131 DnsQuestion(); 00138 DnsQuestion(const DnsQuestion& q); 00145 DnsQuestion& operator=(const DnsQuestion& q); 00146 00156 DnsQuestion(domainname QNAME, u_int16 QTYPE, u_int16 QCLASS = CLASS_IN); 00157 00163 ~DnsQuestion(); 00164 00170 domainname QNAME; 00171 00179 u_int16 QTYPE; 00189 u_int16 QCLASS; 00190 }; 00191 00199 class DnsRR { 00200 public: 00206 DnsRR(); 00207 00218 DnsRR(domainname NAME, u_int16 TYPE, u_int16 CLASS, u_int32 TTL); 00219 00232 DnsRR(domainname NAME, u_int16 TYPE, u_int16 CLASS, u_int32 TTL, uint16_t RDLENGTH, const char *RDATA); 00233 00241 DnsRR(const DnsRR& rr); 00242 00249 DnsRR& operator=(const DnsRR& rr); 00250 00256 ~DnsRR(); 00257 00264 domainname NAME; 00265 00272 u_int16 TYPE; 00273 00280 u_int16 CLASS; 00281 00288 u_int32 TTL; 00289 00295 u_int16 RDLENGTH; 00296 00304 char *RDATA; 00305 }; 00306 00314 class DnsMessage { 00315 public: 00321 DnsMessage(); 00322 00328 ~DnsMessage(); 00329 00339 u_int16 ID; 00340 00346 bool QR; 00347 00355 u_int4 OPCODE; 00356 00365 bool AA; 00366 00374 bool TC; 00375 00383 bool RD; 00384 00392 bool RA; 00393 00401 u_int3 Z; 00402 00411 u_int4 RCODE; 00412 00419 stl_list(DnsQuestion) questions; 00420 00427 stl_list(DnsRR) answers; 00428 00436 stl_list(DnsRR) authority; 00437 00445 stl_list(DnsRR) additional; 00446 00455 void read_from_data(char *data, int len); 00456 00468 message_buff compile(int maxlen); 00469 00470 protected: 00471 void write_section(stl_list(DnsRR)& section, int lenpos, stl_string& message, stl_slist(dom_compr_info) &comprinfo, int maxlen, bool is_additional = false); 00472 void read_section(stl_list(DnsRR)& section, int count, message_buff &buff, int &pos); 00473 }; 00474 00475 u_int16 uint16_value(char *buff); 00476 u_int32 uint32_value(char *buff); 00477 00478 char *uint16_buff(uint16_t val); 00479 char *uint32_buff(uint32_t val); 00480 00495 DnsMessage *create_query(domainname QNAME, uint16_t QTYPE = DNS_TYPE_A, bool RD = true, uint16_t QCLASS = CLASS_IN); 00496 00497 00503 class a_record { 00504 public: 00505 char address[4]; 00506 }; 00507 00509 a_record get_a_record(DnsMessage *a); 00511 stl_list(a_record) get_a_records(DnsMessage *a, bool fail_if_none = false); 00512 00518 class aaaa_record { 00519 public: 00520 char address[16]; 00521 }; 00522 00524 aaaa_record get_aaaa_record(DnsMessage *a); 00526 stl_list(aaaa_record) get_aaaa_records(DnsMessage *a, bool fail_if_none = false); 00527 00533 class mx_record { 00534 public: 00535 uint16_t preference; 00536 domainname server; 00537 }; 00538 00540 mx_record get_mx_record(DnsMessage *a); 00542 stl_list(mx_record) get_mx_records(DnsMessage *a, bool fail_if_none = false); 00543 00545 domainname get_ns_record(DnsMessage *a); 00547 stl_list(domainname) get_ns_records(DnsMessage *a, bool fail_if_none = false); 00548 00550 domainname get_ptr_record(DnsMessage *a); 00551 //* Gets the list of PTR records in te answer to a PTR query. 00552 stl_list(domainname) get_ptr_records(DnsMessage *a, bool fail_if_none = false); 00553 00554 //* Structure for RR data returned by get_records 00555 class rrdat { 00556 public: 00557 rrdat(uint16_t, uint16_t, char *); 00558 uint16_t type; 00559 uint16_t len; 00560 char *msg; 00561 }; 00562 00564 stl_list(rrdat) get_records(DnsMessage *a, bool fail_if_none = false, bool follow_cname = true, stl_list(domainname) *followed_cnames = NULL); 00565 00567 enum _answer_type { 00568 A_ERROR, 00569 A_CNAME, 00570 A_NXDOMAIN, 00571 A_ANSWER, 00572 A_REFERRAL, 00573 A_NODATA 00574 }; 00575 00577 _answer_type check_answer_type(DnsMessage *msg, domainname &qname, uint16_t qtype); 00578 00580 bool has_rrset(stl_list(DnsRR) &rrlist, domainname &QNAME, uint16_t QTYPE = QTYPE_ANY); 00581 00582 #endif /* __POSLIB_DNSMESSAGE_H */ 00583

  
Generated on Fri Dec 24 19:55:14 2004 for Poslib by doxygen 1.3.7