139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
-
-
|
end
handle_packet(buf[0, len], addr)
end
end
end
def handle_packet(packet : Bytes, sender : Socket::IPAddress) : Nil
io = IO::Memory.new(packet, writeable: false)
begin
id = packet[0].to_u16 << 8 | packet[1]
begin
context = @queries[id]
rescue KeyError
return
|
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
+
|
io = IO::Memory.new(packet[4, packet.size - 4], writeable: false)
qdcount = io.read_bytes(UInt16, IO::ByteFormat::BigEndian)
adcount = io.read_bytes(UInt16, IO::ByteFormat::BigEndian)
nscount = io.read_bytes(UInt16, IO::ByteFormat::BigEndian)
arcount = io.read_bytes(UInt16, IO::ByteFormat::BigEndian)
rescue IndexError
rescue IO::EOFError
end
end
def stop : Nil
@v6_sock.try { |s| s.close }
@v4_sock.try { |s| s.close }
end
end
end
|