net-dns 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::MR
4
+ #
5
+ # $Id: MR.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+ module Net
10
+ module DNS
11
+
12
+ class RR
13
+
14
+ #------------------------------------------------------------
15
+ # RR type MR
16
+ #------------------------------------------------------------
17
+ class MR < RR
18
+ attr_reader :newname
19
+
20
+ private
21
+
22
+ def check_name(name)
23
+ unless name =~ /(\w\.?)+\s*$/
24
+ raise RRArgumentError, "Name not valid: #{name.inspect}"
25
+ end
26
+ name
27
+ end
28
+
29
+ def build_pack
30
+ @newname_pack = pack_name(@newname)
31
+ @rdlength = @newname_pack.size
32
+ end
33
+
34
+ def set_type
35
+ @type = Net::DNS::RR::Types.new("MR")
36
+ end
37
+
38
+ def get_data
39
+ @newname_pack
40
+ end
41
+
42
+ def get_inspect
43
+ "#@newname"
44
+ end
45
+
46
+ def subclass_new_from_hash(args)
47
+ if args.has_key? :newname
48
+ @newname = check_name args[:newname]
49
+ else
50
+ raise RRArgumentError, ":newname field is mandatory but missing"
51
+ end
52
+ end
53
+
54
+ def subclass_new_from_string(str)
55
+ @newname = check_name(str)
56
+ end
57
+
58
+ def subclass_new_from_array(data,offset)
59
+ @newname = dn_expand(data,offset)
60
+ return offset
61
+ end
62
+
63
+ end # class MR
64
+
65
+ end # class RR
66
+ end # module DNS
67
+ end # module Net
68
+
@@ -0,0 +1,74 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::MX
4
+ #
5
+ # $Id: MX.rb,v 1.8 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+
10
+ module Net
11
+ module DNS
12
+ class RR
13
+
14
+ #------------------------------------------------------------
15
+ # RR type MX
16
+ #------------------------------------------------------------
17
+ class MX < RR
18
+ attr_reader :preference, :exchange
19
+
20
+ private
21
+
22
+ def check_mx(str)
23
+ if str.strip =~ /^(\d+)\s+(\S+)$/
24
+ return $1.to_i,$2
25
+ else
26
+ raise RRArgumentError, "MX section not valid"
27
+ end
28
+ end
29
+
30
+ def build_pack
31
+ @mx_pack = [@preference].pack("n") + pack_name(@exchange)
32
+ @rdlength = @mx_pack.size
33
+ end
34
+
35
+ def set_type
36
+ @type = Net::DNS::RR::Types.new("MX")
37
+ end
38
+
39
+ def get_data
40
+ @mx_pack
41
+ end
42
+
43
+ def get_inspect
44
+ "#@preference #@exchange"
45
+ end
46
+
47
+ def subclass_new_from_hash(args)
48
+ if args.has_key? :preference and args.has_key? :exchange
49
+ @preference = args[0][:preference].to_i
50
+ @exchange = args[0][:exchange]
51
+ else
52
+ raise RRArgumentError, ":preference and :exchange fields are mandatory but missing"
53
+ end
54
+ end
55
+
56
+ def subclass_new_from_string(str)
57
+ @preference,@exchange = check_mx(str)
58
+ end
59
+
60
+ def subclass_new_from_binary(data,offset)
61
+ @preference = data.unpack("@#{offset} n")[0]
62
+ offset += 2
63
+ @exchange,offset = dn_expand(data,offset)
64
+ return offset
65
+ end
66
+
67
+ end # class MX
68
+
69
+ end # class RR
70
+ end # module DNS
71
+ end # module Net
72
+
73
+
74
+
@@ -0,0 +1,70 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::NS
4
+ #
5
+ # $Id: NS.rb,v 1.8 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+ module Net
10
+ module DNS
11
+
12
+ class RR
13
+
14
+ #------------------------------------------------------------
15
+ # RR type NS
16
+ #------------------------------------------------------------
17
+ class NS < RR
18
+ attr_reader :nsdname
19
+
20
+ private
21
+
22
+ def check_name(name)
23
+ unless name =~ /(\w\.?)+\s*$/ and name =~ /[a-zA-Z]/
24
+ raise RRArgumentError, "NS Domain Name not valid: #{name}"
25
+ end
26
+ name
27
+ end
28
+
29
+ def build_pack
30
+ @nsdname_pack = pack_name(@nsdname)
31
+ @rdlength = @nsdname_pack.size
32
+ end
33
+
34
+ def set_type
35
+ @type = Net::DNS::RR::Types.new("NS")
36
+ end
37
+
38
+ def get_data
39
+ @nsdname_pack
40
+ end
41
+
42
+ def get_inspect
43
+ "#@nsdname"
44
+ end
45
+
46
+ def subclass_new_from_hash(args)
47
+ if args.has_key? :nsdname
48
+ @nsdname = check_name args[:nsdname]
49
+ else
50
+ raise RRArgumentError, ":nsdname field is mandatory but missing"
51
+ end
52
+ end
53
+
54
+ def subclass_new_from_string(str)
55
+ @nsdname = check_name(str)
56
+ end
57
+
58
+ def subclass_new_from_binary(data,offset)
59
+ @nsdname,offset = dn_expand(data,offset)
60
+ return offset
61
+ end
62
+
63
+ end # class NS
64
+
65
+ end # class RR
66
+ end # module DNS
67
+ end # module Net
68
+
69
+
70
+
@@ -0,0 +1,61 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::NULL
4
+ #
5
+ # $Id: NULL.rb,v 1.5 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+
10
+ module Net
11
+ module DNS
12
+ class RR
13
+
14
+ #------------------------------------------------------------
15
+ # RR type NULL
16
+ #------------------------------------------------------------
17
+ class NULL < RR
18
+ attr_reader :null
19
+
20
+ private
21
+
22
+ def build_pack
23
+ @null_pack = @null
24
+ @rdlength = @null_pack.size
25
+ end
26
+
27
+ def set_type
28
+ @type = Net::DNS::RR::RRTypes.new("NULL")
29
+ end
30
+
31
+ def get_data
32
+ @null_pack
33
+ end
34
+
35
+ def get_inspect
36
+ "#@null"
37
+ end
38
+
39
+ def subclass_new_from_hash(args)
40
+ if args.has_key? :null
41
+ @null = args[:null]
42
+ else
43
+ raise RRArgumentError, ":null field is mandatory but missing"
44
+ end
45
+ end
46
+
47
+ def subclass_new_from_string(str)
48
+ @null = str.strip
49
+ end
50
+
51
+ def subclass_new_from_binary(data,offset)
52
+ @null = data[offset..offset+@rdlength]
53
+ return offset + @rdlength
54
+ end
55
+
56
+ end # class NULL
57
+
58
+ end # class RR
59
+ end # module DNS
60
+ end # module Net
61
+
@@ -0,0 +1,71 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::PTR
4
+ #
5
+ # $Id: PTR.rb,v 1.5 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+ module Net
10
+ module DNS
11
+ class RR
12
+
13
+ #------------------------------------------------------------
14
+ # RR type PTR
15
+ #------------------------------------------------------------
16
+ class PTR < RR
17
+
18
+ # Getter for PTR resource
19
+ def ptr
20
+ @ptrdname.to_s
21
+ end
22
+ alias_method :ptrdname, :ptr
23
+
24
+ private
25
+
26
+ def check_ptr(str)
27
+ IPAddr.new str
28
+ rescue
29
+ raise RRArgumentError, "PTR section not valid"
30
+ end
31
+
32
+ def build_pack
33
+ @ptrdname_pack = pack_name(@ptrdname)
34
+ @rdlength = @ptrdname_pack.size
35
+ end
36
+
37
+ def set_type
38
+ @type = Net::DNS::RR::RRTypes.new("PTR")
39
+ end
40
+
41
+ def get_data
42
+ @ptrdname_pack
43
+ end
44
+
45
+ def get_inspect
46
+ "#@ptrdname"
47
+ end
48
+
49
+ def subclass_new_from_hash(args)
50
+ if args.has_key? :ptrdname or args.has_key? :ptr
51
+ @ptrdname = args[0][:ptrdname]
52
+ else
53
+ raise RRArgumentError, ":ptrdname or :ptr field is mandatory but missing"
54
+ end
55
+ end
56
+
57
+ def subclass_new_from_string(str)
58
+ @ptrdname = check_ptr(str)
59
+ end
60
+
61
+ def subclass_new_from_binary(data,offset)
62
+ @ptrdname,offset = dn_expand(data,offset)
63
+ return offset
64
+ end
65
+
66
+ end # class PTR
67
+
68
+ end # class RR
69
+ end # module DNS
70
+ end # module Net
71
+
@@ -0,0 +1,85 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::SOA
4
+ #
5
+ # $Id: SOA.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+ module Net
10
+ module DNS
11
+ class RR
12
+
13
+ #------------------------------------------------------------
14
+ # RR type SOA
15
+ #------------------------------------------------------------
16
+ class SOA < RR
17
+ attr_reader :mname, :rname, :serial, :refresh, :retry, :expire, :minimum
18
+
19
+ private
20
+
21
+ def build_pack
22
+ @soa_pack = pack_name(@mname)
23
+ @soa_pack += pack_name(@rname)
24
+ @soa_pack += [@serial,@refresh,@retry,@expire,@minimum].pack("N5")
25
+ end
26
+
27
+ def set_type
28
+ @type = Net::DNS::RR::Types.new("SOA")
29
+ end
30
+
31
+ def get_data
32
+ @soa_pack
33
+ end
34
+
35
+ def get_inspect
36
+ "#@mname #@rname #@serial #@refresh #@retry #@expire #@minimum"
37
+ end
38
+
39
+ def subclass_new_from_hash(args)
40
+ if args.has_key? :rdata
41
+ subclass_new_from_string(args[:rdata])
42
+ else
43
+ [:mname,:rname,:serial,:refresh,:retry,:expire,:minimum].each do |key|
44
+ raise RRArgumentError, "Missing field :#{key}" unless args.has_key? key
45
+ end
46
+ @mname = args[:mname] if valid? args[:mname]
47
+ @rname = args[:rname] if valid? args[:rname]
48
+ @serial = args[:serial] if number? args[:serial]
49
+ @refresh = args[:refresh] if number? args[:refresh]
50
+ @retry = args[:retry] if number? args[:retry]
51
+ @expire = args[:expire] if number? args[:expire]
52
+ @minimum = args[:minimum] if number? args[:minimum]
53
+ end
54
+ end
55
+
56
+ def number?(num)
57
+ if num.kind_of? Integer and num > 0
58
+ true
59
+ else
60
+ raise RRArgumentError, "Wrong format field: #{num} not a number or less than zero"
61
+ end
62
+ end
63
+
64
+ def subclass_new_from_string(str)
65
+ mname,rname,serial,refresh,ret,expire,minimum = str.strip.split(" ")
66
+ @mname = mname if valid? mname
67
+ @rname = rname if valid? rname
68
+ @serial,@refresh,@retry,@expire,@minimum = [serial,refresh,ret,expire,minimum].collect do |i|
69
+ i.to_i if valid? i.to_i
70
+ end
71
+ end
72
+
73
+ def subclass_new_from_binary(data,offset)
74
+ @mname,offset = dn_expand(data,offset)
75
+ @rname,offset = dn_expand(data,offset)
76
+ @serial,@refresh,@retry,@expire,@minimum = data.unpack("@#{offset} N5")
77
+ return offset + 5*Net::DNS::INT32SZ
78
+ end
79
+
80
+ end # class SOA
81
+
82
+ end # class RR
83
+ end # module DNS
84
+ end # module Net
85
+
@@ -0,0 +1,72 @@
1
+ ##
2
+ #
3
+ # Net::DNS::RR::TXT
4
+ #
5
+ # $Id: TXT.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
+ #
7
+ ##
8
+
9
+
10
+ module Net
11
+ module DNS
12
+ class RR
13
+
14
+ #------------------------------------------------------------
15
+ # RR type TXT
16
+ #------------------------------------------------------------
17
+ class TXT < RR
18
+ attr_reader :txt
19
+
20
+ private
21
+
22
+ def build_pack
23
+ str = ""
24
+ @txt.split(" ").each do |txt|
25
+ str += [txt.length,txt].pack("C a*")
26
+ end
27
+ @txt_pack = str
28
+ @rdlength = @txt_pack.size
29
+ end
30
+
31
+ def set_type
32
+ @type = Net::DNS::RR::Types.new("TXT")
33
+ end
34
+
35
+ def get_data
36
+ @txt_pack
37
+ end
38
+
39
+ def subclass_new_from_hash(args)
40
+ if args.has_key? :txt
41
+ @txt = args[:txt].strip
42
+ else
43
+ raise RRArgumentError, ":txt field is mandatory but missing"
44
+ end
45
+ end
46
+
47
+ def subclass_new_from_string(str)
48
+ @txt = str.strip
49
+ end
50
+
51
+ def subclass_new_from_binary(data,offset)
52
+ off_end = offset + @rdlength
53
+ @txt = ""
54
+ while offset < off_end
55
+ len = data.unpack("@#{offset} C")[0]
56
+ offset += 1
57
+ str = data[offset..offset+len-1]
58
+ offset += len
59
+ @txt << str << " "
60
+ end
61
+ return offset
62
+ end
63
+
64
+ end # class TXT
65
+
66
+ end # class RR
67
+ end # module DNS
68
+ end # module Net
69
+
70
+
71
+
72
+