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/aaaa.rb
Views: 11784
1
# -*- coding: binary -*-
2
##
3
#
4
# Net::DNS::RR::AAAA
5
#
6
# $id$
7
#
8
##
9
10
require 'ipaddr'
11
12
module Net
13
module DNS
14
15
class RR
16
17
#
18
# RR type AAAA
19
#
20
class AAAA < RR
21
attr_reader :address
22
23
# Assign to the RR::AAAA object a new IPv6 address, which can be in the
24
# form of a string or an IPAddr object
25
#
26
# a.address = "::1"
27
# a.address = IPAddr.new("::1")
28
#
29
def address=(addr)
30
@address = check_address addr
31
build_pack
32
end # address=
33
34
private
35
36
def check_address(addr)
37
address = ""
38
case addr
39
when String
40
address = IPAddr.new addr
41
when IPAddr
42
address = addr
43
else
44
raise RRArgumentError, "Unknown address type: #{addr.inspect}"
45
end
46
raise RRArgumentError, "Must specify an IPv6 address" unless address.ipv6?
47
address
48
rescue ArgumentError
49
raise RRArgumentError, "Invalid address #{addr.inspect}"
50
end
51
52
def build_pack
53
@address_pack = @address.hton
54
@rdlength = @address_pack.size
55
end
56
57
def set_type
58
@type = Net::DNS::RR::Types.new("AAAA")
59
end
60
61
def get_data
62
@address_pack
63
end
64
65
def get_inspect
66
"#@address"
67
end
68
69
def subclass_new_from_hash(args)
70
if args.has_key? :address
71
@address = check_address args[:address]
72
else
73
raise RRArgumentError, ":address field is mandatory but missing"
74
end
75
end
76
77
def subclass_new_from_string(str)
78
@address = check_address(str)
79
end
80
81
def subclass_new_from_binary(data,offset)
82
arr = data.unpack("@#{offset} n8")
83
@address = IPAddr.new sprintf("%x:%x:%x:%x:%x:%x:%x:%x",*arr)
84
return offset + 16
85
end
86
87
end # class AAAA
88
89
end # class RR
90
end # module DNS
91
end # module Net
92
93