| 469 | 0x01 - A |
| 470 | */ |
| 471 | reply(response, mask, service, bye = false, from) { |
| 472 | let build = response ? false : true; |
| 473 | if (build) response = new Serializer({query: false, opcode: DNS.OPCODE.QUERY, authoritative: true}); |
| 474 | bye = bye ? 0 : 0xFFFFFFF; |
| 475 | |
| 476 | if (0x20 & mask) // NSEC indicating A only |
| 477 | response.add(DNS.SECTION.ANSWER, this.hostName + "." + LOCAL, DNS.RR.NSEC, DNS.CLASS.IN | MDNS.FLUSH, TTL & bye, |
| 478 | {next: this.hostName + "." + LOCAL, bitmaps: Uint8Array.of(0, 4, 0x40, 0, 0, 0)}); |
| 479 | |
| 480 | if (0x10 & mask) // PTR for service discovery |
| 481 | response.add(DNS.SECTION.ANSWER, "_services._dns-sd._udp.local", DNS.RR.PTR, DNS.CLASS.IN, TTL & bye, "_" + service.name + "._" + service.protocol + "." + LOCAL); |
| 482 | |
| 483 | if (0x08 & mask) // PTR |
| 484 | response.add(DNS.SECTION.ANSWER, "_" + service.name + "._" + service.protocol + "." + LOCAL, DNS.RR.PTR, DNS.CLASS.IN, TTL & bye, this.hostName + "._" + service.name + "._" + service.protocol + "." + LOCAL); |
| 485 | |
| 486 | if (0x04 & mask) // TXT |
| 487 | response.add(DNS.SECTION.ANSWER, this.hostName + "._" + service.name + "._" + service.protocol + "." + LOCAL, DNS.RR.TXT, DNS.CLASS.IN | ((0x8000 & mask) ? MDNS.FLUSH : 0), TTL & bye, service.txt); |
| 488 | |
| 489 | if (0x02 & mask) // SRV |
| 490 | response.add(DNS.SECTION.ANSWER, this.hostName + "._" + service.name + "._" + service.protocol + "." + LOCAL, DNS.RR.SRV, DNS.CLASS.IN, 120 & bye, |
| 491 | {priority: 0, weight: 0, port: service.port, target: this.hostName + "." + LOCAL}); |
| 492 | |
| 493 | if (0x01 & mask) // A |
| 494 | response.add(DNS.SECTION.ANSWER, this.hostName + "." + LOCAL, DNS.RR.A, DNS.CLASS.IN | MDNS.FLUSH, 120 & bye, Net.get("IP", from)); |
| 495 | |
| 496 | if (!build) |
| 497 | return; |
| 498 | |
| 499 | return response.build(); |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | Probe |