64 unsigned int etherType = 12;
65 unsigned int ipHeader = 0;
66 unsigned int tcpHeader = 0;
69 if (packet[etherType] == 0x81 && packet[etherType+1] == 0x00) etherType += 4;
70 ipHeader = etherType + 2;
72 if (packet[etherType] == 0x08 && packet[etherType+1] == 0x00) {
73 unsigned int internetHeaderLength =
static_cast<unsigned int>(packet[ipHeader] & 0x0f) * 4;
74 tcpHeader = ipHeader + internetHeaderLength;
76 std::swap_ranges(packet+ipHeader+12,packet+ipHeader+12+4,packet+ipHeader+16);
78 else if (packet[etherType] == 0x86 && packet[etherType+1] == 0xdd) {
79 tcpHeader = ipHeader + 40;
81 std::swap_ranges(packet+ipHeader+8,packet+ipHeader+8+16,packet+ipHeader+24);
87 std::swap_ranges(packet+tcpHeader+0,packet+tcpHeader+0+2,packet+tcpHeader+2);
93 size_t frameSize,
int numPackets, uint64_t perPacketDelay,
bool swapIp)
110 std::memset(ptr, 0, frameSize);
111 std::memcpy(ptr, packet, packetSize);
120 if (perPacketDelay != 0) {
121 std::this_thread::sleep_for(std::chrono::milliseconds(perPacketDelay));
126 std::this_thread::sleep_for(std::chrono::milliseconds(100));
133 std::this_thread::sleep_for(std::chrono::milliseconds(100));