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/txt.rb
Views: 11784
1
# -*- coding: binary -*-
2
##
3
#
4
# Net::DNS::RR::TXT
5
#
6
# $Id: TXT.rb,v 1.4 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 TXT
17
#------------------------------------------------------------
18
class TXT < RR
19
attr_reader :txt
20
21
private
22
23
def build_pack
24
str = ""
25
@txt.split(" ").each do |txt|
26
str += [txt.length,txt].pack("C a*")
27
end
28
@txt_pack = str
29
@rdlength = @txt_pack.size
30
end
31
32
def set_type
33
@type = Net::DNS::RR::Types.new("TXT")
34
end
35
36
def get_data
37
@txt_pack
38
end
39
40
def subclass_new_from_hash(args)
41
if args.has_key? :txt
42
@txt = args[:txt].strip
43
else
44
raise RRArgumentError, ":txt field is mandatory but missing"
45
end
46
end
47
48
def subclass_new_from_string(str)
49
@txt = str.strip
50
end
51
52
def subclass_new_from_binary(data,offset)
53
off_end = offset + @rdlength
54
@txt = ""
55
while offset < off_end
56
len = data.unpack("@#{offset} C")[0]
57
offset += 1
58
str = data[offset..offset+len-1]
59
offset += len
60
@txt << str << " "
61
end
62
return offset
63
end
64
65
end # class TXT
66
67
end # class RR
68
end # module DNS
69
end # module Net
70
71