Class: Net::DNS::RR::SRV

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

Overview

NAME

Net::DNS::RR::SRV - DNS SRV resource record

DESCRIPTION

Class for DNS Service (SRV) 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 2782

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

#_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

#portObject

Returns the port on this target host for the service.

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


58
59
60
# File 'lib/Net/DNS/RR/SRV.rb', line 58

def port
  @port
end

#priorityObject

Returns the priority for this target host.

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


48
49
50
# File 'lib/Net/DNS/RR/SRV.rb', line 48

def priority
  @priority
end

#targetObject

Returns the target host.

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


63
64
65
# File 'lib/Net/DNS/RR/SRV.rb', line 63

def target
  @target
end

#weightObject

Returns the weight for this target host.

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


53
54
55
# File 'lib/Net/DNS/RR/SRV.rb', line 53

def weight
  @weight
end

Instance Method Details

#_canonicalRdataObject



140
141
142
143
144
145
146
147
148
149
# File 'lib/Net/DNS/RR/SRV.rb', line 140

def _canonicalRdata
  rdata = '';
  
  if (defined?priority)
    rdata += [@priority.to_i, @weight.to_i, @port.to_i].pack('n3');
    rdata += _name2wire(@target);
  end
  
  return rdata;
end

#init_rrsort_funcObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/Net/DNS/RR/SRV.rb', line 64

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

#new_from_data(data, offset) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/Net/DNS/RR/SRV.rb', line 79

def new_from_data(data, offset) 
  if (@rdlength > 0)
    ret = data.unpack("\@#{offset} n3");
    @priority = ret[0]
    @weight = ret[1]
    @port = ret[2]
    offset += 3 * Net::DNS::INT16SZ;
    
    @target = Net::DNS::Packet.dn_expand(data, offset)[0];
  end
end

#new_from_hash(values) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/Net/DNS/RR/SRV.rb', line 91

def new_from_hash(values)
  if (values.has_key?:priority)
    @priority = values[:priority]
  end
  if (values.has_key?:weight)
    @weight = values[:weight]
  end
  if (values.has_key?:port)
    @port = values[:port]
  end
  if (values.has_key?:target)
    @target = values[:target]
  end
end

#new_from_string(string) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/Net/DNS/RR/SRV.rb', line 106

def new_from_string(string)
  if (string && (string =~ /^(\d+)\s+(\d+)\s+(\d+)\s+(\S+)$/))
    @priority = $1.to_i
    @weight = $2.to_i
    @port = $3.to_i
    @target = $4
    
    @target.sub!(/\.+$/, "");
  end
end

#rdatastrObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/Net/DNS/RR/SRV.rb', line 117

def rdatastr
  if (defined?@priority)
    rdatastr = [@priority, @weight, @port, @target].join(' ');
    rdatastr.sub!(/(.*[^\.])$/) { |s| s+"." };
  else
    rdatastr = '';
  end
  
  return rdatastr;
end

#rr_rdata(packet, offset) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/Net/DNS/RR/SRV.rb', line 128

def rr_rdata(packet, offset)
  rdata = '';
  
  if (defined?priority)
    rdata += [@priority, @weight, @port].pack('n3');
    rdata += packet.dn_comp(@target, offset + rdata.length );
  end
  
  return rdata;
end