| 194 | } |
| 195 | } |
| 196 | scanPacket(packet, address) { |
| 197 | const answers = packet.answers; |
| 198 | let changed, i, j, length; |
| 199 | for (i = 0, length = answers + packet.additionals; i < length; i++) { |
| 200 | const record = (i < answers) ? packet.answer(i) : packet.additional(i - answers); |
| 201 | let name = record.qname, service; |
| 202 | let monitor, instance; |
| 203 | |
| 204 | switch (record.qtype) { |
| 205 | case DNS.RR.A: |
| 206 | //@@ if not probing, check to see if name matches and IP is different. If so there is a conflict, revert to probing state... |
| 207 | if ((this.probing > 0) && (this.hostNameLower == name[0].toLowerCase()) && (2 === name.length) && (LOCAL === name[1].toLowerCase())) { |
| 208 | trace(`probe conflict with ${address}\n`); |
| 209 | this.probing = -1; |
| 210 | this.probeAttempt += 1; |
| 211 | break; |
| 212 | } |
| 213 | name = name.join("."); |
| 214 | this.monitors.forEach(monitor => { |
| 215 | monitor.forEach(instance => { |
| 216 | if (instance.target?.toLowerCase() === name.toLowerCase()) |
| 217 | instance.address = record.rdata; |
| 218 | }); |
| 219 | }); |
| 220 | break; |
| 221 | case DNS.RR.PTR: |
| 222 | service = name.join("."); |
| 223 | monitor = this.monitors.find(monitor => monitor.service === service); |
| 224 | if (!monitor) |
| 225 | break; |
| 226 | instance = monitor.find(item => item.name === record.rdata[0]); |
| 227 | if (!instance) { |
| 228 | instance = {name: record.rdata[0]}; |
| 229 | monitor.push(instance); |
| 230 | instance.changed = changed = true; |
| 231 | } |
| 232 | instance.ttl = record.ttl |
| 233 | break; |
| 234 | case DNS.RR.SRV: |
| 235 | case DNS.RR.TXT: |
| 236 | service = name.slice(1).join("."); |
| 237 | monitor = this.monitors.find(monitor => monitor.service === service); |
| 238 | if (!monitor) |
| 239 | break; |
| 240 | instance = monitor.find(item => item.name.toLowerCase() === name[0].toLowerCase()); |
| 241 | if (!instance) { |
| 242 | instance = {name: name[0]}; |
| 243 | monitor.push(instance); |
| 244 | } |
| 245 | if (DNS.RR.TXT === record.qtype) { |
| 246 | const txt = record.rdata ? record.rdata : []; |
| 247 | if (!instance.txt || (instance.txt.length !== txt.length)) { |
| 248 | instance.txt = txt; |
| 249 | instance.changed = changed = true; |
| 250 | } |
| 251 | else { |
| 252 | for (j = 0; j < txt.length; ++j) { |
| 253 | if (txt[j] === instance.txt[j]) |