Class: Net::DNS::RR::NSAP

Inherits:
Net::DNS::RR show all
Defined in:
lib/Net/DNS/RR/NSAP.rb

Overview

NAME

Net::DNS::RR::NSAP - DNS NSAP resource record

DESCRIPTION

Class for DNS Network Service Access Point (NSAP) resource records.

COPYRIGHT

Copyright © 1997-2002 Michael Fuhr.

Portions Copyright © 2002-2004 Chris Reinhardt.

Ruby version Copyright © 2006 AlexD (Nominet UK)

All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself..

SEE ALSO

Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 1706.

Constant Summary

Constants inherited from Net::DNS::RR

RRS

Instance Attribute Summary collapse

Attributes inherited from Net::DNS::RR

#name, #rdata, #rdlength, #rrclass, #ttl, #type

Instance Method Summary collapse

Methods inherited from Net::DNS::RR

#_canonicalRdata, #_canonicaldata, _get_subclass, _name2wire, #_name2wire, build_regex, create, #create_rrsort_func, #data, #get_rrsort_func, #init, #init_rrsort_func, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func

Instance Attribute Details

#aaObject

Returns the RR’s administrative authority.

print "aa = ", rr.aa, "\n"


64
65
66
# File 'lib/Net/DNS/RR/NSAP.rb', line 64

def aa
  @aa
end

#afiObject

Returns the RR’s authority and format identifier. Net::DNS currently supports only AFI 47 (GOSIP Version 2).

print "afi = ", rr.afi, "\n"


49
50
51
# File 'lib/Net/DNS/RR/NSAP.rb', line 49

def afi
  @afi
end

#areaObject

Returns the RR’s area identifier.

print "area = ", rr.area, "\n"


74
75
76
# File 'lib/Net/DNS/RR/NSAP.rb', line 74

def area
  @area
end

#dfiObject

Returns the RR’s DSP format identifier.

print "dfi = ", rr.dfi, "\n"


59
60
61
# File 'lib/Net/DNS/RR/NSAP.rb', line 59

def dfi
  @dfi
end

#idObject

Returns the RR’s system identifier.

print "id = ", rr.id, "\n"


79
80
81
# File 'lib/Net/DNS/RR/NSAP.rb', line 79

def id
  @id
end

#idiObject

Returns the RR’s initial domain identifier.

print "idi = ", rr.idi, "\n"


54
55
56
# File 'lib/Net/DNS/RR/NSAP.rb', line 54

def idi
  @idi
end

#rdObject

Returns the RR’s routing domain identifier.

print "rd = ", rr.rd, "\n"


69
70
71
# File 'lib/Net/DNS/RR/NSAP.rb', line 69

def rd
  @rd
end

#rsvdObject



197
198
199
200
201
202
203
# File 'lib/Net/DNS/RR/NSAP.rb', line 197

def rsvd
  if (@rsvd==nil)
    return "0000"
  else
    return @rsvd
  end
end

#selObject

Returns the RR’s NSAP selector.

print "sel = ", rr.sel, "\n"


84
85
86
# File 'lib/Net/DNS/RR/NSAP.rb', line 84

def sel
  @sel
end

Instance Method Details

#dspObject

Returns the RR’s domain specific part (the DFI, AA, Rsvd, RD, Area, ID, and SEL fields).

print "dsp = ", rr.dsp, "\n"


192
193
194
195
# File 'lib/Net/DNS/RR/NSAP.rb', line 192

def dsp
  ret = [@dfi,@aa,rsvd,@rd,@area,@id,@sel].join('')
  return ret
end

#idpObject

Returns the RR’s initial domain part (the AFI and IDI fields).

print "idp = ", rr.idp, "\n"


182
183
184
185
# File 'lib/Net/DNS/RR/NSAP.rb', line 182

def idp
  ret = [@afi, @idi].join('')
  return ret
end

#new_from_data(data, offset) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/Net/DNS/RR/NSAP.rb', line 90

def new_from_data(data, offset)
  if (@rdlength > 0)
    afi = data.unpack("\@#{offset} C")[0];
    @afi = sprintf("%02x", afi);
    offset+=1;
    
    if (@afi == "47")
      idi = data.unpack("\@#{offset} C2");
      offset += 2;
      
      dfi = data.unpack("\@#{offset} C")[0];
      offset += 1;
      
      aa = data.unpack("\@#{offset} C3");
      offset += 3;
      
      rsvd = data.unpack("\@#{offset} C2");
      offset += 2;
      
      rd = data.unpack("\@#{offset} C2");
      offset += 2;
      
      area = data.unpack("\@#{offset} C2");
      offset += 2;
      
      id = data.unpack("\@#{offset} C6");
      offset += 6;
      
      sel = data.unpack("\@#{offset} C")[0];
      offset += 1;
      
      @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
  end
end

#new_from_hash(values) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/Net/DNS/RR/NSAP.rb', line 136

def new_from_hash(values)
  if values.has_key?(:idi)
    @idi = values[:idi]
  end
  if values.has_key?(:dfi)
    @dfi = values[:dfi]
  end
  if values.has_key?(:afi)
    @afi = values[:afi]
  end
  if values.has_key?(:aa)
    @aa = values[:aa]
  end
  if values.has_key?(:sel)
    @sel = values[:sel]
  end
  if values.has_key?(:id)
    @id = values[:id]
  end
  if values.has_key?(:rsvd)
    @rsvd = values[:rsvd]
  end
  if values.has_key?(:rd)
    @rd = values[:rd]
  end
  if values.has_key?(:area)
    @area = values[:area]
  end
end

#new_from_string(s) ⇒ Object



166
167
168
169
170
171
172
173
174
175
# File 'lib/Net/DNS/RR/NSAP.rb', line 166

def new_from_string(s)
  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

#rdatastrObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/Net/DNS/RR/NSAP.rb', line 205

def rdatastr
  rdatastr=""
  
  if (defined?@afi)
    if (@afi == "47")
      rdatastr = [idp, dsp].join('')
    else
      rdatastr = "; AFI #{@afi} not supported"
    end
  else
    rdatastr = ''
  end
  
  return rdatastr
end

#rr_rdata(*args) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/Net/DNS/RR/NSAP.rb', line 221

def rr_rdata(*args)
  rdata = ""
  
  if (defined?@afi)
    #            rdata += [@afi.to_i().to_s(16).to_i()].pack("C");
    rdata += [@afi.to_i(16)].pack("C")
    
    if (@afi == "47")
      rdata += str2bcd(@idi,  2)
      rdata += str2bcd(@dfi,  1)
      rdata += str2bcd(@aa,   3)
      rdata += str2bcd(0,               2)	# rsvd
      rdata += str2bcd(@rd,   2)
      rdata += str2bcd(@area, 2)
      rdata += str2bcd(@id,   6)
      rdata += str2bcd(@sel,  1)
    end            
    # Checks for other versions would go here.
  end
  
  return rdata
end

#str2bcd(s, bytes) ⇒ Object

This can’t be the best way.…



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/Net/DNS/RR/NSAP.rb', line 253

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