Class: Dnsruby::RR::NSAP
- Inherits:
-
Dnsruby::RR
- Object
- Dnsruby::RR
- Dnsruby::RR::NSAP
- Defined in:
- lib/dnsruby/resource/NSAP.rb
Overview
Class for DNS Network Service Access Point (NSAP) resource records. RFC 1706.
Constant Summary collapse
Constants inherited from Dnsruby::RR
Instance Attribute Summary collapse
-
#aa ⇒ Object
The RR’s administrative authority.
-
#afi ⇒ Object
The RR’s authority and format identifier.
-
#area ⇒ Object
The RR’s area identifier.
-
#dfi ⇒ Object
The RR’s DSP format identifier.
-
#id ⇒ Object
The RR’s system identifier.
-
#idi ⇒ Object
The RR’s initial domain identifier.
-
#rd ⇒ Object
The RR’s routing domain identifier.
- #rsvd ⇒ Object
-
#sel ⇒ Object
The RR’s NSAP selector.
Attributes inherited from Dnsruby::RR
#klass, #name, #rdata, #ttl, #type
Class Method Summary collapse
-
.decode_rdata(msg) ⇒ Object
:nodoc: all.
Instance Method Summary collapse
-
#dsp ⇒ Object
The RR’s domain specific part (the DFI, AA, Rsvd, RD, Area, ID, and SEL fields).
-
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all.
-
#from_data(data) ⇒ Object
:nodoc: all.
-
#from_string(s) ⇒ Object
:nodoc: all.
-
#idp ⇒ Object
The RR’s initial domain part (the AFI and IDI fields).
-
#rdata_to_string ⇒ Object
:nodoc: all.
-
#str2bcd(s, bytes) ⇒ Object
—————————————————————————— Usage: str2bcd(STRING, NUM_BYTES).
Methods inherited from Dnsruby::RR
#<=>, #==, #clone, create, #eql?, find_class, #from_hash, get_class, get_num, #hash, implemented_rrs, #init_defaults, new_from_data, new_from_hash, new_from_string, #rdlength, #sameRRset, #to_s
Instance Attribute Details
#aa ⇒ Object
The RR’s administrative authority.
31 32 33 |
# File 'lib/dnsruby/resource/NSAP.rb', line 31 def aa @aa end |
#afi ⇒ Object
The RR’s authority and format identifier. Dnsruby currently supports only AFI 47 (GOSIP Version 2).
25 26 27 |
# File 'lib/dnsruby/resource/NSAP.rb', line 25 def afi @afi end |
#area ⇒ Object
The RR’s area identifier.
35 36 37 |
# File 'lib/dnsruby/resource/NSAP.rb', line 35 def area @area end |
#dfi ⇒ Object
The RR’s DSP format identifier.
29 30 31 |
# File 'lib/dnsruby/resource/NSAP.rb', line 29 def dfi @dfi end |
#id ⇒ Object
The RR’s system identifier.
37 38 39 |
# File 'lib/dnsruby/resource/NSAP.rb', line 37 def id @id end |
#idi ⇒ Object
The RR’s initial domain identifier.
27 28 29 |
# File 'lib/dnsruby/resource/NSAP.rb', line 27 def idi @idi end |
#rd ⇒ Object
The RR’s routing domain identifier.
33 34 35 |
# File 'lib/dnsruby/resource/NSAP.rb', line 33 def rd @rd end |
#rsvd ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/dnsruby/resource/NSAP.rb', line 57 def rsvd if (@rsvd==nil) return "0000" else return @rsvd end end |
#sel ⇒ Object
The RR’s NSAP selector.
39 40 41 |
# File 'lib/dnsruby/resource/NSAP.rb', line 39 def sel @sel end |
Class Method Details
.decode_rdata(msg) ⇒ Object
:nodoc: all
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/dnsruby/resource/NSAP.rb', line 142 def self.decode_rdata(msg) #:nodoc: all afi = msg.get_unpack("C")[0] afi = sprintf("%02x", afi) if (afi == "47") idi = msg.get_unpack("CC") dfi = msg.get_unpack("C")[0] aa = msg.get_unpack("CCC") rsvd = msg.get_unpack("CC") rd = msg.get_unpack("CC") area = msg.get_unpack("CC") id = msg.get_unpack("CCCCCC") sel = msg.get_unpack("C")[0] idi = sprintf("%02x%02x", idi[0], idi[1]) dfi = sprintf("%02x", dfi) aa = sprintf("%02x%02x%02x", aa[0], aa[1], aa[2]) rsvd = sprintf("%02x%02x", rsvd[0],rsvd[1]) rd = sprintf("%02x%02x", rd[0],rd[1]) area = sprintf("%02x%02x", area[0],area[1]) id = sprintf("%02x%02x%02x%02x%02x%02x", id[0],id[1],id[2],id[3],id[4],id[5]) sel = sprintf("%02x", sel) else # What to do for unsupported versions? end return self.new([afi, idi, dfi, aa, rsvd, rd, area, id, sel]) end |
Instance Method Details
#dsp ⇒ Object
The RR’s domain specific part (the DFI, AA, Rsvd, RD, Area, ID, and SEL fields).
52 53 54 55 |
# File 'lib/dnsruby/resource/NSAP.rb', line 52 def dsp ret = [@dfi,@aa,rsvd,@rd,@area,@id,@sel].join('') return ret end |
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/dnsruby/resource/NSAP.rb', line 122 def encode_rdata(msg, canonical=false) #:nodoc: all if (defined?@afi) msg.put_pack("C", @afi.to_i(16)) if (@afi == "47") msg.put_bytes(str2bcd(@idi, 2)) msg.put_bytes(str2bcd(@dfi, 1)) msg.put_bytes(str2bcd(@aa, 3)) msg.put_bytes(str2bcd(0, 2)) # rsvd) msg.put_bytes(str2bcd(@rd, 2)) msg.put_bytes(str2bcd(@area, 2)) msg.put_bytes(str2bcd(@id, 6)) msg.put_bytes(str2bcd(@sel, 1)) end # Checks for other versions would go here. end return rdata end |
#from_data(data) ⇒ Object
:nodoc: all
90 91 92 |
# File 'lib/dnsruby/resource/NSAP.rb', line 90 def from_data(data) #:nodoc: all @afi, @idi, @dfi, @aa, @rsvd, @rd, @area, @id, @sel = data end |
#from_string(s) ⇒ Object
:nodoc: all
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dnsruby/resource/NSAP.rb', line 94 def from_string(s) #:nodoc: all if (s) string = s.gsub(/\./, ""); # remove all dots. string.gsub!(/^0x/,""); # remove leading 0x if (string =~ /^[a-zA-Z0-9]{40}$/) (@afi, @idi, @dfi, @aa, @rsvd, @rd, @area, @id, @sel) = string.unpack("A2A4A2A6A4A4A4A12A2") end end end |
#idp ⇒ Object
The RR’s initial domain part (the AFI and IDI fields).
45 46 47 48 |
# File 'lib/dnsruby/resource/NSAP.rb', line 45 def idp ret = [@afi, @idi].join('') return ret end |
#rdata_to_string ⇒ Object
:nodoc: all
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/dnsruby/resource/NSAP.rb', line 106 def rdata_to_string #:nodoc: all rdatastr="" if (defined?@afi) if (@afi == "47") rdatastr = [idp, dsp].join('') else rdatastr = "; AFI #{@afi} not supported" end else rdatastr = '' end return rdatastr end |
#str2bcd(s, bytes) ⇒ Object
Usage: str2bcd(STRING, NUM_BYTES)
Takes a string representing a hex number of arbitrary length and
returns an equivalent BCD string of NUM_BYTES length (with
NUM_BYTES * 2 digits), adding leading zeros if necessary.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dnsruby/resource/NSAP.rb', line 72 def str2bcd(s, bytes) retval = ""; digits = bytes * 2; string = sprintf("%#{digits}s", s); string.tr!(" ","0"); i=0; bytes.times do bcd = string[i*2, 2]; retval += [bcd.to_i(16)].pack("C"); i+=1 end return retval; end |