CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/net/dns/rr/mx.rb
Views: 11784
1
# -*- coding: binary -*-
2
##
3
#
4
# Net::DNS::RR::MX
5
#
6
# $Id: MX.rb,v 1.8 2006/07/28 07:33:36 bluemonk Exp $
7
#
8
##
9
10
11
module Net
12
module DNS
13
class RR
14
15
#------------------------------------------------------------
16
# RR type MX
17
#------------------------------------------------------------
18
class MX < RR
19
attr_reader :preference, :exchange
20
21
private
22
23
def check_mx(str)
24
if str.strip =~ /^(\d+)\s+(\S+)$/
25
return $1.to_i,$2
26
else
27
raise RRArgumentError, "MX section not valid"
28
end
29
end
30
31
def build_pack
32
@mx_pack = [@preference].pack("n") + pack_name(@exchange)
33
@rdlength = @mx_pack.size
34
end
35
36
def set_type
37
@type = Net::DNS::RR::Types.new("MX")
38
end
39
40
def get_data
41
@mx_pack
42
end
43
44
def get_inspect
45
"#@preference #@exchange"
46
end
47
48
def subclass_new_from_hash(args)
49
if args.has_key? :preference and args.has_key? :exchange
50
@preference = args[0][:preference].to_i
51
@exchange = args[0][:exchange]
52
else
53
raise RRArgumentError, ":preference and :exchange fields are mandatory but missing"
54
end
55
end
56
57
def subclass_new_from_string(str)
58
@preference,@exchange = check_mx(str)
59
end
60
61
def subclass_new_from_binary(data,offset)
62
@preference = data.unpack("@#{offset} n")[0]
63
offset += 2
64
@exchange,offset = dn_expand(data,offset)
65
return offset
66
end
67
68
end # class MX
69
70
end # class RR
71
end # module DNS
72
end # module Net
73
74