Creating icmp packet
Hi
I'm using libipq to get some tcp packets and i want to send back a port unreachable msg if ip matches some list
So far everything works fine except creating the icmp packet Perhaps any1 can give me a hint what i made wrong?
Here my code to generate packet:
ip->version = 4;ip->ihl = 5;ip->id = htonl(random());ip->saddr = iph->daddr;ip->daddr = iph->saddr;ip->ttl = 123;ip->protocol = IPPROTO_ICMP;ip->tot_len = icmppacketsize;ip->check = 0;
icmp->type = 3;icmp->code = 3;icmp->checksum = 0;icmp->un.echo.id = m->packet_id;icmp->checksum = in_cksum((u_short *) icmp,sizeof(icmp));
struct sockaddr_in icmpaddr;
icmpaddr.sin_family = AF_INET;
icmpaddr.sin_port = htons(111);
icmpaddr.sin_addr.s_addr = ip->saddr;
if( (sendto(rawsock,icmppacket,icmppacketsize,0,(struct sockaddr*)&icmpaddr,sizeof(struct sockaddr_in))) == -1 ) {
cout << "error sending icmp packet\n";
}
Send alway fails
Cheers,
Stephan