You are not logged in.
Pages: 1
Guys can anyone explain what the following 4 lines do,it's a piece of code from a syn flood attack.
int packet_size = (sizeof (struct iphdr)+sizeof (struct tcphdr)) * sizeof (char);
char *packet = (char *) malloc (packet_size);
struct iphdr *ip;
ip = (struct iphdr *) packet;
Last edited by S2xCracker1234 (2011-07-08 05:22 AM)
Offline
It just allocates enough memory for a whole packet, so IP and TCP headers.
It packs struct iphdr and tcphdr together manually. The code is quite ugly,
that might have confused you a bit.
Identical code:
int packet_size = sizeof(struct iphdr) + sizeof(struct tcphdr);
struct iphdr *ip = malloc(packet_size);
Offline
Last edited by S2xCracker1234 (2011-07-08 12:34 PM)
Offline
It's just an ugly way to deal with type differences between what data
is sent and what type is expected by sendto(). It used to be char*, but
nowadays it's void*, so there should be no need for keeping around
two pointers and all the unecessary casting.
Either you posted the wrong link, or the code in question got much
improved. As you can see in the link you posted, there is no need for
malloc at all.
Offline
Offline
Last edited by developwyo (2011-09-22 05:49 PM)
Offline
Pages: 1