/***************************************** Exemplo - Socket RAW para envio de frames *****************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include unsigned char buff[1500]; void monta_pacote() { struct ether_header *eth; eth = (struct ether_header *) &buff[0]; //Endereco Mac Destino eth->ether_dhost[0] = 0X00; eth->ether_dhost[1] = 0X06; eth->ether_dhost[2] = 0X5B; eth->ether_dhost[3] = 0X28; eth->ether_dhost[4] = 0XAE; eth->ether_dhost[5] = 0X73; //Endereco Mac Origem eth->ether_shost[0] = 0X00; eth->ether_shost[1] = 0X08; eth->ether_shost[2] = 0X74; eth->ether_shost[3] = 0XB5; eth->ether_shost[4] = 0XB5; eth->ether_shost[5] = 0X8E; eth->ether_type = htons(0X800); } int main(int argc,char *argv[]) { int sock, i; struct ifreq ifr; struct sockaddr_ll to; socklen_t len; unsigned char addr[6]; memset(&ifr, 0, sizeof(ifr)); if((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { perror("Erro na criacao do socket"); exit(0); } to.sll_protocol= htons(ETH_P_ALL); to.sll_ifindex = 2; monta_pacote(); addr[0]=0x00; addr[0]=0x0b; addr[0]=0xcd; addr[0]=0x5e; addr[0]=0xee; addr[0]=0x6d; memcpy (to.sll_addr, addr, 6); len = sizeof(struct sockaddr_ll); if(sendto(sock, (char *) buff, sizeof(buff), 0, (struct sockaddr*) &to, len)<0) perror("sendto maquina B"); }