()
| 51 | }); |
| 52 | } |
| 53 | ping() { |
| 54 | this.#icmp_seq++; |
| 55 | const values = new Uint8Array(56); // 8 for icmp header + 48 for icmp payload |
| 56 | |
| 57 | // ICMP header |
| 58 | values[0] = 8; // type 8 (echo request) |
| 59 | // values[1] = 0; // code 0 |
| 60 | // values[2] = values[3] = 0; // will be the checksum |
| 61 | values[4] = this.#identifier >> 8; |
| 62 | values[5] = this.#identifier; |
| 63 | values[6] = this.#icmp_seq >> 8; |
| 64 | values[7] = this.#icmp_seq; |
| 65 | for (let i=8, val=0x08; val<0x38; val+=1, i++) { // packet data |
| 66 | values[i] = val; |
| 67 | } |
| 68 | const checksum = Ping.checksum(values); |
| 69 | values[2] = checksum >> 8; |
| 70 | values[3] = checksum; |
| 71 | |
| 72 | this.#reply = false; |
| 73 | this.write(this.#address, values.buffer); |
| 74 | } |
| 75 | failed(message) { |
| 76 | this.#callback(Ping.error, message); |
| 77 | this.close(); |
no test coverage detected