Class: PacketGen::Header::DNS::Question
- Inherits:
-
BinStruct::Struct
- Object
- BinStruct::Struct
- PacketGen::Header::DNS::Question
- Includes:
- BinStruct::Structable
- Defined in:
- lib/packetgen/header/dns/question.rb
Overview
DNS Question
Direct Known Subclasses
Constant Summary collapse
- TYPES =
Ressource Record types
{ 'A' => 1, 'NS' => 2, 'MD' => 3, 'MF' => 4, 'CNAME' => 5, 'SOA' => 6, 'MB' => 7, 'MG' => 8, 'MR' => 9, 'NULL' => 10, 'WKS' => 11, 'PTR' => 12, 'HINFO' => 13, 'MINFO' => 14, 'MX' => 15, 'TXT' => 16, 'AAAA' => 28, 'SRV' => 33, 'NAPTR' => 35, 'KX' => 36, 'CERT' => 37, 'OPT' => 41, 'DS' => 43, 'RRSIG' => 46, 'NSEC' => 47, 'DNSKEY' => 48, 'TKEY' => 249, 'TSIG' => 250, '*' => 255 }.freeze
- CLASSES =
Ressource Record classes
{ 'IN' => 1, 'CH' => 3, 'HS' => 4, 'NONE' => 254, '*' => 255 }.freeze
Instance Attribute Summary collapse
-
#name ⇒ String
Question domain name.
-
#rrclass ⇒ Integer
16-bit question class.
-
#type ⇒ Integer
16-bit question type.
Instance Method Summary collapse
-
#human_rrclass ⇒ String
Get human readable class.
-
#human_type ⇒ String
Get human readable type.
-
#initialize(dns, options = {}) ⇒ Question
constructor
A new instance of Question.
-
#to_human ⇒ String
Human-readable string for this question.
-
#type?(type) ⇒ Boolean
Check type.
Constructor Details
#initialize(dns, options = {}) ⇒ Question
Returns a new instance of Question.
77 78 79 80 |
# File 'lib/packetgen/header/dns/question.rb', line 77 def initialize(dns, ={}) super() self[:name].dns = dns end |
Instance Attribute Details
#name ⇒ String
Question domain name
62 |
# File 'lib/packetgen/header/dns/question.rb', line 62 define_attr :name, Name, default: '.' |
#rrclass ⇒ Integer
16-bit question class
70 |
# File 'lib/packetgen/header/dns/question.rb', line 70 define_attr :rrclass, BinStruct::Int16Enum, default: 1, enum: CLASSES |
#type ⇒ Integer
16-bit question type
66 |
# File 'lib/packetgen/header/dns/question.rb', line 66 define_attr :type, BinStruct::Int16Enum, default: 1, enum: TYPES |
Instance Method Details
#human_rrclass ⇒ String
Get human readable class
115 116 117 118 119 120 121 |
# File 'lib/packetgen/header/dns/question.rb', line 115 def human_rrclass if self[:name].dns.is_a? MDNS self.class::CLASSES.key(self.rrclass & 0x7fff) || '0x%04x' % (self.rrclass & 0x7fff) else self.class::CLASSES.key(self.rrclass) || '0x%04x' % self.rrclass end end |
#human_type ⇒ String
Get human readable type
109 110 111 |
# File 'lib/packetgen/header/dns/question.rb', line 109 def human_type self.class::TYPES.key(type) || '0x%04x' % type end |
#to_human ⇒ String
Human-readable string for this question
125 126 127 128 129 130 131 132 |
# File 'lib/packetgen/header/dns/question.rb', line 125 def to_human if self[:name].dns.is_a? MDNS unicast_bit = self.rrclass & 0x8000 == 0x8000 ? 'QU' : 'QM' "#{human_type} #{human_rrclass} #{unicast_bit} #{name}" else "#{human_type} #{human_rrclass} #{name}" end end |
#type?(type) ⇒ Boolean
Check type
103 104 105 |
# File 'lib/packetgen/header/dns/question.rb', line 103 def type?(type) self.class::TYPES[type] == self.type end |