(net, srcIP, dstIP, protocol, payloadLen)
| 35 | |
| 36 | // Helper to create IP header |
| 37 | function createIPHeader(net, srcIP, dstIP, protocol, payloadLen) { |
| 38 | const header = Buffer.alloc(20); |
| 39 | header[0] = 0x45; // Version 4, IHL 5 |
| 40 | header[1] = 0x00; // DSCP/ECN |
| 41 | header.writeUInt16BE(20 + payloadLen, 2); // Total length |
| 42 | header.writeUInt16BE(0, 4); // Identification |
| 43 | header.writeUInt16BE(0x4000, 6); // Flags + Fragment offset (Don't fragment) |
| 44 | header[8] = 64; // TTL |
| 45 | header[9] = protocol; // Protocol |
| 46 | header.writeUInt16BE(0, 10); // Checksum (calculate after) |
| 47 | Buffer.from(srcIP.split('.').map(Number)).copy(header, 12); |
| 48 | Buffer.from(dstIP.split('.').map(Number)).copy(header, 16); |
| 49 | |
| 50 | // Calculate checksum |
| 51 | const checksum = net.calculateChecksum(header); |
| 52 | header.writeUInt16BE(checksum, 10); |
| 53 | |
| 54 | return header; |
| 55 | } |
| 56 | |
| 57 | const vmMac = Buffer.from([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]); |
| 58 | const gatewayMac = Buffer.from([0x5a, 0x94, 0xef, 0xe4, 0x0c, 0xdd]); |
no test coverage detected