MCPcopy Create free account
hub / github.com/deepclause/agentvm / handleARP

Method handleARP

src/network.js:415–439  ·  view source on GitHub ↗
(packet)

Source from the content-addressed store, hash-verified

413 }
414
415 handleARP(packet) {
416 // Simple ARP Reply
417 // Hardware Type (2), Protocol (2), HLen (1), PLen (1), Op (2)
418 const op = packet.readUInt16BE(6);
419 if (op === 1) { // Request
420 // Target IP
421 const targetIP = packet.subarray(24, 28);
422 const targetIPStr = targetIP.join('.');
423
424 if (targetIPStr === this.gatewayIP) {
425 // Reply
426 const reply = Buffer.alloc(28);
427 packet.copy(reply, 0, 0, 8); // Copy HW/Proto/Len
428 reply.writeUInt16BE(2, 6); // Reply Op
429
430 this.gatewayMac.copy(reply, 8); // Sender HW
431 targetIP.copy(reply, 14); // Sender IP (Gateway)
432
433 packet.subarray(8, 14).copy(reply, 18); // Target HW (VM)
434 packet.subarray(14, 18).copy(reply, 24); // Target IP (VM)
435
436 this.send(reply, ETH_P_ARP);
437 }
438 }
439 }
440
441 handleIP(packet) {
442 const version = packet[0] >> 4;

Callers 1

receiveMethod · 0.95

Calls 1

sendMethod · 0.95

Tested by

no test coverage detected