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/hinfo.rb
Views: 11784
1
# -*- coding: binary -*-
2
##
3
#
4
# Net::DNS::RR::HINFO
5
#
6
# $Id: HINFO.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 HINFO
16
#------------------------------------------------------------
17
class HINFO < RR
18
attr_reader :cpu, :os
19
20
private
21
22
def check_hinfo(str)
23
if str.strip =~ /^["'](.*?)["']\s+["'](.*?)["']$/
24
return $1,$2
25
else
26
raise RRArgumentError, "HINFO section not valid: #{str.inspect}"
27
end
28
end
29
30
def build_pack
31
@hinfo_pack = [@cpu.size].pack("C") + @cpu
32
@hinfo_pack += [@os.size].pack("C") + @os
33
@rdlength = @hinfo_pack.size
34
end
35
36
def set_type
37
@type = Net::DNS::RR::Types.new("HINFO")
38
end
39
40
def get_data
41
@hinfo_pack
42
end
43
44
def get_inspect
45
"#@cpu #@os"
46
end
47
48
def subclass_new_from_hash(args)
49
if args.has_key? :cpu and args.has_key? :os
50
@cpu = args[:cpu]
51
@os = args[:os]
52
else
53
raise RRArgumentError, ":cpu and :os fields are mandatory but missing"
54
end
55
end
56
57
def subclass_new_from_string(str)
58
@cpu,@os = check_hinfo(str)
59
end
60
61
def subclass_new_from_binary(data,offset)
62
len = data.unpack("@#{offset} C")[0]
63
@cpu = data[offset+1..offset+1+len]
64
offset += len+1
65
len = data.unpack("@#{offset} C")[0]
66
@os = data[offset+1..offset+1+len]
67
return offset += len+1
68
end
69
70
end # class HINFO
71
72
end # class RR
73
end # module DNS
74
end # module Net
75
76