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,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::NIMLOC - DNS NIMLOC resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Nimrod Locator (NIMLOC) 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 NIMLOC < RR
58
+ def new_from_data(data, offset)
59
+ end
60
+
61
+ def new_from_string(string)
62
+ end
63
+
64
+ def new_from_hash(values)
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,100 @@
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::NS - DNS NS resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Name Server (NS) resource records.
26
+ #
27
+ #= COPYRIGHT
28
+ #
29
+ #Copyright (c) 1997-2002 Michael Fuhr.
30
+ #
31
+ #Portions Copyright (c) 2002-2004 Chris Reinhardt.
32
+ #
33
+ #Portions Copyright (c) 2005 O.M, Kolkman, RIPE NCC.
34
+ #
35
+ #Portions Copyright (c) 2005-2006 O.M, Kolkman, NLnet Labs.
36
+ #
37
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
38
+ #
39
+ #All rights reserved. This program is free software; you may redistribute
40
+ #it and/or modify it under the same terms as Perl itself.
41
+ #
42
+ #= SEE ALSO
43
+ #
44
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
45
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
46
+ #RFC 1035 Section 3.3.11
47
+ class NS < RR
48
+ #Returns the name of the nameserver.
49
+ #
50
+ # print "nsdname = ", rr.nsdname, "\n"
51
+ #
52
+ attr_accessor :nsdname
53
+ def new_from_data(data, offset)
54
+ if (@rdlength > 0)
55
+ @nsdname = Net::DNS::Packet.dn_expand(data, offset)[0];
56
+ end
57
+ end
58
+
59
+ def new_from_string(string)
60
+ if (string)
61
+ string.gsub!(/\.+$/, "");
62
+ @nsdname = string;
63
+ end
64
+ end
65
+
66
+ def new_from_hash(values)
67
+ if values.has_key?(:nsdname)
68
+ @nsdname = values[:nsdname]
69
+ end
70
+ end
71
+
72
+ def rdatastr
73
+ if @nsdname
74
+ return "#{@nsdname}."
75
+ else
76
+ return '';
77
+ end
78
+ end
79
+
80
+ def rr_rdata(packet, offset)
81
+ rdata = "";
82
+
83
+ if (defined?@nsdname)
84
+ rdata += packet.dn_comp(@nsdname, offset);
85
+ end
86
+
87
+ return rdata;
88
+ end
89
+
90
+
91
+
92
+ def _canonicalRdata
93
+ # rdata contains a compressed domainname... we should not have that.
94
+ rdata=_name2wire(@nsdname);
95
+ return rdata;
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,273 @@
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::NSAP - DNS NSAP resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Network Service Access Point (NSAP) 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 1706.
43
+ class NSAP < RR
44
+ #Returns the RR's authority and format identifier. Net::DNS
45
+ #currently supports only AFI 47 (GOSIP Version 2).
46
+ #
47
+ # print "afi = ", rr.afi, "\n"
48
+ #
49
+ attr_accessor :afi
50
+ #Returns the RR's initial domain identifier.
51
+ #
52
+ # print "idi = ", rr.idi, "\n"
53
+ #
54
+ attr_accessor :idi
55
+ #Returns the RR's DSP format identifier.
56
+ #
57
+ # print "dfi = ", rr.dfi, "\n"
58
+ #
59
+ attr_accessor :dfi
60
+ #Returns the RR's administrative authority.
61
+ #
62
+ # print "aa = ", rr.aa, "\n"
63
+ #
64
+ attr_accessor :aa
65
+ #Returns the RR's routing domain identifier.
66
+ #
67
+ # print "rd = ", rr.rd, "\n"
68
+ #
69
+ attr_accessor :rd
70
+ #Returns the RR's area identifier.
71
+ #
72
+ # print "area = ", rr.area, "\n"
73
+ #
74
+ attr_accessor :area
75
+ #Returns the RR's system identifier.
76
+ #
77
+ # print "id = ", rr.id, "\n"
78
+ #
79
+ attr_accessor :id
80
+ #Returns the RR's NSAP selector.
81
+ #
82
+ # print "sel = ", rr.sel, "\n"
83
+ #
84
+ attr_accessor :sel
85
+
86
+ #Returns the RR's reserved field.
87
+ # print "rsvd = ", rr.rsvd, "\n"
88
+ #
89
+ attr_writer :rsvd
90
+ def new_from_data(data, offset)
91
+ if (@rdlength > 0)
92
+ afi = data.unpack("\@#{offset} C")[0];
93
+ @afi = sprintf("%02x", afi);
94
+ offset+=1;
95
+
96
+ if (@afi == "47")
97
+ idi = data.unpack("\@#{offset} C2");
98
+ offset += 2;
99
+
100
+ dfi = data.unpack("\@#{offset} C")[0];
101
+ offset += 1;
102
+
103
+ aa = data.unpack("\@#{offset} C3");
104
+ offset += 3;
105
+
106
+ rsvd = data.unpack("\@#{offset} C2");
107
+ offset += 2;
108
+
109
+ rd = data.unpack("\@#{offset} C2");
110
+ offset += 2;
111
+
112
+ area = data.unpack("\@#{offset} C2");
113
+ offset += 2;
114
+
115
+ id = data.unpack("\@#{offset} C6");
116
+ offset += 6;
117
+
118
+ sel = data.unpack("\@#{offset} C")[0];
119
+ offset += 1;
120
+
121
+ @idi = sprintf("%02x%02x", idi[0], idi[1]);
122
+ @dfi = sprintf("%02x", dfi);
123
+ @aa = sprintf("%02x%02x%02x", aa[0], aa[1], aa[2]);
124
+ @rsvd = sprintf("%02x%02x", rsvd[0],rsvd[1]);
125
+ @rd = sprintf("%02x%02x", rd[0],rd[1]);
126
+ @area = sprintf("%02x%02x", area[0],area[1]);
127
+ @id = sprintf("%02x%02x%02x%02x%02x%02x", id[0],id[1],id[2],id[3],id[4],id[5]);
128
+ @sel = sprintf("%02x", sel);
129
+
130
+ else
131
+ # What to do for unsupported versions?
132
+ end
133
+ end
134
+ end
135
+
136
+ def new_from_hash(values)
137
+ if values.has_key?(:idi)
138
+ @idi = values[:idi]
139
+ end
140
+ if values.has_key?(:dfi)
141
+ @dfi = values[:dfi]
142
+ end
143
+ if values.has_key?(:afi)
144
+ @afi = values[:afi]
145
+ end
146
+ if values.has_key?(:aa)
147
+ @aa = values[:aa]
148
+ end
149
+ if values.has_key?(:sel)
150
+ @sel = values[:sel]
151
+ end
152
+ if values.has_key?(:id)
153
+ @id = values[:id]
154
+ end
155
+ if values.has_key?(:rsvd)
156
+ @rsvd = values[:rsvd]
157
+ end
158
+ if values.has_key?(:rd)
159
+ @rd = values[:rd]
160
+ end
161
+ if values.has_key?(:area)
162
+ @area = values[:area]
163
+ end
164
+ end
165
+
166
+ def new_from_string(s)
167
+ if (s)
168
+ string = s.gsub(/\./, ""); # remove all dots.
169
+ string.gsub!(/^0x/,""); # remove leading 0x
170
+
171
+ if (string =~ /^[a-zA-Z0-9]{40}$/)
172
+ (@afi, @idi, @dfi, @aa, @rsvd, @rd, @area, @id, @sel) = string.unpack("A2A4A2A6A4A4A4A12A2")
173
+ end
174
+ end
175
+ end
176
+
177
+
178
+ #Returns the RR's initial domain part (the AFI and IDI fields).
179
+ #
180
+ # print "idp = ", rr.idp, "\n"
181
+ #
182
+ def idp
183
+ ret = [@afi, @idi].join('')
184
+ return ret
185
+ end
186
+
187
+ #Returns the RR's domain specific part (the DFI, AA, Rsvd, RD, Area,
188
+ #ID, and SEL fields).
189
+ #
190
+ # print "dsp = ", rr.dsp, "\n"
191
+ #
192
+ def dsp
193
+ ret = [@dfi,@aa,rsvd,@rd,@area,@id,@sel].join('')
194
+ return ret
195
+ end
196
+
197
+ def rsvd
198
+ if (@rsvd==nil)
199
+ return "0000"
200
+ else
201
+ return @rsvd
202
+ end
203
+ end
204
+
205
+ def rdatastr
206
+ rdatastr=""
207
+
208
+ if (defined?@afi)
209
+ if (@afi == "47")
210
+ rdatastr = [idp, dsp].join('')
211
+ else
212
+ rdatastr = "; AFI #{@afi} not supported"
213
+ end
214
+ else
215
+ rdatastr = ''
216
+ end
217
+
218
+ return rdatastr
219
+ end
220
+
221
+ def rr_rdata(*args)
222
+ rdata = ""
223
+
224
+ if (defined?@afi)
225
+ # rdata += [@afi.to_i().to_s(16).to_i()].pack("C");
226
+ rdata += [@afi.to_i(16)].pack("C")
227
+
228
+ if (@afi == "47")
229
+ rdata += str2bcd(@idi, 2)
230
+ rdata += str2bcd(@dfi, 1)
231
+ rdata += str2bcd(@aa, 3)
232
+ rdata += str2bcd(0, 2) # rsvd
233
+ rdata += str2bcd(@rd, 2)
234
+ rdata += str2bcd(@area, 2)
235
+ rdata += str2bcd(@id, 6)
236
+ rdata += str2bcd(@sel, 1)
237
+ end
238
+ # Checks for other versions would go here.
239
+ end
240
+
241
+ return rdata
242
+ end
243
+
244
+ #------------------------------------------------------------------------------
245
+ # Usage: str2bcd(STRING, NUM_BYTES)
246
+ #
247
+ # Takes a string representing a hex number of arbitrary length and
248
+ # returns an equivalent BCD string of NUM_BYTES length (with
249
+ # NUM_BYTES * 2 digits), adding leading zeros if necessary.
250
+ #------------------------------------------------------------------------------
251
+
252
+ # This can't be the best way....
253
+ def str2bcd(s, bytes)
254
+ retval = "";
255
+
256
+ digits = bytes * 2;
257
+ string = sprintf("%#{digits}s", s);
258
+ string.tr!(" ","0");
259
+
260
+ i=0;
261
+ bytes.times do
262
+ bcd = string[i*2, 2];
263
+ retval += [bcd.to_i(16)].pack("C");
264
+ i+=1
265
+ end
266
+
267
+ return retval;
268
+ end
269
+
270
+ end
271
+ end
272
+ end
273
+ end
@@ -0,0 +1,68 @@
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::NULL - DNS NULL resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Null (NULL) 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
+ #All rights reserved. This program is free software; you may redistribute
48
+ #it and/or modify it under the same terms as Perl itself.
49
+ #
50
+ #= SEE ALSO
51
+ #
52
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
53
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
54
+ #RFC 1035 Section 3.3.10
55
+
56
+ class NULL < RR
57
+ def new_from_data(data, offset)
58
+ end
59
+
60
+ def new_from_hash(values)
61
+ end
62
+
63
+ def new_from_string(string)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end