Ho un nuovo problema:
Ora mi legge tutto però se imposto un indirizzo MAC, quando ricevo il pacchetto me ne ristampa un'altro:
Qui preparo il pacchetto
//Preparo e includo nel paccheto l'header ipv6
ip6_header=(struct ip6_hdr *)calloc(1,sizeof(struct ip6_hdr));
ip6_header->ip6_ctlun.ip6_un1.ip6_un1_flow=0;
ip6_header->ip6_ctlun.ip6_un1.ip6_un1_plen=PACKET_LENGTH-(sizeof(struct ethhdr)+sizeof(struct ip6_hdr));
ip6_header->ip6_ctlun.ip6_un1.ip6_un1_nxt=59;
ip6_header->ip6_ctlun.ip6_un1.ip6_un1_hlim=0;
if(inet_pton(AF_INET6,"fe80::226:c7ff:fe85:6758",&ip6_header->ip6_src)!=1 || inet_pton(AF_INET6,"fe80::226:c7ff:fe85:6758",&ip6_header->ip6_dst)!=1)
{ perror("inet_pton");
//printf("%d", inet_pton(AF_INET6,host,&ip6_header->ip6_src));
}
ip6_header=(struct ip6_hdr*)packet;
//Preparo e includo nel pacchetto l'header ethernet
ethernet_header=(struct ethhdr *)calloc(1,sizeof(struct ethhdr));
if(ioctl(write_socket,SIOCGIFHWADDR,&freq)==-1) {
perror("ioctl");
close(write_socket);
exit(1);
}
ethernet_header->h_source[0]=0x00;
ethernet_header->h_source[1]=0x26;
ethernet_header->h_source[2]=0xc7;
ethernet_header->h_source[3]=0x27;
ethernet_header->h_source[4]=0x67;
ethernet_header->h_source[5]=0x58;
ethernet_header->h_dest[0]=0x00;
ethernet_header->h_dest[1]=0x26;
ethernet_header->h_dest[2]=0xc7;
ethernet_header->h_dest[3]=0x85;
ethernet_header->h_dest[4]=0x67;
ethernet_header->h_dest[5]=0x58;
printf("> Successfully received Local MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n",
ethernet_header->h_source[0],ethernet_header->h_source[1],ethernet_header->h_source[2]
,ethernet_header->h_source[3],ethernet_header->h_source[4],ethernet_header->h_source[5]);
ethernet_header=(struct ethhdr*)ip6_header;
payload=(char *)(packet+sizeof(struct ethhdr));
strcpy(payload,"Questo che leggete qui e' il payload del pacchetto ipv6 :)");
poi quando lo ricevo cerco di estrarre ogni header:
read_length=recv(read_socket,buffer,PACKET_LENGTH,0);
if(read_length==-1) {perror("recv");}
else {printf("sono stati ricevuti %d di dati con successo\n", read_length);}
//ethernet header
//ethhead=buffer;
//ethernet_header_rec=(struct ethhdr *)buffer;
memcpy(ðernet_header_rec, &buffer,sizeof(struct ethhdr));
printf("*********ethernet header******\n");
printf("> Successfully received Local MAC Address : %02x:%02x:%02x:%02x:%02x:%02x\n",
ethernet_header_rec->h_source[0],ethernet_header_rec->h_source[1],ethernet_header_rec->h_source[2]
,ethernet_header_rec->h_source[3],ethernet_header_rec->h_source[4],ethernet_header_rec->h_source[5]);
//ip6 header
printf("*******ip6 header******\n");
ip6hdr=(struct ip6_hdr*)(buffer+sizeof(struct ethhdr));
printf("il flow è %d\n", ip6hdr->ip6_ctlun.ip6_un1.ip6_un1_flow);
printf("il packet length è %d\n", ip6hdr->ip6_ctlun.ip6_un1.ip6_un1_plen);
printf("il campo successivo è %d\n", ip6hdr->ip6_ctlun.ip6_un1.ip6_un1_nxt);
però mi da un indirizzo diverso, e anche i campi del ipv6 header sono sfalzati perchè???