MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / ping

Method ping

modules/network/ping/ping.js:53–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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();

Callers 1

constructorMethod · 0.95

Calls 2

writeMethod · 0.65
checksumMethod · 0.45

Tested by

no test coverage detected