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

Method sendIP

src/network.js:495–518  ·  view source on GitHub ↗
(payload, protocol, srcIP, dstIP)

Source from the content-addressed store, hash-verified

493 }
494
495 sendIP(payload, protocol, srcIP, dstIP) {
496 const header = Buffer.alloc(20);
497 header[0] = 0x45; // v4, 5 words
498 header[1] = 0; // TOS
499 header.writeUInt16BE(20 + payload.length, 2);
500 header.writeUInt16BE(0, 4); // ID
501 header.writeUInt16BE(0, 6); // Flags/Offset
502 header[8] = 64; // TTL
503 header[9] = protocol;
504 srcIP.copy(header, 12);
505 dstIP.copy(header, 16);
506
507 // IP Checksum
508 header.writeUInt16BE(this.calculateChecksum(header), 10);
509
510 const packet = Buffer.concat([header, payload]);
511
512 // Check if destination is broadcast
513 if (dstIP[0] === 255 && dstIP[1] === 255 && dstIP[2] === 255 && dstIP[3] === 255) {
514 this.sendBroadcast(packet, ETH_P_IP);
515 } else {
516 this.send(packet, ETH_P_IP);
517 }
518 }
519
520 handleTCP(segment, srcIP, dstIP, fullIPPacket) {
521 const srcPort = segment.readUInt16BE(0);

Callers 3

_handleUdpResponseMethod · 0.95
handleICMPMethod · 0.95
sendTCPMethod · 0.95

Calls 3

calculateChecksumMethod · 0.95
sendBroadcastMethod · 0.95
sendMethod · 0.95

Tested by

no test coverage detected