Class: Net::DNS::RR::NAPTR

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

Overview

NAME

Net::DNS::RR::NAPTR - DNS NAPTR resource record

DESCRIPTION

Class for DNS Naming Authority Pointer (NAPTR) resource records.

COPYRIGHT

Copyright © 1997-2002 Michael Fuhr.

Portions Copyright © 2002-2004 Chris Reinhardt.

Portions Copyright © 2005 Olaf Kolkman NLnet Labs.

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.

Net::DNS::RR::NAPTR is based on code contributed by Ryan Moats.

SEE ALSO

Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 2168

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, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func

Instance Attribute Details

#flagsObject

Returns the flags field.

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


62
63
64
# File 'lib/Net/DNS/RR/NAPTR.rb', line 62

def flags
  @flags
end

#orderObject

Returns the order field.

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


52
53
54
# File 'lib/Net/DNS/RR/NAPTR.rb', line 52

def order
  @order
end

#preferenceObject

Returns the preference field.

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


57
58
59
# File 'lib/Net/DNS/RR/NAPTR.rb', line 57

def preference
  @preference
end

#regexpObject

Returns the regexp field.

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


72
73
74
# File 'lib/Net/DNS/RR/NAPTR.rb', line 72

def regexp
  @regexp
end

#replacementObject

Returns the replacement field.

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


77
78
79
# File 'lib/Net/DNS/RR/NAPTR.rb', line 77

def replacement
  @replacement
end

#serviceObject

Returns the service field.

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


67
68
69
# File 'lib/Net/DNS/RR/NAPTR.rb', line 67

def service
  @service
end

Instance Method Details

#init_rrsort_funcObject



78
79
80
81
82
# File 'lib/Net/DNS/RR/NAPTR.rb', line 78

def init_rrsort_func 
  set_rrsort_func("order", Proc.new { |a,b| a.order <=> b.order || a.preference <=> b.preference } )                    
  set_rrsort_func("default_sort", get_rrsort_func("order"))
  set_rrsort_func("preference", Proc.new { |a,b| a.preference <=> b.preference || a.order <=> b.order } );
end

#new_from_data(data, offset) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/Net/DNS/RR/NAPTR.rb', line 84

def new_from_data(data, offset)
  if (@rdlength > 0)
    @order = data.unpack("\@#{offset} n")[0];
    offset += Net::DNS::INT16SZ;
    
    @preference = data.unpack("\@#{offset} n")[0];
    offset += Net::DNS::INT16SZ;
    
    len = data.unpack("\@#{offset} C")[0];
    offset+=1;
    @flags = data.unpack("\@#{offset} a#{len}")[0];
    offset += len;
    
    len = data.unpack("\@#{offset} C")[0];
    offset+=1;
    @service = data.unpack("\@#{offset} a#{len}")[0];
    offset += len;
    
    len = data.unpack("\@#{offset} C")[0];
    offset+=1;
    @regexp = data.unpack("\@#{offset} a#{len}")[0];
    offset += len;
    
    @replacement = Net::DNS::Packet::dn_expand(data, offset)[0];
  end
  
end

#new_from_hash(values) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/Net/DNS/RR/NAPTR.rb', line 125

def new_from_hash(values)
  if values.has_key?(:order)
    @order = values[:order]
  end
  if values.has_key?(:preference)
    @preference = values[:preference]
  end
  if values.has_key?(:flags)
    @flags = values[:flags]
  end
  if values.has_key?(:service)
    @service = values[:service]
  end
  if values.has_key?(:regexp)
    @regexp = values[:regexp]
  end
  if values.has_key?(:replacement)
    @replacement = values[:replacement]
  end
end

#new_from_string(string) ⇒ Object



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

def new_from_string(string)
  if (string && string =~ /^(\d+)\s+(\d+)\s+['"] (.*?) ['"] \s+['"] (.*?) ['"] \s+['"] (.*?) ['"] \s+(\S+) $/x)
    
    @order       = $1;
    @preference  = $2;
    @flags       = $3;
    @service     = $4;
    @regexp      = $5;
    @replacement = $6;
    @replacement.sub!(/\.+$/,"");
  end
end

#rdatastrObject



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/Net/DNS/RR/NAPTR.rb', line 146

def rdatastr
  rdatastr=""
  
  if (defined?@order)
    rdatastr = @order.to_s + ' ' +@preference.to_s + ' "'  +@flags.to_s + '" "' +@service.to_s + '" "' +@regexp.to_s + '" ' +@replacement.to_s + '.';
  else
    rdatastr = '';
  end
  
  return rdatastr;
end

#rr_rdata(packet, offset) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/Net/DNS/RR/NAPTR.rb', line 158

def rr_rdata(packet, offset)
  rdata = "";
  
  if (defined?@order)
    
    rdata += [@order, @preference].pack("n2");
    
    rdata += [@flags.length].pack("C");
    rdata += @flags;
    
    rdata += [@service.length].pack("C");
    rdata += @service;
    
    rdata += [@regexp.length].pack("C");
    rdata += @regexp;
    
    rdata += packet.dn_comp(@replacement, offset + rdata.length);
  end
  
  return rdata;
end