Class: Net::DNS::RR::MX

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

Overview

NAME

Net::DNS::RR::MX - DNS MX resource record

DESCRIPTION

Class for DNS Mail Exchanger (MX) 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.

SEE ALSO

Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 1035 Section 3.3.9

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

#exchangeObject

Returns name of this mail exchange.

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


55
56
57
# File 'lib/Net/DNS/RR/MX.rb', line 55

def exchange
  @exchange
end

#preferenceObject

Returns the preference for this mail exchange.

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


50
51
52
# File 'lib/Net/DNS/RR/MX.rb', line 50

def preference
  @preference
end

Instance Method Details

#_canonicalRdataObject



111
112
113
114
115
116
117
118
119
120
# File 'lib/Net/DNS/RR/MX.rb', line 111

def _canonicalRdata 
  rdata = "";
  
  if (defined?@preference)
    rdata += [@preference].pack("n");
    rdata += _name2wire(@exchange)
  end
  
  return rdata;
end

#init_rrsort_funcObject



56
57
58
59
60
61
# File 'lib/Net/DNS/RR/MX.rb', line 56

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

#new_from_data(data, offset) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/Net/DNS/RR/MX.rb', line 65

def new_from_data(data, offset)
  if (@rdlength > 0)
    @preference = data.unpack("\@#{offset} n")[0];
    offset += Net::DNS::INT16SZ;
    
    @exchange = Net::DNS::Packet.dn_expand(data, offset)[0];
  end
end

#new_from_hash(values) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/Net/DNS/RR/MX.rb', line 83

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

#new_from_string(string) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/Net/DNS/RR/MX.rb', line 74

def new_from_string(string)
  
  if (string && (string =~ /^(\d+)\s+(\S+)$/))
    @preference = $1.to_i;
    @exchange   = $2;
    @exchange.gsub(/\.+$/, "")
  end
end

#rdatastrObject



92
93
94
95
96
97
98
# File 'lib/Net/DNS/RR/MX.rb', line 92

def rdatastr
  if (defined?@preference)
    return "#{@preference} #{@exchange}" 
  else
   '';
  end
end

#rr_rdata(packet, offset) ⇒ Object



100
101
102
103
104
105
106
107
108
109
# File 'lib/Net/DNS/RR/MX.rb', line 100

def rr_rdata(packet, offset)
  rdata = "";
  
  if (defined?@preference)
    rdata += [@preference].pack("n");
    rdata += packet.dn_comp(@exchange, offset + rdata.length);
  end
  
  return rdata;
end