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,109 @@
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::MINFO - DNS MINFO resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Mailbox Information (MINFO) 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.7
43
+ class MINFO < RR
44
+ #Returns the RR's responsible mailbox field. See RFC 1035.
45
+ #
46
+ # print "rmailbx = ", rr.rmailbx, "\n"
47
+ #
48
+ attr_accessor :rmailbx
49
+ #Returns the RR's error mailbox field.
50
+ #
51
+ # print "emailbx = ", rr.emailbx, "\n"
52
+ #
53
+ attr_accessor :emailbx
54
+ def new_from_data(data, offset)
55
+ if (@rdlength > 0)
56
+ (@rmailbx, offset) = Net::DNS::Packet::dn_expand(data, offset);
57
+ (@emailbx, offset) = Net::DNS::Packet::dn_expand(data, offset);
58
+ end
59
+ end
60
+
61
+ def new_from_string(string)
62
+ if (string && (string =~ /^(\S+)\s+(\S+)$/))
63
+ @rmailbx = $1;
64
+ @emailbx = $2;
65
+ @rmailbx.sub!(/\.+$/, "");
66
+ @emailbx.sub!(/\.+$/,"");
67
+ end
68
+ end
69
+
70
+ def new_from_hash(values)
71
+ if values.has_key?(:rmailbx)
72
+ @rmailbx = values[:rmailbx]
73
+ end
74
+ if values.has_key?(:emailbx)
75
+ @emailbx = values[:emailbx]
76
+ end
77
+ end
78
+
79
+ def rdatastr
80
+ return @rmailbx ? "#{@rmailbx}. #{@emailbx}." : '';
81
+ end
82
+
83
+ def rr_rdata(packet, offset)
84
+ rdata = "";
85
+
86
+ if (defined?@rmailbx)
87
+ rdata += packet.dn_comp(@rmailbx, offset);
88
+
89
+ rdata += packet.dn_comp(@emailbx, offset + rdata.length);
90
+ end
91
+
92
+ return rdata;
93
+ end
94
+
95
+
96
+ def _canonicalRdata(data, offset)
97
+ rdata = "";
98
+
99
+ if (defined?@rmailbx)
100
+ rdata += _name2wire(@rmailbx);
101
+ rdata += _name2wire(@emailbx);
102
+ end
103
+
104
+ return rdata;
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,92 @@
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::MR - DNS MR resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Mail Rename (MR) 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.8
43
+ class MR < RR
44
+ #Returns the RR's new name field.
45
+ #
46
+ # print "newname = ", rr.newname, "\n"
47
+ #
48
+ attr_accessor :newname
49
+ def new_from_data(data, offset)
50
+ if (@rdlength > 0)
51
+ @newname = Net::DNS::Packet::dn_expand(data, offset)[0];
52
+ end
53
+ end
54
+
55
+ def new_from_string(s)
56
+ if (s)
57
+ string = s.sub(/\.+$/, "");
58
+ @newname = string;
59
+ end
60
+ end
61
+
62
+ def new_from_hash(values)
63
+ if values.has_key?(:newname)
64
+ @newname = values[:newname]
65
+ end
66
+ end
67
+
68
+ def rdatastr
69
+ return @newname ? "#{@newname}." : '';
70
+ end
71
+
72
+ def rr_rdata(packet, offset)
73
+ rdata = "";
74
+
75
+ if (defined?@newname)
76
+ rdata += packet.dn_comp(@newname, offset);
77
+ end
78
+
79
+ return rdata;
80
+ end
81
+
82
+ def _canonicalRdata
83
+ rdata = "";
84
+ if (defined?@newname)
85
+ rdata += _name2wire(@newname);
86
+ end
87
+ return rdata;
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,124 @@
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::MX - DNS MX resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Mail Exchanger (MX) 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 Olaf Kolkman NLnet Labs.
34
+ #
35
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
36
+ #
37
+ #All rights reserved. This program is free software; you may redistribute
38
+ #it and/or modify it under the same terms as Perl itself.
39
+ #
40
+ #= SEE ALSO
41
+ #
42
+ #Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
43
+ #Net::DNS::Header, Net::DNS::Question, Net::DNS::RR,
44
+ #RFC 1035 Section 3.3.9
45
+ class MX < RR
46
+ #Returns the preference for this mail exchange.
47
+ #
48
+ # print "preference = ", rr.preference, "\n"
49
+ #
50
+ attr_accessor :preference
51
+ #Returns name of this mail exchange.
52
+ #
53
+ # print "exchange = ", rr.exchange, "\n"
54
+ #
55
+ attr_accessor :exchange
56
+ def init_rrsort_func
57
+ # Highest preference sorted first.
58
+ set_rrsort_func("preference", Proc.new { |a,b| a.preference() <=> b.preference()})
59
+
60
+ set_rrsort_func("default_sort", get_rrsort_func("preference"));
61
+ end
62
+
63
+
64
+
65
+ def new_from_data(data, offset)
66
+ if (@rdlength > 0)
67
+ @preference = data.unpack("\@#{offset} n")[0];
68
+ offset += Net::DNS::INT16SZ;
69
+
70
+ @exchange = Net::DNS::Packet.dn_expand(data, offset)[0];
71
+ end
72
+ end
73
+
74
+ def new_from_string(string)
75
+
76
+ if (string && (string =~ /^(\d+)\s+(\S+)$/))
77
+ @preference = $1.to_i;
78
+ @exchange = $2;
79
+ @exchange.gsub(/\.+$/, "")
80
+ end
81
+ end
82
+
83
+ def new_from_hash(values)
84
+ if values.has_key?(:preference)
85
+ @preference = values[:preference]
86
+ end
87
+ if values.has_key?(:exchange)
88
+ @exchange = values[:exchange]
89
+ end
90
+ end
91
+
92
+ def rdatastr
93
+ if (defined?@preference)
94
+ return "#{@preference} #{@exchange}"
95
+ else
96
+ '';
97
+ end
98
+ end
99
+
100
+ def rr_rdata(packet, offset)
101
+ rdata = "";
102
+
103
+ if (defined?@preference)
104
+ rdata += [@preference].pack("n");
105
+ rdata += packet.dn_comp(@exchange, offset + rdata.length);
106
+ end
107
+
108
+ return rdata;
109
+ end
110
+
111
+ def _canonicalRdata
112
+ rdata = "";
113
+
114
+ if (defined?@preference)
115
+ rdata += [@preference].pack("n");
116
+ rdata += _name2wire(@exchange)
117
+ end
118
+
119
+ return rdata;
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,182 @@
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::NAPTR - DNS NAPTR resource record
22
+ #
23
+ #= DESCRIPTION
24
+ #
25
+ #Class for DNS Naming Authority Pointer (NAPTR) 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 Olaf Kolkman NLnet Labs.
34
+ #
35
+ #Ruby version Copyright (c) 2006 AlexD (Nominet UK)
36
+ #
37
+ #All rights reserved. This program is free software; you may redistribute
38
+ #it and/or modify it under the same terms as Perl itself.
39
+ #
40
+ #Net::DNS::RR::NAPTR is based on code contributed by Ryan Moats.
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 2168
47
+ class NAPTR < RR
48
+ #Returns the order field.
49
+ #
50
+ # print "order = ", rr.order, "\n"
51
+ #
52
+ attr_accessor :order
53
+ #Returns the preference field.
54
+ #
55
+ # print "preference = ", rr.preference, "\n"
56
+ #
57
+ attr_accessor :preference
58
+ #Returns the flags field.
59
+ #
60
+ # print "flags = ", rr.flags, "\n"
61
+ #
62
+ attr_accessor :flags
63
+ #Returns the service field.
64
+ #
65
+ # print "service = ", rr.service, "\n"
66
+ #
67
+ attr_accessor :service
68
+ #Returns the regexp field.
69
+ #
70
+ # print "regexp = ", rr.regexp, "\n"
71
+ #
72
+ attr_accessor :regexp
73
+ #Returns the replacement field.
74
+ #
75
+ # print "replacement = ", rr.replacement, "\n"
76
+ #
77
+ attr_accessor :replacement
78
+ def init_rrsort_func
79
+ set_rrsort_func("order", Proc.new { |a,b| a.order <=> b.order || a.preference <=> b.preference } )
80
+ set_rrsort_func("default_sort", get_rrsort_func("order"))
81
+ set_rrsort_func("preference", Proc.new { |a,b| a.preference <=> b.preference || a.order <=> b.order } );
82
+ end
83
+
84
+ def new_from_data(data, offset)
85
+ if (@rdlength > 0)
86
+ @order = data.unpack("\@#{offset} n")[0];
87
+ offset += Net::DNS::INT16SZ;
88
+
89
+ @preference = data.unpack("\@#{offset} n")[0];
90
+ offset += Net::DNS::INT16SZ;
91
+
92
+ len = data.unpack("\@#{offset} C")[0];
93
+ offset+=1;
94
+ @flags = data.unpack("\@#{offset} a#{len}")[0];
95
+ offset += len;
96
+
97
+ len = data.unpack("\@#{offset} C")[0];
98
+ offset+=1;
99
+ @service = data.unpack("\@#{offset} a#{len}")[0];
100
+ offset += len;
101
+
102
+ len = data.unpack("\@#{offset} C")[0];
103
+ offset+=1;
104
+ @regexp = data.unpack("\@#{offset} a#{len}")[0];
105
+ offset += len;
106
+
107
+ @replacement = Net::DNS::Packet::dn_expand(data, offset)[0];
108
+ end
109
+
110
+ end
111
+
112
+ def new_from_string(string)
113
+ if (string && string =~ /^(\d+)\s+(\d+)\s+['"] (.*?) ['"] \s+['"] (.*?) ['"] \s+['"] (.*?) ['"] \s+(\S+) $/x)
114
+
115
+ @order = $1;
116
+ @preference = $2;
117
+ @flags = $3;
118
+ @service = $4;
119
+ @regexp = $5;
120
+ @replacement = $6;
121
+ @replacement.sub!(/\.+$/,"");
122
+ end
123
+ end
124
+
125
+ def new_from_hash(values)
126
+ if values.has_key?(:order)
127
+ @order = values[:order]
128
+ end
129
+ if values.has_key?(:preference)
130
+ @preference = values[:preference]
131
+ end
132
+ if values.has_key?(:flags)
133
+ @flags = values[:flags]
134
+ end
135
+ if values.has_key?(:service)
136
+ @service = values[:service]
137
+ end
138
+ if values.has_key?(:regexp)
139
+ @regexp = values[:regexp]
140
+ end
141
+ if values.has_key?(:replacement)
142
+ @replacement = values[:replacement]
143
+ end
144
+ end
145
+
146
+ def rdatastr
147
+ rdatastr=""
148
+
149
+ if (defined?@order)
150
+ rdatastr = @order.to_s + ' ' +@preference.to_s + ' "' +@flags.to_s + '" "' +@service.to_s + '" "' +@regexp.to_s + '" ' +@replacement.to_s + '.';
151
+ else
152
+ rdatastr = '';
153
+ end
154
+
155
+ return rdatastr;
156
+ end
157
+
158
+ def rr_rdata(packet, offset)
159
+ rdata = "";
160
+
161
+ if (defined?@order)
162
+
163
+ rdata += [@order, @preference].pack("n2");
164
+
165
+ rdata += [@flags.length].pack("C");
166
+ rdata += @flags;
167
+
168
+ rdata += [@service.length].pack("C");
169
+ rdata += @service;
170
+
171
+ rdata += [@regexp.length].pack("C");
172
+ rdata += @regexp;
173
+
174
+ rdata += packet.dn_comp(@replacement, offset + rdata.length);
175
+ end
176
+
177
+ return rdata;
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end