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,251 @@
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::OPT - DNS OPT
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for EDNS pseudo resource record OPT.
26
+ #
27
+ #= Construction
28
+ #
29
+ #This object should only be used inside the Net::DNS classes itself.
30
+ #
31
+ #Since "OPT" is a pseudo record and should not be stored in
32
+ #masterfiles; Therefore we have not implemented a method to create this
33
+ #RR from string.
34
+ #
35
+ #One may create the object from a hash. See RFC 2671 for details for
36
+ #the meaning of the hash keys.
37
+ #
38
+ # rr= Net::DNS::RR.new_from_hash({
39
+ # 'name' => "", # Ignored and set to ""
40
+ # 'type' => "OPT",
41
+ # 'class' => 1024, # sets UDP payload size
42
+ # :extendedrcode => 0x00, # sets the extended RCODE 1 octets
43
+ # :ednsflags => 0x0000, # sets the ednsflags (2octets)
44
+ # :optioncode => 0x0 # 2 octets
45
+ # :optiondata => 0x0 # optionlength octets
46
+ # })
47
+ #
48
+ #The ednsversion is set to 0 for now. The ttl value is determined from
49
+ #the extendedrcode, the ednsversion and the ednsflag.
50
+ #The rdata is constructed from the optioncode and optiondata
51
+ #see section 4.4 of RFC 2671
52
+ #
53
+ #If optioncode is left undefined then we do not expect any RDATA.
54
+ #
55
+ #The defaults are no rdata.
56
+ #
57
+ #
58
+ #= TODO
59
+ #
60
+ #- This class is tailored to use with dnssec.
61
+ #
62
+ #- Do some range checking on the input.
63
+ #
64
+ #- This class probably needs subclasses once OPTION codes start to be defined.
65
+ #
66
+ #- look at use of extended labels
67
+ #
68
+ #= COPYRIGHT
69
+ #
70
+ #Copyright (c) 2001, 2002 RIPE NCC. Author Olaf M. Kolkman
71
+ #
72
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
73
+ #
74
+ #All Rights Reserved
75
+ #
76
+ #Permission to use, copy, modify, and distribute this software and its
77
+ #documentation for any purpose and without fee is hereby granted,
78
+ #provided that the above copyright notice appear in all copies and that
79
+ #both that copyright notice and this permission notice appear in
80
+ #supporting documentation, and that the name of the author not be
81
+ #used in advertising or publicity pertaining to distribution of the
82
+ #software without specific, written prior permission.
83
+ #
84
+ #
85
+ #THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
86
+ #ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
87
+ #AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
88
+ #DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
89
+ #AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
90
+ #OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
+ #
92
+ #Based on, and contains, code by Copyright (c) 1997-2002 Michael Fuhr.
93
+ #
94
+ #= SEE ALSO
95
+ #
96
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
97
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
98
+ #RFC 2435 Section 3
99
+ class OPT < RR
100
+ attr_accessor :optioncode, :optionlength, :optiondata, :extendedrcode, :ednsversion, :ednsflags
101
+ @@EDNSVERSION = 0;
102
+
103
+ @@extendedrcodesbyname = {
104
+ "ONLY_RDATA" => 0, # No name specified see 4.6 of 2671
105
+ "UNDEF1" => 1,
106
+ "UNDEF2" => 2,
107
+ "UNDEF3" => 3,
108
+ "UNDEF4" => 4,
109
+ "UNDEF5" => 5,
110
+ "UNDEF6" => 6,
111
+ "UNDEF7" => 7,
112
+ "UNDEF8" => 8,
113
+ "UNDEF9" => 9,
114
+ "UNDEF10" => 10,
115
+ "UNDEF11" => 11,
116
+ "UNDEF12" => 12,
117
+ "UNDEF13" => 13,
118
+ "UNDEF14" => 14,
119
+ "UNDEF15" => 15,
120
+ "BADVERS" => 16, # RFC 2671
121
+ }
122
+ @@extendedrcodesbyval = @@extendedrcodesbyname.invert
123
+
124
+
125
+
126
+ def new_from_data(data, offset)
127
+ @name = "" ; # should allway be "root"
128
+
129
+ if (@rdlength > 0)
130
+ @optioncode = data[offset, 2].unpack("n")[0];
131
+ @optionlength = data[offset+2, 2].unpack("n")[0];
132
+ @optiondata = data[offset+4, @optionlength].unpack("n");
133
+ end
134
+
135
+ @_rcode_flags = [ttl].pack("N");
136
+
137
+ @extendedrcode = @_rcode_flags[0, 1].unpack("C")[0];
138
+ @ednsversion = @_rcode_flags[1, 1].unpack("C")[0];
139
+ @ednsflags = @_rcode_flags[2, 2].unpack("n")[0];
140
+ end
141
+
142
+
143
+
144
+
145
+
146
+ def new_from_string(*args)
147
+ # There is no such thing as an OPT RR in a ZONE file.
148
+ # Not implemented!
149
+ raise RuntimeError, "You should not try to create a OPT RR from a string\nNot implemented";
150
+ end
151
+
152
+
153
+
154
+ def new_from_hash(values)
155
+ @name = "" ; # should allway be "root"
156
+
157
+
158
+ # Setting the MTU smaller then 512 does not make sense
159
+ # should we test for a maximum here?
160
+ if (@rrclass == "IN" || @rrclass.to_s.to_i < 512)
161
+ @rrclass = 512; # Default value...
162
+ end
163
+
164
+ @extendedrcode = 0
165
+ if values.has_key?:extendedrcode
166
+ @extendedrcode = values[:extendedrcode]
167
+ end
168
+
169
+ @ednsflags = 0;
170
+ if values.has_key?:ednsflags
171
+ @ednsflags = values[:ednsflags]
172
+ end
173
+
174
+ @ednsversion = @@EDNSVERSION;
175
+ if values.has_key?:ednsversion
176
+ @ednsversion = values[:ednsversion]
177
+ end
178
+
179
+ @ttl= ([@extendedrcode].pack("C") + [@ednsversion].pack("C") + [@ednsflags].pack("n")).unpack("N")[0]
180
+
181
+ if (values.has_key?:optioncode)
182
+ @optiondata = ""
183
+ if values.has_key(:optiondata)
184
+ @optiondata= values[:optiondata]
185
+ end
186
+ @optionlength = @optiondata.length
187
+ end
188
+ end
189
+
190
+
191
+
192
+
193
+ def inpsect
194
+ return "; EDNS Version " + @ednsversion + \
195
+ "\t UDP Packetsize: " + @class + "\n; EDNS-RCODE:\t" + @extendedrcode + \
196
+ " (" + @@extendedrcodesbyval[@extendedrcode] + ")" + \
197
+ "\n; EDNS-FLAGS:\t" + sprintf("0x%04x", @ednsflags) + "\n";
198
+ end
199
+
200
+
201
+ def rdatastr
202
+ return '; Parsing of OPT rdata is not yet implemented';
203
+ end
204
+
205
+ def rr_rdata(*args)
206
+ rdata="";
207
+
208
+ if (defined?@optioncode)
209
+ rdata = pack("n", @optioncode);
210
+ rdata += pack("n", @optionlength);
211
+ rdata += @optiondata
212
+ end
213
+ return rdata;
214
+ end
215
+
216
+ #Reads the do flag. (first bit in the ednssflags);
217
+ def do_flag
218
+ return ( 0x8000 & @ednsflags );
219
+ end
220
+
221
+ #Sets the do flag. (first bit in the ednssflags);
222
+ def set_do_flag
223
+ return @ednsflags = ( 0x8000 | @ednsflags );
224
+ end
225
+
226
+ #Clears the do flag. (first bit in the ednssflags);
227
+ def clear_do_flag
228
+ return @ednsflags = ( ~0x8000 & @ednsflags );
229
+ end
230
+
231
+ #Set the packet size.
232
+ #
233
+ # opt.size(1498)
234
+ def size=(s)
235
+ if (s != nil)
236
+ @rrclass=s;
237
+ end
238
+ return @rrclass;
239
+ end
240
+
241
+ #Get the packet size.
242
+ #
243
+ # print "Packet size:". opt.size
244
+ #
245
+ def size
246
+ return @rrclass
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,93 @@
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::PTR - DNS PTR resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Pointer (PTR) resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #
33
+ #All rights reserved. This program is free software; you may redistribute
34
+ #it and/or modify it under the same terms as Perl itself.
35
+ #
36
+ #= SEE ALSO
37
+ #
38
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
39
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
40
+ #RFC 1035 Section 3.3.12
41
+ class PTR < RR
42
+ #Returns the domain name associated with this record.
43
+ #
44
+ # print "ptrdname = ", rr.ptrdname, "\n"
45
+ #
46
+ attr_accessor :ptrdname
47
+ def new_from_data(data, offset)
48
+ if (@rdlength > 0)
49
+ @ptrdname = Net::DNS::Packet::dn_expand(data, offset)[0];
50
+ end
51
+ end
52
+
53
+ def new_from_string(s)
54
+ if (s != nil)
55
+ string = s.gsub(/\.+$/, "");
56
+ @ptrdname = string;
57
+ end
58
+ end
59
+
60
+ def new_from_hash(values)
61
+ if (values.has_key?:ptrdname)
62
+ @ptrdname = values[:ptrdname]
63
+ end
64
+ end
65
+
66
+ def rdatastr
67
+ return @ptrdname ? "#{@ptrdname}." : '';
68
+
69
+ end
70
+
71
+ def rr_rdata(packet, offset)
72
+ rdata = "";
73
+
74
+ if (defined?@ptrdname)
75
+ rdata += packet.dn_comp(@ptrdname, offset);
76
+ end
77
+
78
+ return rdata;
79
+ end
80
+
81
+ def _canonicalRdata(packet, offset)
82
+ rdata = "";
83
+
84
+ if (defined?@ptrdname)
85
+ rdata += _name2wire(@ptrdname);
86
+ end
87
+
88
+ return rdata;
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,131 @@
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::PX - DNS PX resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS X.400 Mail Mapping Information (PX) 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
+ #RFC822, RFC 1327, RFC 2163
43
+ class PX < RR
44
+ #Returns the preference given to this RR.
45
+ #
46
+ # print "preference = ", rr.preference, "\n"
47
+ #
48
+ attr_accessor :preference
49
+ #Returns the RFC822 part of the RFC1327 mapping information.
50
+ #
51
+ # print "map822 = ", rr.map822, "\n"
52
+ #
53
+ attr_accessor :map822
54
+ #Returns the X.400 part of the RFC1327 mapping information.
55
+ #
56
+ # print "mapx400 = ", rr.mapx400, "\n"
57
+ #
58
+ attr_accessor :mapx400
59
+ # Highest preference sorted first.
60
+
61
+ def init_rrsort_func
62
+ set_rrsort_func("preference", Proc.new { |a,b| a.preference <=> b.preference});
63
+ set_rrsort_func("default_sort", get_rrsort_func("preference"));
64
+ end
65
+
66
+ def new_from_data(data, offset)
67
+ if (@rdlength > 0)
68
+ @preference = data.unpack("\@#{offset} n")[0];
69
+ offset += Net::DNS::INT16SZ;
70
+
71
+ (@map822, offset) = Net::DNS::Packet::dn_expand(data, offset);
72
+ (@mapx400, offset) = Net::DNS::Packet::dn_expand(data, offset);
73
+ end
74
+ end
75
+
76
+ def new_from_string(string)
77
+ if (string && (string =~ /^(\d+)\s+(\S+)\s+(\S+)$/))
78
+ @preference = $1;
79
+ @map822 = $2;
80
+ @mapx400 = $3;
81
+ @map822.sub!(/\.+$/,"")
82
+ @mapx400.sub!(/\.+$/,"")
83
+ end
84
+ end
85
+
86
+ def new_from_hash(values)
87
+ if values.has_key?(:preference)
88
+ @preference = values[:preference]
89
+ end
90
+ if values.has_key?(:map822)
91
+ @map822 = values[:map822]
92
+ end
93
+ if values.has_key?(:mapx400)
94
+ @mapx400 = values[:mapx400]
95
+ end
96
+ end
97
+
98
+ def rdatastr
99
+ return @preference ? "#{@preference} #{@map822}. #{@mapx400}." : '';
100
+ end
101
+
102
+ def rr_rdata(packet, offset)
103
+ rdata = "";
104
+
105
+ if (defined?@preference)
106
+ rdata += [@preference].pack("n");
107
+
108
+ rdata += packet.dn_comp(@map822, offset + rdata.length);
109
+
110
+ rdata += packet.dn_comp(@mapx400, offset + rdata.length);
111
+ end
112
+
113
+ return rdata;
114
+ end
115
+
116
+
117
+ def _canonicalRdata
118
+ rdata = "";
119
+
120
+ if (defined?@preference)
121
+ rdata += [@preference].pack("n");
122
+ rdata += _name2wire(@map822);
123
+ rdata += _name2wire(@mapx400);
124
+ end
125
+
126
+ return rdata;
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end