Class: Dnsruby::RR::IN::SRV

Inherits:
Dnsruby::RR show all
Defined in:
lib/dnsruby/resource/SRV.rb

Overview

SRV resource record defined in RFC 2782

These records identify the hostname and port that a service is
available at.

The format is:
  _Service._Proto.Name TTL Class SRV Priority Weight Port Target

The fields specific to SRV are defined in RFC 2782

Constant Summary

Constants inherited from Dnsruby::RR

ClassInsensitiveTypes

Instance Attribute Summary collapse

Attributes inherited from Dnsruby::RR

#klass, #name, #rdata, #ttl, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dnsruby::RR

#<=>, #==, #clone, create, #eql?, find_class, 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

#portObject

The port on this target host of this service. The range is 0-65535.



50
51
52
# File 'lib/dnsruby/resource/SRV.rb', line 50

def port
  @port
end

#priorityObject

The priority of this target host.

A client MUST attempt
to contact the target host with the lowest-numbered priority it can
reach; target hosts with the same priority SHOULD be tried in an
order defined by the weight field.  The range is 0-65535.  Note that
it is not widely implemented and should be set to zero.


37
38
39
# File 'lib/dnsruby/resource/SRV.rb', line 37

def priority
  @priority
end

#targetObject

The domain name of the target host. A target of “.” means

that the service is decidedly not available at this domain.


54
55
56
# File 'lib/dnsruby/resource/SRV.rb', line 54

def target
  @target
end

#weightObject

A server selection mechanism.

The weight field specifies
a relative weight for entries with the same priority. Larger weights
SHOULD be given a proportionately higher probability of being
selected. The range of this number is 0-65535.  Domain administrators
SHOULD use Weight 0 when there isn't any server selection to do, to
make the RR easier to read for humans (less noisy). Note that it is
not widely implemented and should be set to zero.


47
48
49
# File 'lib/dnsruby/resource/SRV.rb', line 47

def weight
  @weight
end

Class Method Details

.decode_rdata(msg) ⇒ Object

:nodoc: all



102
103
104
105
106
107
108
# File 'lib/dnsruby/resource/SRV.rb', line 102

def self.decode_rdata(msg) #:nodoc: all
  priority, = msg.get_unpack("n")
  weight,   = msg.get_unpack("n")
  port,     = msg.get_unpack("n")
  target    = msg.get_name
  return self.new([priority, weight, port, target])
end

Instance Method Details

#encode_rdata(msg, canonical = false) ⇒ Object

:nodoc: all



95
96
97
98
99
100
# File 'lib/dnsruby/resource/SRV.rb', line 95

def encode_rdata(msg, canonical=false) #:nodoc: all
  msg.put_pack("n", @priority)
  msg.put_pack("n", @weight)
  msg.put_pack("n", @port)
  msg.put_name(@target,canonical)
end

#from_data(data) ⇒ Object

:nodoc: all



56
57
58
# File 'lib/dnsruby/resource/SRV.rb', line 56

def from_data(data) #:nodoc: all
  @priority, @weight, @port, @target = data
end

#from_hash(hash) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dnsruby/resource/SRV.rb', line 60

def from_hash(hash)
  if hash[:priority]
    @priority = hash[:priority].to_i
  end
  if hash[:weight]
    @weight = hash[:weight].to_i
  end
  if hash[:port]
    @port = hash[:port].to_i
  end
  if hash[:target]
    @target= Name.create(hash[:target])
  end
end

#from_string(input) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dnsruby/resource/SRV.rb', line 75

def from_string(input)
  if (input.length > 0)
    names = input.split(" ")
    @priority = names[0].to_i
    @weight = names[1].to_i
    @port = names[2].to_i
    if (names[3])
      @target = Name.create(names[3])
    end
  end
end

#rdata_to_stringObject



87
88
89
90
91
92
93
# File 'lib/dnsruby/resource/SRV.rb', line 87

def rdata_to_string
  if (@target!=nil)
    return "#{@priority} #{@weight} #{@port} #{@target.to_s(true)}"
  else
    return ""
  end
end