You might also consider using PcapPlusPlus. It has a packet creation engine that supports ICMP and a way to send packets to the network.
Here is an example code for what you want (sending high-latency erroneous ICMP packets):
// open a pcap live device for interface with IP 10.0.0.1 (put your IP address instead)
IPv4Address ipToSearch("10.0.0.1");
PcapLiveDevice* liveDev = PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIp(ipToSearch);;
liveDev->open();
int NUM_OF_ERRONEOUS_PACKETS_TO_GENERATE = 1000;
// send NUM_OF_ERRONEOUS_PACKETS_TO_GENERATE echo request packets
for (int i = 0; i < NUM_OF_ERRONEOUS_PACKETS_TO_GENERATE; i++)
{
// create an Eth layer with whatever MAC addresses you want
MacAddress srcMac(std::string("11:22:33:44:55:66")); // put the MAC address you want here
MacAddress destMac(std::string("66:55:44:33:22:11")); // put the MAC address you want here
EthLayer ethLayer(srcMac, destMac, ETHERTYPE_IP);
// create IPv4 layer with whatever IPs you want (put the IPs you want instead)
IPv4Layer ipLayer(IPv4Address(std::string("1.1.1.1")), IPv4Address(std::string("2.2.2.2")));
// Create ICMP echo (ping) request layer
IcmpLayer echoReqLayer;
icmp_echo_request* echoReq = echoReqLayer.setEchoRequestData(100, 0, 0xe45104007dd6a751ULL, NULL, 0);
// make the echo request erroneous. You can do whatever manipulation you want here
echoReq->header->checksum = 0x1111;
echoReq->header->code = 100;
// create a packet with Eth, IPv4, ICMP echo layers;
Packet echoRequestPacket(100);
echoRequestPacket.addLayer(ðLayer);
echoRequestPacket.addLayer(&ipLayer);
echoRequestPacket.addLayer(&echoReqLayer);
// send the packet
liveDev->sendPacket(&echoRequestPacket);
}
liveDev->close();