Class: PacketGen::Header::DNS::RR
- Defined in:
- lib/packetgen/header/dns/rr.rb
Overview
DNS Ressource Record
Direct Known Subclasses
Defined Under Namespace
Constant Summary
Constants inherited from Question
Question::CLASSES, Question::TYPES
Instance Attribute Summary collapse
- #rdata ⇒ BinStruct::String
-
#rdlength ⇒ Integer
16-bit #rdata length.
-
#ttl ⇒ Integer
32-bit time to live.
Attributes inherited from Question
Instance Method Summary collapse
-
#human_rdata ⇒ String
Get human readable rdata.
-
#human_rrclass ⇒ String
Get human readable class.
-
#initialize(dns, options = {}) ⇒ RR
constructor
A new instance of RR.
- #to_human ⇒ String
Methods inherited from Question
Constructor Details
#initialize(dns, options = {}) ⇒ RR
Returns a new instance of RR.
73 74 75 76 77 78 |
# File 'lib/packetgen/header/dns/rr.rb', line 73 def initialize(dns, ={}) super return unless [:rdata] && [:rdlength].nil? self.rdata = [:rdata] end |
Instance Attribute Details
#rdata ⇒ BinStruct::String
26 27 |
# File 'lib/packetgen/header/dns/rr.rb', line 26 define_attr :rdata, BinStruct::String, builder: ->(rr, t) { t.new(length_from: rr[:rdlength]) } |
#rdlength ⇒ Integer
16-bit #rdata length
23 |
# File 'lib/packetgen/header/dns/rr.rb', line 23 define_attr :rdlength, BinStruct::Int16 |
#ttl ⇒ Integer
32-bit time to live
19 |
# File 'lib/packetgen/header/dns/rr.rb', line 19 define_attr :ttl, BinStruct::Int32 |
Instance Method Details
#human_rdata ⇒ String
Get human readable rdata
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/packetgen/header/dns/rr.rb', line 94 def human_rdata str = human_ip_rdata || self[:rdata].inspect case type when TYPES['NS'], TYPES['PTR'], TYPES['CNAME'] name = Name.new(dns: self[:name].dns) str = name.read(self[:rdata]).to_human when TYPES['SOA'] str = human_soa_rdata when TYPES['MX'] str = human_mx_data when TYPES['SRV'] str = human_srv_data end str end |
#human_rrclass ⇒ String
Get human readable class
115 116 117 118 119 120 121 122 123 |
# File 'lib/packetgen/header/dns/rr.rb', line 115 def human_rrclass if self[:name].dns.is_a?(MDNS) str = self.class::CLASSES.key(self.rrclass & 0x7fff) || '0x%04x' % (self.rrclass & 0x7fff) str += ' CACHE-FLUSH' if self.rrclass.anybits?(0x8000) str else self.class::CLASSES.key(self.rrclass) || '0x%04x' % self.rrclass end end |
#to_human ⇒ String
126 127 128 |
# File 'lib/packetgen/header/dns/rr.rb', line 126 def to_human "#{human_type} #{human_rrclass} #{name} TTL #{ttl} #{human_rdata}" end |