(message, value, address)
| 84 | super.close(); |
| 85 | } |
| 86 | callback(message, value, address) { |
| 87 | if (2 !== message) return; |
| 88 | if (76 !== value) |
| 89 | return; // not expected size |
| 90 | |
| 91 | // Ignore IP header |
| 92 | this.read(null, 20); |
| 93 | |
| 94 | // ICMP header |
| 95 | const values = new Uint8Array(this.read(ArrayBuffer, 56)); |
| 96 | if (values[0] || values[1]) |
| 97 | return; // not an echo reply |
| 98 | const checksum = (values[2] << 8) + values[3]; |
| 99 | const identifier = (values[4] << 8) + values[5]; |
| 100 | if (identifier !== this.#identifier) |
| 101 | return; // not for this instance |
| 102 | this.#reply = true; |
| 103 | const icmp_seq = (values[6] << 8) + values[7]; |
| 104 | if (!Ping.validate_checksum(identifier, icmp_seq, checksum)) |
| 105 | this.failed("Invalid checksum for icmp_seq "+icmp_seq); |
| 106 | |
| 107 | this.#callback(Ping.response, value - 20, {address, icmp_seq, identifier}); |
| 108 | } |
| 109 | |
| 110 | static checksum(values) { |
| 111 | let sum = 0; |
nothing calls this directly
no test coverage detected