pNet-DNS 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README +68 -0
  2. data/lib/Net/DNS.rb +879 -0
  3. data/lib/Net/DNS/Header.rb +303 -0
  4. data/lib/Net/DNS/Nameserver.rb +601 -0
  5. data/lib/Net/DNS/Packet.rb +851 -0
  6. data/lib/Net/DNS/Question.rb +117 -0
  7. data/lib/Net/DNS/RR.rb +630 -0
  8. data/lib/Net/DNS/RR/A.rb +103 -0
  9. data/lib/Net/DNS/RR/AAAA.rb +147 -0
  10. data/lib/Net/DNS/RR/AFSDB.rb +114 -0
  11. data/lib/Net/DNS/RR/CERT.rb +191 -0
  12. data/lib/Net/DNS/RR/CNAME.rb +89 -0
  13. data/lib/Net/DNS/RR/DNAME.rb +84 -0
  14. data/lib/Net/DNS/RR/EID.rb +70 -0
  15. data/lib/Net/DNS/RR/HINFO.rb +108 -0
  16. data/lib/Net/DNS/RR/ISDN.rb +118 -0
  17. data/lib/Net/DNS/RR/LOC.rb +341 -0
  18. data/lib/Net/DNS/RR/MB.rb +92 -0
  19. data/lib/Net/DNS/RR/MG.rb +96 -0
  20. data/lib/Net/DNS/RR/MINFO.rb +109 -0
  21. data/lib/Net/DNS/RR/MR.rb +92 -0
  22. data/lib/Net/DNS/RR/MX.rb +124 -0
  23. data/lib/Net/DNS/RR/NAPTR.rb +182 -0
  24. data/lib/Net/DNS/RR/NIMLOC.rb +70 -0
  25. data/lib/Net/DNS/RR/NS.rb +100 -0
  26. data/lib/Net/DNS/RR/NSAP.rb +273 -0
  27. data/lib/Net/DNS/RR/NULL.rb +68 -0
  28. data/lib/Net/DNS/RR/OPT.rb +251 -0
  29. data/lib/Net/DNS/RR/PTR.rb +93 -0
  30. data/lib/Net/DNS/RR/PX.rb +131 -0
  31. data/lib/Net/DNS/RR/RP.rb +108 -0
  32. data/lib/Net/DNS/RR/RT.rb +115 -0
  33. data/lib/Net/DNS/RR/SOA.rb +195 -0
  34. data/lib/Net/DNS/RR/SPF.rb +46 -0
  35. data/lib/Net/DNS/RR/SRV.rb +153 -0
  36. data/lib/Net/DNS/RR/SSHFP.rb +190 -0
  37. data/lib/Net/DNS/RR/TKEY.rb +219 -0
  38. data/lib/Net/DNS/RR/TSIG.rb +358 -0
  39. data/lib/Net/DNS/RR/TXT.rb +162 -0
  40. data/lib/Net/DNS/RR/UNKNOWN.rb +76 -0
  41. data/lib/Net/DNS/RR/X25.rb +90 -0
  42. data/lib/Net/DNS/Resolver.rb +2090 -0
  43. data/lib/Net/DNS/Resolver/Recurse.rb +478 -0
  44. data/lib/Net/DNS/Update.rb +189 -0
  45. data/test/custom.txt +4 -0
  46. data/test/resolv.conf +4 -0
  47. data/test/tc_escapedchars.rb +498 -0
  48. data/test/tc_header.rb +91 -0
  49. data/test/tc_inet6.rb +169 -0
  50. data/test/tc_misc.rb +137 -0
  51. data/test/tc_online.rb +236 -0
  52. data/test/tc_packet.rb +174 -0
  53. data/test/tc_packet_unique_push.rb +126 -0
  54. data/test/tc_question.rb +49 -0
  55. data/test/tc_recurse.rb +69 -0
  56. data/test/tc_res_env.rb +59 -0
  57. data/test/tc_res_file.rb +55 -0
  58. data/test/tc_res_opt.rb +135 -0
  59. data/test/tc_resolver.rb +102 -0
  60. data/test/tc_rr-opt.rb +40 -0
  61. data/test/tc_rr-rrsort.rb +116 -0
  62. data/test/tc_rr-txt.rb +138 -0
  63. data/test/tc_rr-unknown.rb +95 -0
  64. data/test/tc_rr.rb +246 -0
  65. data/test/tc_tcp.rb +34 -0
  66. data/test/tc_tkey.rb +115 -0
  67. data/test/tc_update.rb +226 -0
  68. data/test/ts_netdns.rb +17 -0
  69. data/test/ts_offline.rb +32 -0
  70. data/test/ts_online.rb +33 -0
  71. metadata +119 -0
@@ -0,0 +1,89 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ module Net
17
+ module DNS
18
+ class RR
19
+ #= NAME
20
+ #
21
+ #Net::DNS::RR::CNAME - DNS CNAME resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Canonical Name (CNAME) resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #
33
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
34
+ #
35
+ #All rights reserved. This program is free software; you may redistribute
36
+ #it and/or modify it under the same terms as Perl itself.
37
+ #
38
+ #= SEE ALSO
39
+ #
40
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
41
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
42
+ #RFC 1035 Section 3.3.1
43
+ class CNAME < RR
44
+ #Returns the RR's canonical name.
45
+ #
46
+ # print "cname = ", rr.cname, "\n"
47
+ #
48
+ attr_accessor :cname
49
+ def new_from_data(data, offset)
50
+ if (@rdlength > 0)
51
+ @cname = Net::DNS::Packet::dn_expand(data, offset)[0];
52
+ end
53
+ end
54
+
55
+ def new_from_string(s)
56
+ if (s!=nil)
57
+ string = s.sub(/\.+$/o, "");
58
+ @cname = string;
59
+ end
60
+ end
61
+
62
+ def new_from_hash(values)
63
+ if values.has_key?(:cname)
64
+ @cname = values[:cname]
65
+ end
66
+ end
67
+
68
+ def rdatastr
69
+ return @cname ? "#{@cname}." : '';
70
+ end
71
+
72
+ def rr_rdata(packet, offset)
73
+ rdata = "";
74
+
75
+ if (defined?@cname)
76
+ rdata = packet.dn_comp(@cname, offset);
77
+ end
78
+
79
+ return rdata;
80
+ end
81
+
82
+ # rdata contains a compressed domainname... we should not have that.
83
+ def _canonicalRdata
84
+ return _name2wire(@cname);
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,84 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ module Net
17
+ module DNS
18
+ class RR
19
+ #= NAME
20
+ #
21
+ #Net::DNS::RR::DNAME - DNS DNAME resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Non-Terminal Name Redirection (DNAME) resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #
33
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
34
+ #
35
+ #All rights reserved. This program is free software; you may redistribute
36
+ #it and/or modify it under the same terms as Perl itself.
37
+ #
38
+ #= SEE ALSO
39
+ #
40
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
41
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
42
+ #RFC 2672
43
+ class DNAME < RR
44
+ #Returns the DNAME target.
45
+ #
46
+ # print "dname = ", rr.dname, "\n"
47
+ #
48
+ attr_accessor :dname
49
+ def new_from_data(packet, offset)
50
+ if (@rdlength > 0)
51
+ @dname = Net::DNS::Packet.dn_expand(packet, offset)[0];
52
+ end
53
+ end
54
+
55
+ def new_from_hash(values)
56
+ if values.has_key?(:dname)
57
+ @dname = values[:dname]
58
+ end
59
+ end
60
+
61
+ def new_from_string(s)
62
+ if (s != nil)
63
+ string = s.sub(/\.+$/o, "");
64
+ @dname = string;
65
+ end
66
+ end
67
+
68
+ def rdatastr
69
+ return @dname ? "#{@dname}." : '';
70
+ end
71
+
72
+ def rr_rdata(packet, offset)
73
+ rdata = "";
74
+
75
+ if (defined?@dname)
76
+ rdata = packet.dn_comp(@dname, offset);
77
+ end
78
+
79
+ return rdata;
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,70 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ module Net
17
+ module DNS
18
+ class RR
19
+ #= NAME
20
+ #
21
+ #Net::DNS::RR::EID - DNS EID resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Endpoint Identifier (EID) resource records.
26
+ #
27
+ #= METHODS
28
+ #
29
+ #== rdlength
30
+ #
31
+ # print "rdlength = ", rr.rdlength, "\n"
32
+ #
33
+ #Returns the length of the record's data section.
34
+ #
35
+ #== rdata
36
+ #
37
+ # rdata = rr.rdata
38
+ #
39
+ #Returns the record's data section as binary data.
40
+ #
41
+ #= COPYRIGHT
42
+ #
43
+ #Copyright (c) 1997-2002 Michael Fuhr.
44
+ #
45
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
46
+ #
47
+ ##Ruby version Copyright (c) 2006 AlexD (Nominet UK)
48
+ #
49
+ #All rights reserved. This program is free software; you may redistribute
50
+ #it and/or modify it under the same terms as Perl itself.
51
+ #
52
+ #= SEE ALSO
53
+ #
54
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
55
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
56
+ #draft-ietf-nimrod-dns-I<xx>.txt
57
+ class EID < RR
58
+
59
+ def new_from_data(data, offset)
60
+ end
61
+
62
+ def new_from_hash(values)
63
+ end
64
+
65
+ def new_from_string(string)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,108 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ module Net
17
+ module DNS
18
+ class RR
19
+ #= NAME
20
+ #
21
+ #Net::DNS::RR::HINFO - DNS HINFO resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Host Information (HINFO) resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #
33
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
34
+ #
35
+ #All rights reserved. This program is free software; you may redistribute
36
+ #it and/or modify it under the same terms as Perl itself.
37
+ #
38
+ #= SEE ALSO
39
+ #
40
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
41
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
42
+ #RFC 1035 Section 3.3.2
43
+ class HINFO < RR
44
+ #Returns the CPU type for this RR.
45
+ #
46
+ # print "cpu = ", rr.cpu, "\n"
47
+ #
48
+ attr_accessor :cpu
49
+
50
+ #Returns the operating system type for this RR.
51
+ #
52
+ # print "os = ", rr.os, "\n"
53
+ #
54
+ attr_accessor :os
55
+ def new_from_data(data, offset)
56
+ if (@rdlength > 0)
57
+ len = data.unpack("\@#{offset} C")[0];
58
+ offset+=1;
59
+ cpu = data[offset, len];
60
+ offset += len;
61
+
62
+ len = data.unpack("\@#{offset} C")[0];
63
+ offset+=1;
64
+ os = data[offset, len];
65
+ offset += len;
66
+
67
+ @cpu = cpu;
68
+ @os = os;
69
+ end
70
+ end
71
+
72
+ def new_from_string(string)
73
+ if (string && string =~ /^["'](.*?)["']\s+["'](.*?)["']$/)
74
+ @cpu = $1;
75
+ @os = $2;
76
+ end
77
+ end
78
+
79
+ def new_from_hash(values)
80
+ if values.has_key?(:cpu)
81
+ @cpu = values[:cpu]
82
+ end
83
+ if values.has_key?(:os)
84
+ @os = values[:os]
85
+ end
86
+ end
87
+
88
+ def rdatastr
89
+ return @cpu ? "'#{@cpu}' '#{@os}'" : '';
90
+ end
91
+
92
+ def rr_rdata(*args)
93
+ rdata = "";
94
+
95
+ if (defined?@cpu)
96
+ rdata += [@cpu.length].pack("C");
97
+ rdata += @cpu;
98
+
99
+ rdata += [@os.length].pack("C");
100
+ rdata += @os;
101
+ end
102
+
103
+ return rdata;
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,118 @@
1
+ # The contents of this file are subject to the Mozilla
2
+ # Public Licence Version 1.1 (the "Licence"); you may
3
+ # not use this file except in compliance with the
4
+ # Licence. You may obtain a copy of the Licence at
5
+ # http://www.mozilla.org/MPL
6
+ # Software distributed under the Licence is distributed
7
+ # on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
8
+ # either express or implied. See the Licence of the
9
+ # specific language governing rights and limitations
10
+ # under the Licence.
11
+ # The Original Code is pNet::DNS.
12
+ # The Initial Developer of the Original Code is
13
+ # Nominet UK (www.nominet.org.uk). Portions created by
14
+ # Nominet UK are Copyright (c) Nominet UK 2006.
15
+ # All rights reserved.
16
+ module Net
17
+ module DNS
18
+ class RR
19
+ #= NAME
20
+ #
21
+ #Net::DNS::RR::ISDN - DNS ISDN resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS ISDN resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #
33
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
34
+ #
35
+ #All rights reserved. This program is free software; you may redistribute
36
+ #it and/or modify it under the same terms as Perl itself.
37
+ #
38
+ #= SEE ALSO
39
+ #
40
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
41
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
42
+ #RFC 1183 Section 3.2
43
+ class ISDN < RR
44
+ #Returns the RR's address field.
45
+ #
46
+ # print "address = ", rr.address, "\n"
47
+ #
48
+ attr_accessor :address
49
+ #Returns the RR's subaddress field.
50
+ #
51
+ # print "subaddress = ", rr.sa, "\n"
52
+ #
53
+ attr_accessor :sa
54
+ def new_from_data(data, offset)
55
+ if (@rdlength > 0)
56
+ len = data.unpack("\@#{offset} C")[0];
57
+ offset+=1;
58
+ address = data[offset, len];
59
+ offset += len;
60
+
61
+ if (len + 1 < @rdlength)
62
+ len = data.unpack("\@#{offset} C")[0];
63
+ offset+=1;
64
+ sa = data[offset, len];
65
+ offset += len;
66
+ else
67
+ sa = "";
68
+ end
69
+ @address = address;
70
+ @sa = sa;
71
+ end
72
+ end
73
+
74
+ def new_from_string(string)
75
+ if (string && string =~ /^['"](.*?)['"](.*)/s)
76
+ @address = $1;
77
+ rest = $2;
78
+
79
+ if (rest =~ /^\s+['"](.*?)['"]$/)
80
+ @sa = $1;
81
+ else
82
+ @sa = "";
83
+ end
84
+ end
85
+ end
86
+
87
+ def new_from_hash(values)
88
+ if values.has_key?(:address)
89
+ @address = values[:address]
90
+ end
91
+ if values.has_key?(:sa)
92
+ @sa = values[:sa]
93
+ end
94
+ end
95
+
96
+ def rdatastr
97
+ return @address ? "'#{@address}' '#{@sa}'" : '';
98
+ end
99
+
100
+ def rr_rdata(*args)
101
+ rdata = "";
102
+
103
+ if (defined?@address)
104
+ rdata += [@address.length].pack("C");
105
+ rdata += @address;
106
+
107
+ if (@sa)
108
+ rdata += [@sa.length].pack("C");
109
+ rdata += @sa;
110
+ end
111
+ end
112
+
113
+ return rdata;
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end