Results 1 to 1 of 1
Code:
#include <stdio.h>
#include <sys/socket.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#define ETH_FRAME_LEN 1518
#define STRING "cool, this is raw ethernet packet!!! "
int main(int argc, char *argv[])
{
struct ...
- 11-03-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 1
ethernet raw programming
after the execution it gives back "send: Message too long" error...Code:#include <stdio.h> #include <sys/socket.h> #include <linux/if_packet.h> #include <linux/if_ether.h> #include <linux/if_arp.h> #define ETH_FRAME_LEN 1518 #define STRING "cool, this is raw ethernet packet!!! " int main(int argc, char *argv[]) { struct sockaddr_ll socket_address; int sock,i; void* buffer = (void*)malloc(ETH_FRAME_LEN); //mem for buffer unsigned char* etherhead = buffer;//set pointer of eth.hdr unsigned char* data = buffer + 14;//data in the frame struct ethhdr* eh = (struct ethhdr*)etherhead; /*our MAC address*/ unsigned char src_MAC[6] = {0x00, 0x01, 0x02, 0xFA, 0x70, 0xAA}; /*other host MAC address*/ unsigned char dst_MAC[6] = {0x00, 0x04, 0x75, 0xC8, 0x28, 0xE5}; if ((sock=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL)))==-1) {perror("raw socket"); exit(0);} socket_address.sll_family = AF_PACKET; socket_address.sll_protocol = htons(ETH_P_IP); socket_address.sll_ifindex = 2; socket_address.sll_hatype = ARPHRD_ETHER; socket_address.sll_pkttype = PACKET_OTHERHOST; socket_address.sll_halen = ETH_ALEN; socket_address.sll_addr[0] = 0x00; //00:0F:B0:0D:54:20 socket_address.sll_addr[1] = 0x0F; socket_address.sll_addr[2] = 0xB0; socket_address.sll_addr[3] = 0x0D; socket_address.sll_addr[4] = 0x54; socket_address.sll_addr[5] = 0x20; //socket_address.sll_addr[6] = 0x00; //socket_address.sll_addr[7] = 0x00; memcpy((void*)buffer,(void*)dst_MAC,ETH_ALEN); memcpy((void*)(buffer+ETH_ALEN),(void*)src_MAC,ETH_ALEN); eh->h_proto = 0x00; /*fill the data*/ for (i = 0; i < 1499; i++) { data[i] = (unsigned char)((int) (255.0*rand()/(100+1.0))); } while(1){ if((sendto(sock,buffer,ETH_FRAME_LEN,0,(struct sockaddr*)&socket_address,sizeof(socket_address)))==-1) {perror("send");exit(0);} } return 0; }
so, i dont know, whats the problem........
help me please


Reply With Quote