#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
int main(int argc, char *argv)
{
char dst_addr[] = "93.184.216.34";
short dst_port = 80;
int icmp_socket;
struct sockaddr_in addr;
struct iphdr ip_header;
struct icmphdr icmp_header;
int len = sizeof(struct iphdr) + sizeof(struct icmphdr) + 64;
char data[len];
char recv_data[len];
socklen_t recv_len;
addr.sin_family = AF_INET;
addr.sin_port = htons(dst_port);
addr.sin_addr.s_addr = inet_addr(dst_addr);
icmp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (icmp_socket == -1) {
}
memset(&ip_header
, 0, sizeof(struct iphdr
)); ip_header.version = IPVERSION;
ip_header.tos = IPTOS_ECN_NOT_ECT;
ip_header.id = 0;
ip_header.frag_off = 1;
ip_header.ttl = 32;
ip_header.protocol = IPPROTO_ICMP;
ip_header.saddr = 0;
ip_header.daddr = addr.sin_addr.s_addr;
memset(&icmp_header
, 0, sizeof(struct icmphdr
)); icmp_header.type = ICMP_ECHO;
icmp_header.checksum = 0x00;
memcpy(data
, &ip_header
, sizeof(struct iphdr
)); memcpy(data
+ sizeof(struct iphdr
), &icmp_header
, sizeof(struct icmphdr
)); memcpy(data
+ len
- 64, (char *) "Test...Test...Test...", 64);
sendto(icmp_socket, data, len, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr));
recvfrom(icmp_socket, recv_data, len, 0, (struct sockaddr *) &addr, &recv_len);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8dW5pc3RkLmg+CiNpbmNsdWRlIDxzeXMvc29ja2V0Lmg+CiNpbmNsdWRlIDxhcnBhL2luZXQuaD4KI2luY2x1ZGUgPG5ldGluZXQvaXAuaD4KI2luY2x1ZGUgPG5ldGluZXQvaXBfaWNtcC5oPgo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