rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/ip.h>
#include <linux/icmp.h>
#include <netinet/in.h>
#define SRC "206.204.215.152"
#define DST "69.55.233.87"
#define NICK "orion"
unsigned short in_cksum(unsigned short *, int);
int main (int argc, char **argv) {
int sock;
char datagram[sizeof(struct iphdr) + sizeof(struct icmphdr) + strlen(NICK)];
struct icmphdr *icmp;
struct iphdr *ip;
struct sockaddr_in dst;
//sock = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
sock = atoi(argv[1]);
memset(datagram, 0, sizeof(datagram));
ip = (struct iphdr *)datagram;
icmp = (struct icmphdr *)(datagram + sizeof(struct iphdr));
ip->ihl = 5;
ip->version = 4;
ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + strlen(NICK));
ip->ttl = 255;
ip->protocol = IPPROTO_ICMP;
ip->saddr = inet_addr(SRC); // dotgov.gov
ip->daddr = inet_addr(DST);
icmp->type = 130;
icmp->code = ICMP_DEST_UNREACH;
datagram[sizeof(struct iphdr) + sizeof(struct icmphdr)] = 'o';
datagram[sizeof(struct iphdr) + sizeof(struct icmphdr)+1] = 'r';
datagram[sizeof(struct iphdr) + sizeof(struct icmphdr)+2] = 'i';
datagram[sizeof(struct iphdr) + sizeof(struct icmphdr)+3] = 'o';
datagram[sizeof(struct iphdr) + sizeof(struct icmphdr)+4] = 'n';
ip->check = in_cksum((unsigned short *)datagram, sizeof(struct iphdr));
icmp->checksum = in_cksum((unsigned short *)(datagram + sizeof(struct iphdr)), sizeof(struct icmphdr) + 5);
dst.sin_addr.s_addr = inet_addr(DST);
dst.sin_family = AF_INET;
{
int one = 1;
const int *val = &one;
if (setsockopt (sock, IPPROTO_IP, IP_HDRINCL, val, sizeof (one)) < 0) {
perror("setsockopt");
exit(1);
}
}
sendto(sock, datagram, sizeof(datagram), 0, (struct sockaddr *)&dst, sizeof(struct sockaddr));
close(sock);
exit(0);
}
unsigned short in_cksum(u_short *addr, int len) {
register int nleft = len;
register u_short *w = addr;
register int sum = 0;
u_short answer = 0;
while (nleft > 1) {
sum += *w++;
nleft -= 2;
}
if (nleft == 1) {
*(u_char *)(&answer) = *(u_char *)w ;
sum += answer;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return(answer);
}