Ciao a tutti,
vorrei sapere come si fa a spedire un pacchetto udp? azni a spedirlo non ci sono ancora arrivato....
Il mio problema è la creazione del pacchetto UDP e la successiva spedizione...
ho trovato un pò di materiale su internet e ci stavo provando ma quando lo lancio mi da come errore "segmentation fault"
alleggo il codice che uso per creare il pacchetto:
L'errore di runtime è dato dall'eseguzione delle ultime 3 memcpy.codice:// Allocca memoria per l'header Ethernet ethernet_header = (struct ethhdr *) malloc(sizeof(struct ethhdr)); // Setta campi dell'header Ethernet memcpy((void *)ethernet_header->h_source, (void *)ether_aton(SRC_ETHER_ADDR), 6); memcpy((void *)ethernet_header->h_dest, (void *)ether_aton(DST_ETHER_ADDR), 6); ethernet_header->h_proto = htons(ETHERTYPE_IP); udp = (struct udphdr *) malloc(sizeof(struct udphdr)); udp = (struct udphdr *) packet1; udp->source=htons(sport); udp->dest = htons(dport); udp->check=0; // Allocca memoria per l'header IP ip_header = (struct iphdr *) malloc(sizeof(struct iphdr)); // Setta campi dell'header IP ip_header->version = 4; ip_header->ihl = (sizeof(struct iphdr))/4; ip_header->tos = 0; ip_header->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr)); ip_header->id = htons(0); ip_header->frag_off = 0; ip_header->ttl = 64; ip_header->protocol = IPPROTO_UDP; ip_header->saddr = inet_addr(srcip); ip_header->daddr = inet_addr(srcip); ip_header->check = checksum((unsigned char *) ip_header, ip_header->ihl*4); memcpy(packet, ethernet_header, sizeof(struct ethhdr)); memcpy(packet + sizeof(struct ethhdr), ip_header, sizeof(struct iphdr)); memcpy(packet + sizeof(struct ethhdr) + sizeof(struct iphdr), udp, sizeof(struct udphdr));
premetto che è materiale che ho messo insieme da vari stralci su internet.....
Poi per la spedizione ho trovato che si può fare con pcap_sendpacket, o in alternativa con la raw socket....ma a quello ci penserò dopo!
Alla fine quello che mi interesserebbe fare è riuscire a creare un pacchetto UDP e spedirlo senza fare il passaggio socket/device, le socket raw per l'appunto....
Grazie
Ciao

Rispondi quotando