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

Method handleIP

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

Source from the content-addressed store, hash-verified

439 }
440
441 handleIP(packet) {
442 const version = packet[0] >> 4;
443 if (version !== 4) return;
444
445 const headerLen = (packet[0] & 0x0F) * 4;
446 const totalLen = packet.readUInt16BE(2);
447 const protocol = packet[9];
448 const srcIP = packet.subarray(12, 16);
449 const dstIP = packet.subarray(16, 20);
450
451 const data = packet.subarray(headerLen, totalLen); // strict length?
452
453 // this.emit('debug', `[IP] proto=${protocol} src=${srcIP.join('.')} dst=${dstIP.join('.')} len=${data.length}`);
454
455 if (protocol === IP_PROTO_ICMP) {
456 this.handleICMP(data, srcIP, dstIP, packet.subarray(0, headerLen));
457 } else if (protocol === IP_PROTO_TCP) {
458 this.handleTCP(data, srcIP, dstIP, packet);
459 } else if (protocol === IP_PROTO_UDP) {
460 this.handleUDP(data, srcIP, dstIP);
461 }
462 }
463
464 // Checksum Helpers
465 calculateChecksum(buf) {

Callers 1

receiveMethod · 0.95

Calls 3

handleICMPMethod · 0.95
handleTCPMethod · 0.95
handleUDPMethod · 0.95

Tested by

no test coverage detected