1
# $Id: dns_message.rb,v 1.12 2003/10/16 11:21:24 sdalu Exp $
4
# AUTHOR : Stephane D'Alu <sdalu@nic.fr>
5
# CREATED : 2002/08/02 13:58:17
7
# COPYRIGHT: AFNIC (c) 2003
12
# $Date: 2003/10/16 11:21:24 $
15
# - the ruby file: resolv.rb
17
# CONTRIBUTORS: (see also CREDITS file)
22
# TODO: add a hash facility to Section
28
attr_reader :msgid, :opcode
30
# Allow generation of message id
34
Thread.exclusive { @@genid = (@@genid + 1) & 0xffff }
36
@@genid = (@@genid + 1) & 0xffff
41
if id < 0 || id > 0xffff
42
raise ArgumentError, 'message id should be in [0..0xffff]'
49
if code.nil? || code.class != OpCode
51
'expected type NResolv::DNS::OpCode'
58
self.msgid = id.nil? ? Message::generate_id : id
64
@ad = @cd = nil # RFC 2535
65
@rcode = RCode::NOERROR
67
@answer = @authority = @additional = nil
81
def initialize(msgid=nil)
84
@opcode = OpCode::QUERY
85
@question = Section::Q::new
89
unless q.nil? || q.class == Section::Q
91
'expected type NResolv::DNS::Section::Q'
100
class Answer < Message
101
attr_reader :qr, :aa, :rd, :ra, :tc
102
attr_reader :rcode, :question, :answer, :authority, :additional
103
attr_writer :qr, :aa, :rd, :ra, :tc
105
def initialize(msgid=nil)
108
@opcode = OpCode::QUERY
109
@question = Section::Q::new
110
@answer = Section::A::new
111
@authority = Section::A::new
112
@additional = Section::A::new
117
unless code.kind_of?(RCode)
118
raise ArgumentError, "expecting #{RCode}"
127
unless q.kind_of?(Section::Q)
128
raise ArgumentError, "expecting #{Section::Q}"
137
unless a.kind_of?(Section::A)
138
raise ArgumentError, "expecting #{Section::A}"
147
unless a.kind_of?(Section::A)
148
raise ArgumentError, "expecting #{Section::A}"
157
unless a.kind_of?(Section::A)
158
raise ArgumentError, "expecting #{Section::A}"
173
if self.class == Section
174
raise "#{self.class} is an abstract class"
180
def length ; @record.length ; end
181
def empty? ; @record.empty? ; end
182
def [](idx) ; @record[idx] ; end
183
def each(&block) ; @record.each &block ; end
184
def reject!(&block) ; @record.reject! &block ; end
185
def sort! ; @record.sort! { |x, y|
186
x[0].to_s <=> y[0].to_s } ; end
194
def add(name, rdata, ttl)
196
@record << [ name, rdata, ttl ]
204
def add(name, rd_class)
206
@record << [ name, rd_class ]