HI !!
I would like to send a raw packet over the network -
Below is the code I have written -
When I do a strace - I see that the sendto call is sending to if0 for some reason - MY Lan card is eth0.
for the sockaddr_ll structure YOU CAN ONLY SPECIFY THE INTERFACE INDEX ----
AM I MISSING SOMEHING ???? Is this whats causing the error? i have attached the strace for the bind call too.
--------------------------
----------
----------
----------
--
int sockfd, portno=4500, n;
struct sockaddr_in serv_addr;
struct hostent *server;
struct sockaddr_ll link1, myaddr;
struct sockaddr from, to;
struct ifreq ifr;
char hwaddr[6]={0xb5,0x0e,0x50,
0x96,0x40,
0x00};
unsigned char proto[2]={0x00, 0x03};
unsigned char buffer[256];
unsigned char *pkt;
pkt = buffer;
memset(buffer, 0 , sizeof(buffer));
memset(&ifr,0,sizeof(ifr))
;
memset(&myaddr, '\0' , sizeof(myaddr));
myaddr.sll_family = AF_PACKET ;
myaddr.sll_protocol = htons(ETH_P_ALL);
myaddr.sll_ifindex = 0;
from.sa_family=AF_PACKET;
strcpy(from.sa_data,"eth0"
);
memset(&from,0,sizeof(from
));
strcpy(ifr.ifr_name,"eth0"
);
ifr.ifr_ifindex=0;
sockfd = socket (PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL));
printf(" Socket call returned %d \n", sockfd);
printf(" ioctl returns %d ",ioctl(sockfd, SIOCGIWNAME, &ifr));
printf(" Name is %s \n",&ifr.ifr_name);
/*************************
**********
**********
**********
*********
Build sockaddr_ll here
**************************
**********
**********
**********
*******/
link1.sll_family=AF_PACKET
;
link1.sll_protocol=0x300;
link1.sll_hatype=0xFFFF;
link1.sll_pkttype=PACKET_O
UTGOING;
link1.sll_ifindex = 0 ;
link1.sll_addr[0]=0xff;
link1.sll_addr[1]=0xff;
link1.sll_addr[2]=0xff;
link1.sll_addr[3]=0xff;
link1.sll_addr[4]=0xff;
link1.sll_addr[5]=0xff;
link1.sll_addr[6]=0x00;
link1.sll_addr[7]=0x00;
link1.sll_halen = 6;
/*************************
**** Finished building sockaddr_11 */
printf("Binding returns %d \n",bind(sockfd, &link1, sizeof(link1)));
printf("\n\nEnter Data Message:");
printf("Setting Destination MAC Address\n");
memcpy(pkt, &hwaddr, 6);
printf(" -Done \n");
memcpy(pkt+6, &hwaddr, 6);
memcpy(pkt+12, &proto ,2);
printf(" Done protocol \n");
memcpy(pkt+14, ".DATA.", sizeof(".DATA."));
n=send(sockfd, &pkt, sizeof(pkt), 0, (struct sockaddr *) &link1, 6 );
printf(" Bytes Sent %d. Error Number %s\n ",n, strerror(errno));
--------------------------
----------
----------
----------
--
strace --bind
bind(3,{sin_family=AF_PACK
ET,proto=0
x08, if0, pkttype=2, addr(6)={1,ffffffffffff}, 20) =0
//is successful though
sento() gives the error - No such device or Address?
PLLLLLLEASASSSEE HELLLLLP !!!!
I am DESPARATE -- have been going crazy over this
-
Thanks
Regards
_ _
\\//
Sunny
//\\
- -
Start Free Trial