Class: PacketGen::Header::DNS::RR
- Inherits:
-
Question
- Object
- Types::Fields
- Question
- PacketGen::Header::DNS::RR
- Defined in:
- lib/packetgen/header/dns/rr.rb
Overview
DNS Ressource Record
Direct Known Subclasses
Constant Summary
Constants inherited from Question
Question::CLASSES, Question::TYPES
Instance Attribute Summary collapse
- #rdata ⇒ Types::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
Methods included from Types::Fieldable
#format_inspect, #read, #sz, #to_s, #type_name
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
#initialize(dns, options = {}) ⇒ RR
Returns a new instance of RR.
37 38 39 40 41 42 |
# File 'lib/packetgen/header/dns/rr.rb', line 37 def initialize(dns, ={}) super return unless [:rdata] && [:rdlength].nil? self.rdata = [:rdata] end |
Instance Attribute Details
#rdata ⇒ Types::String
25 26 |
# File 'lib/packetgen/header/dns/rr.rb', line 25 define_field :rdata, Types::String, builder: ->(rr, t) { t.new(length_from: rr[:rdlength]) } |
Instance Method Details
#human_rdata ⇒ String
Get human readable rdata
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/packetgen/header/dns/rr.rb', line 58 def human_rdata str = human_ip_rdata || self[:rdata].inspect case type when TYPES['NS'], TYPES['PTR'], TYPES['CNAME'] name = Name.new name.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
80 81 82 83 84 85 86 87 88 |
# File 'lib/packetgen/header/dns/rr.rb', line 80 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 & 0x8000).positive? str else self.class::CLASSES.key(self.rrclass) || '0x%04x' % self.rrclass end end |
#to_human ⇒ String
91 92 93 |
# File 'lib/packetgen/header/dns/rr.rb', line 91 def to_human "#{human_type} #{human_rrclass} #{name} TTL #{ttl} #{human_rdata}" end |