Class: Net::DNS::RR::AAAA

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

Overview

NAME

Net::DNS::RR::AAAA - DNS AAAA resource record

DESCRIPTION

Class for DNS IPv6 Address (AAAA) resource records.

BUGS

The inspect method returns only the preferred method of address representation (“x:x:x:x:x:x:x:x”, as documented in RFC 1884, Section 2.2, Para 1).

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 1886 Section 2, RFC 1884 Sections 2.2 & 2.4.4

Constant Summary collapse

@@Regex =
nil

Constants inherited from Net::DNS::RR

RRS

Instance Attribute Summary collapse

Attributes inherited from Net::DNS::RR

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

Class Method Summary collapse

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

#addressObject

Returns the RR’s address field.

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


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

def address
  @address
end

Class Method Details

.init_regexObject



126
127
128
129
130
131
132
133
134
# File 'lib/Net/DNS/RR/AAAA.rb', line 126

def AAAA.init_regex
  if (@@Regex == nil) 
    @@Regex_8Hex  	=  	/\A (?:[0-9A-Fa-f]{1,4}:){7} [0-9A-Fa-f]{1,4} \z/x  	   #	IPv6 address format a:b:c:d:e:f:g:h
    @@Regex_CompressedHex 	= 	/\A ((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) :: ((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) \z/x 	  #	Compressed IPv6 address format a::b
    @@Regex_6Hex4Dec 	= 	/\A ((?:[0-9A-Fa-f]{1,4}:){6,6}) (\d+)\.(\d+)\.(\d+)\.(\d+) \z/x 	  #	IPv4 mapped IPv6 address format a:b:c:d:e:f:w.x.y.z
    @@Regex_CompressedHex4Dec 	= 	/\A ((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?) :: ((?:[0-9A-Fa-f]{1,4}:)*) (\d+)\.(\d+)\.(\d+)\.(\d+) \z/x 	  #	Compressed IPv4 mapped IPv6 address format a::b:w.x.y.z
    @@Regex 	= 	/ (?:#{@@Regex_8Hex}) | (?:#{@@Regex_CompressedHex}) | (?:#{@@Regex_6Hex4Dec}) | (?:#{@@Regex_CompressedHex4Dec})/x 
  end
end

.is_valid(a) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/Net/DNS/RR/AAAA.rb', line 136

def AAAA.is_valid(a)
  init_regex
  if a =~ @@Regex
    return true
  else
    return false
  end
end

Instance Method Details

#new_from_data(data, offset) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/Net/DNS/RR/AAAA.rb', line 55

def new_from_data(data, offset)
  if (@rdlength > 0)
    addr = data.unpack("\@#{offset} n8");
    #            @address = sprintf("%x:%x:%x:%x:%x:%x:%x:%x", addr);
    @address=""
    addr.each { |x| @address += sprintf("%x:", x) }
    @address = @address[0, @address.length-1]
  end
end

#new_from_hash(values) ⇒ Object



105
106
107
108
109
# File 'lib/Net/DNS/RR/AAAA.rb', line 105

def new_from_hash(values) 
  if (values.has_key?(:address))
    @address=values[:address]
  end
end

#new_from_string(string) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/Net/DNS/RR/AAAA.rb', line 65

def new_from_string(string)
  if (string) 
    # I think this is correct, per RFC 1884 Sections 2.2 & 2.4.4.
    if (string =~ /^(.*):(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
      #			my ($front, $a, $b, $c, $d) = ($1, $2, $3, $4, $5);
      front = $1
      a = $2.to_1
      b = $3.to_i
      c = $4.to_i
      d = $5.to_i
      string = front + sprintf(":%x:%x",(a << 8 | b),(c << 8 | d));
    end
    
    if (string =~ /^(.*)::(.*)$/)
      #			my ($front, $back) = ($1, $2);
      front = $1
      back = $2
      front = front.split(/:/)
      back  = back.split(/:/)
      fill = 8 - (front ? front.length + 1 : 0)- (back  ? back.length  + 1 : 0);
      middle = []
      fill.times {middle.push("0")}
      addr = front + middle + back
    else
      addr = string.split(/:/);
      if (addr.length < 8)
       (8 - addr.length).times {addr.insert(0,"0")}
      end
    end
    
    @address = ""
    addr.each {|a| @address += sprintf("%x:", a.to_i(16))}
    # remove last ':'
    @address= @address[0, @address.length-1]
    
    # sprintf("%x:%x:%x:%x:%x:%x:%x:%x", addr.map { |a| a.to_i(16) });
    #		$self->{"address"} = sprintf("%x:%x:%x:%x:%x:%x:%x:%x", map { hex $_ } @addr);
  end
end

#rdatastrObject



111
112
113
# File 'lib/Net/DNS/RR/AAAA.rb', line 111

def rdatastr
  return @address || '';
end

#rr_rdata(*args) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/Net/DNS/RR/AAAA.rb', line 115

def rr_rdata(*args)
  rdata = "";
  
  if (defined?@address)
    addr = @address.split(/:/)
    rdata += addr.map {|a| a.to_i(16) }.pack("n8");            
  end
  return rdata;
end