I'm writing code about raw sockets. In linux this code is ok:
But under FreeBSD I have these errors:
Can you help me?
Thanks a lot
Code:
void spoofa(smurfina *p,smurfina *q)
{ const int PKT_LEN=9999;
int sd;
char buffer[PKT_LEN];
struct iphdr *ip = (struct iphdr *) buffer;
struct udphdr *udp = (struct udphdr *) (buffer + sizeof(struct iphdr));
struct sockaddr_in sin;
int one = 1;
const int *val = &one;
memset(buffer, 0, PKT_LEN);
sd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP); //Pacchetto UDP
if (sd < 0)
{ perror("Errore inoltro Disconnect");
return ;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(p->porta);
sin.sin_addr.s_addr = p->ip_addr.s_addr; //indirizzo IP destinazione
ip->ihl = 5; //pacchetto IP
ip->version = 4; //IPV4
ip->tos = 16; //Mi pare minimize delay
ip->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 5; //5 il mex hola+'\0'
ip->id = htons(52407); //
ip->ttl = 64; //Quanto mi resta da vivere?
ip->protocol = 17; //UDP
ip->saddr = p->ip_addr.s_addr; //indirizzo IP destinazione
ip->daddr = q->ip_addr.s_addr; //indirizzo IP destinazione
//pacchetto UDP
udp->source = htons(9999); //porta UDP sorgente
udp->dest = htons(p->porta); //porta UDP destinazione
udp->len = htons(sizeof(struct udphdr)+5);
strcpy(buffer+sizeof(struct iphdr)+(sizeof(struct udphdr)) ,"hola");
ip->check = csum((unsigned short *) buffer, sizeof(struct iphdr) + sizeof(struct udphdr)); //calcolo checksum
if (setsockopt(sd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0) //informo il sistema operativo che l'intestazione IP è già presente
perror("Errore setsockopt()");
if (sendto(sd, buffer, ip->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin)) < 0) //invio pacchetto
perror("Errore sendto()");
}
But under FreeBSD I have these errors:
Code:
In file included from main_server.c:4:
./server.h: In function `spoofa':
./server.h:388: error: invalid application of `sizeof' to incomplete type `iphdr'
./server.h:402: error: dereferencing pointer to incomplete type
./server.h:403: error: dereferencing pointer to incomplete type
./server.h:404: error: dereferencing pointer to incomplete type
./server.h:405: error: dereferencing pointer to incomplete type
./server.h:405: error: invalid application of `sizeof' to incomplete type `iphdr'
./server.h:406: error: dereferencing pointer to incomplete type
./server.h:407: error: dereferencing pointer to incomplete type
./server.h:408: error: dereferencing pointer to incomplete type
./server.h:409: error: dereferencing pointer to incomplete type
./server.h:410: error: dereferencing pointer to incomplete type
./server.h:413: error: structure has no member named `source'
./server.h:414: error: structure has no member named `dest'
./server.h:415: error: structure has no member named `len'
./server.h:416: error: invalid application of `sizeof' to incomplete type `iphdr'
./server.h:417: error: dereferencing pointer to incomplete type
./server.h:417: error: invalid application of `sizeof' to incomplete type `iphdr'
./server.h:422: error: dereferencing pointer to incomplete type
Can you help me?
Thanks a lot