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/soa.rb
Views: 11784
1
# -*- coding: binary -*-
2
##
3
#
4
# Net::DNS::RR::SOA
5
#
6
# $Id: SOA.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
7
#
8
##
9
10
module Net
11
module DNS
12
class RR
13
14
#------------------------------------------------------------
15
# RR type SOA
16
#------------------------------------------------------------
17
class SOA < RR
18
attr_reader :mname, :rname, :serial, :refresh, :retry, :expire, :minimum
19
20
private
21
22
def build_pack
23
@soa_pack = pack_name(@mname)
24
@soa_pack += pack_name(@rname)
25
@soa_pack += [@serial,@refresh,@retry,@expire,@minimum].pack("N5")
26
end
27
28
def set_type
29
@type = Net::DNS::RR::Types.new("SOA")
30
end
31
32
def get_data
33
@soa_pack
34
end
35
36
def get_inspect
37
"#@mname #@rname #@serial #@refresh #@retry #@expire #@minimum"
38
end
39
40
def subclass_new_from_hash(args)
41
if args.has_key? :rdata
42
subclass_new_from_string(args[:rdata])
43
else
44
[:mname,:rname,:serial,:refresh,:retry,:expire,:minimum].each do |key|
45
raise RRArgumentError, "Missing field :#{key}" unless args.has_key? key
46
end
47
@mname = args[:mname] if valid? args[:mname]
48
@rname = args[:rname] if valid? args[:rname]
49
@serial = args[:serial] if number? args[:serial]
50
@refresh = args[:refresh] if number? args[:refresh]
51
@retry = args[:retry] if number? args[:retry]
52
@expire = args[:expire] if number? args[:expire]
53
@minimum = args[:minimum] if number? args[:minimum]
54
end
55
end
56
57
def number?(num)
58
if num.kind_of? Integer and num > 0
59
true
60
else
61
raise RRArgumentError, "Wrong format field: #{num} not a number or less than zero"
62
end
63
end
64
65
def subclass_new_from_string(str)
66
mname,rname,serial,refresh,ret,expire,minimum = str.strip.split(" ")
67
@mname = mname if valid? mname
68
@rname = rname if valid? rname
69
@serial,@refresh,@retry,@expire,@minimum = [serial,refresh,ret,expire,minimum].collect do |i|
70
i.to_i if valid? i.to_i
71
end
72
end
73
74
def subclass_new_from_binary(data,offset)
75
@mname,offset = dn_expand(data,offset)
76
@rname,offset = dn_expand(data,offset)
77
@serial,@refresh,@retry,@expire,@minimum = data.unpack("@#{offset} N5")
78
return offset + 5*Net::DNS::INT32SZ
79
end
80
81
end # class SOA
82
83
end # class RR
84
end # module DNS
85
end # module Net
86
87