pNet-DNS 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,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::RP - DNS RP resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Responsible Person (RP) 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 2.2
43
+ class RP < RR
44
+ #Returns a domain name that specifies the mailbox for the responsible person.
45
+ #
46
+ # print "mbox = ", rr.mbox, "\n"
47
+ #
48
+ attr_accessor :mbox
49
+ #Returns a domain name that specifies a TXT record containing further
50
+ #information about the responsible person.
51
+ #
52
+ # print "txtdname = ", rr.txtdname, "\n"
53
+ #
54
+ attr_accessor :txtdname
55
+ def new_from_data(data, offset)
56
+ if (@rdlength > 0)
57
+ (@mbox, offset) = Net::DNS::Packet::dn_expand(data, offset);
58
+ (@txtdname, offset) = Net::DNS::Packet::dn_expand(data, offset);
59
+ end
60
+ end
61
+
62
+ def new_from_string(string)
63
+ if (string && (string =~ /^(\S+)\s+(\S+)$/))
64
+ @mbox = $1;
65
+ @txtdname = $2;
66
+ @mbox.sub!(/\.+$/,"");
67
+ @txtdname.sub!(/\.+$/,"");
68
+ end
69
+ end
70
+
71
+ def new_from_hash(values)
72
+ if values.has_key?(:mbox)
73
+ @mbox = values[:mbox]
74
+ end
75
+ if values.has_key?(:txtdname)
76
+ @txtdname = values[:txtdname]
77
+ end
78
+ end
79
+
80
+ def rdatastr
81
+ return @mbox ? "#{@mbox}. #{@txtdname}." : '';
82
+ end
83
+
84
+ def rr_rdata(packet, offset)
85
+ rdata = "";
86
+
87
+ if (defined?@mbox)
88
+ rdata += packet.dn_comp(@mbox, offset);
89
+ rdata += packet.dn_comp(@txtdname, offset + rdata.length);
90
+ end
91
+
92
+ return rdata;
93
+ end
94
+
95
+
96
+ def _canonicalRdata
97
+ rdata = "";
98
+ if (defined?@mbox)
99
+ rdata += _name2wire(@mbox);
100
+ rdata += _name2wire(@txtdname);
101
+ end
102
+
103
+ return rdata;
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,115 @@
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::RT - DNS RT resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Route Through (RT) resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #Portions Copyright (c) 2005 Olaf Kolkman NLnet Labs.
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.3
43
+ class RT < RR
44
+ #Returns the preference for this route.
45
+ #
46
+ # print "preference = ", rr.preference, "\n"
47
+ #
48
+ attr_accessor :preference
49
+ #Returns the domain name of the intermediate host.
50
+ #
51
+ # print "intermediate = ", rr.intermediate, "\n"
52
+ #
53
+ attr_accessor :intermediate
54
+ def init_rrsort_func
55
+ # Highest preference sorted first.
56
+ set_rrsort_func("preference", Proc.new { |a,b| a.preference <=> b.preference } )
57
+
58
+ set_rrsort_func("default_sort", get_rrsort_func("preference") );
59
+ end
60
+
61
+ def new_from_data(data, offset)
62
+ if (@rdlength > 0)
63
+ @preference = data.unpack("\@#{offset} n")[0];
64
+ offset += Net::DNS::INT16SZ;
65
+
66
+ @intermediate = Net::DNS::Packet::dn_expand(data, offset)[0];
67
+ end
68
+ end
69
+
70
+ def new_from_hash(values)
71
+ if values.has_key?(:intermediate)
72
+ @intermediate = values[:intermediate]
73
+ end
74
+ if values.has_key?(:preference)
75
+ @preference = values[:preference]
76
+ end
77
+ end
78
+
79
+ def new_from_string(string)
80
+ if (string && (string =~ /^(\d+)\s+(\S+)$/))
81
+ @preference = $1;
82
+ @intermediate = $2;
83
+ @intermediate.sub!(/\.+$/, "");
84
+ end
85
+ end
86
+
87
+ def rdatastr
88
+ return @preference ? "#{@preference} #{@intermediate}." : '';
89
+ end
90
+
91
+ def rr_rdata(packet, offset)
92
+ rdata = "";
93
+
94
+ if (defined?@preference)
95
+ rdata += [@preference].pack("n");
96
+ rdata += packet.dn_comp(@intermediate, offset + rdata.length);
97
+ end
98
+
99
+ return rdata;
100
+ end
101
+
102
+ def _canonicalRdata(packet, offset)
103
+ rdata = "";
104
+
105
+ if (defined?@preference)
106
+ rdata += [@preference].pack("n");
107
+ rdata += _name2wire(@intermediate);
108
+ end
109
+
110
+ return rdata;
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,195 @@
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::SOA - DNS SOA resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Start of Authority (SOA) 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.13
43
+ class SOA < RR
44
+ #Returns the domain name of the original or primary nameserver for
45
+ #this zone.
46
+ #
47
+ # print "mname = ", rr.mname, "\n"
48
+ #
49
+ attr_accessor :mname
50
+ #Returns a domain name that specifies the mailbox for the person
51
+ #responsible for this zone.
52
+ #
53
+ # print "rname = ", rr.rname, "\n"
54
+ #
55
+ attr_accessor :rname
56
+ #Returns the zone's serial number.
57
+ #
58
+ # print "serial = ", rr.serial, "\n"
59
+ #
60
+ attr_accessor :serial
61
+ #Returns the zone's refresh interval.
62
+ #
63
+ # print "refresh = ", rr.refresh, "\n"
64
+ #
65
+ attr_accessor :refresh
66
+ #Returns the zone's retry interval.
67
+ #
68
+ # print "retry = ", rr.retry, "\n"
69
+ #
70
+ attr_accessor :retry
71
+ #Returns the zone's expire interval.
72
+ #
73
+ # print "expire = ", rr.expire, "\n"
74
+ #
75
+ attr_accessor :expire
76
+ #Returns the minimum (default) TTL for records in this zone.
77
+ #
78
+ # print "minimum = ", rr.minimum, "\n"
79
+ #
80
+ attr_accessor :minimum
81
+ def new_from_data(data, offset)
82
+ if (@rdlength > 0)
83
+ (@mname, offset) = Net::DNS::Packet::dn_expand(data, offset);
84
+ (@rname, offset) = Net::DNS::Packet::dn_expand(data, offset);
85
+
86
+ (@serial, @refresh, @retry, @expire, @minimum) = data.unpack("\@#{offset} N5");
87
+ end
88
+ end
89
+
90
+ def new_from_hash(values)
91
+ if values.has_key?(:mname)
92
+ @mname = values[:mname]
93
+ end
94
+ if values.has_key?(:rname)
95
+ @rname = values[:rname]
96
+ end
97
+ if values.has_key?(:serial)
98
+ @serial = values[:serial]
99
+ end
100
+ if values.has_key?(:refresh)
101
+ @refresh = values[:refresh]
102
+ end
103
+ if values.has_key?(:retry)
104
+ @retry = values[:retry]
105
+ end
106
+ if values.has_key?(:expire)
107
+ @expire = values[:expire]
108
+ end
109
+ if values.has_key?(:minimum)
110
+ @minimum = values[:minimum]
111
+ end
112
+ end
113
+
114
+ def new_from_string(s)
115
+ if (s!= nil)
116
+ # string =~ tr/()//d;
117
+ string = s.tr("()", "")
118
+
119
+ # XXX do we need to strip out comments here now that RR.pm does it?
120
+ string.gsub!(/;.*$/, "");
121
+
122
+ @mname, string = get_next_param(string)
123
+ @rname, string = get_next_param(string)
124
+ @serial, string = get_next_param(string)
125
+ @refresh, string = get_next_param(string)
126
+ @retry, string = get_next_param(string)
127
+ @expire, string = get_next_param(string)
128
+ @minimum, string = get_next_param(string)
129
+
130
+ @mname.sub!(/\.+$/, "");
131
+ @rname.sub!(/\.+$/, "");
132
+ end
133
+ end
134
+
135
+ def get_next_param(s)
136
+ s =~ /(\S+)/
137
+ param = $1
138
+ string = s[param.length, s.length-param.length]
139
+ string.sub!(/\s*/, "")
140
+ return param, string
141
+ end
142
+
143
+ def rdatastr
144
+ rdatastr="";
145
+
146
+ if (defined?@mname)
147
+ rdatastr = "#{@mname}. #{@rname}. (\n";
148
+ rdatastr += "\t\t\t\t\t" + "#{@serial}\t; Serial\n";
149
+ rdatastr += "\t\t\t\t\t" + "#{@refresh}\t; Refresh\n";
150
+ rdatastr += "\t\t\t\t\t" + "#{@retry}\t; Retry\n";
151
+ rdatastr += "\t\t\t\t\t" + "#{@expire}\t; Expire\n";
152
+ rdatastr += "\t\t\t\t\t" + "#{@minimum} )\t; Minimum TTL";
153
+ else
154
+ rdatastr = '';
155
+ end
156
+
157
+ return rdatastr;
158
+ end
159
+
160
+ def rr_rdata(packet, offset)
161
+ rdata = "";
162
+
163
+ # Assume that if one field exists, they all exist. Script will
164
+ # print a warning otherwise.
165
+
166
+ if (defined?@mname)
167
+ rdata += packet.dn_comp(@mname, offset);
168
+ rdata += packet.dn_comp(@rname, offset + rdata.length);
169
+
170
+ rdata += [@serial, @refresh, @retry, @expire, @minimum].pack("N5");
171
+ end
172
+
173
+ return rdata;
174
+ end
175
+
176
+
177
+
178
+ def _canonicalRdata
179
+ rdata = "";
180
+
181
+ # Assume that if one field exists, they all exist. Script will
182
+ # print a warning otherwise.
183
+
184
+ if (defined?@mname)
185
+ rdata += _name2wire(@mname);
186
+ rdata += _name2wire(@rname);
187
+ rdata += [@serial, @refresh, @retry, @expire, @minimum].pack("N5");
188
+ end
189
+
190
+ return rdata;
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,46 @@
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::SPF - DNS SPF resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #This is a clone of the TXT record. This class therfore completely inherits
26
+ #all properties of the Net::DNS::RR::TXT class.
27
+ #
28
+ #Please see the Net::DNS::RR::TXT documentation for details
29
+ #
30
+ #= COPYRIGHT
31
+ #
32
+ #Copyright (c) 2005 Olaf Kolkman (NLnet Labs)
33
+ #
34
+ #All rights reserved. This program is free software; you may redistribute
35
+ #it and/or modify it under the same terms as Perl itself.
36
+ #
37
+ #= SEE ALSO
38
+ #
39
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
40
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
41
+ #RFC 1035 Section 3.3.14, draft-schlitt-ospf-classic-02.txt
42
+ class SPF < TXT
43
+ end
44
+ end
45
+ end
46
+ end