(payload, protocol, srcIP, dstIP)
| 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); |
no test coverage detected