Re: Problem writing a packet to the network.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vijaymahantesh Kalakoti wrote:

Hi amith,

I think the problem can be from two causes,

1. the mode in which program is running.
	since u r receiving the packets this may not be the  problem.

2. bind the socket. *******************************
this may be the cause of it. Since u have created socket at datalink layer( PF_PACKET ), & it is not bind to a device, then u may get error.
pls bind the socket using the sockaddr_ll structure .
the manual page( man packet ) contains the information for this.


	
I am not sure of my answer. But give a try.

I hope it will solve u r problem.

Thanks & Regards.
vijay kalkoti


hi Vijay,
i'am not able to bind the Socket with these values could u just check whether they r proper ? the man pages say it is enough to initialize the struct's 2 feilds - ifindex and family (as far as i cud understand i.e ) . Could anyone help me initialize the struct ?
when i do this bind does not succeed with " bind failed :Invalid argument " could someone help ?


struct sockaddr_ll addr;
addr.sll_ifindex = 0; // guessing
addr.sll_protocol = htons(ETH_P_802_3); /*defined  in if_ether.h */


bind_return = bind(packet_socket,(struct sockaddr *)&addr,sizeof(addr));
if(bind_return != 0)
{
perror("Bind failed :");
exit(1);
}
printf(" Bind Success : returned %d\n",bind_return);


while( 1 )
{
int count=0;
printf("========================================= \n");
len = read(packet_socket,buffer,sizeof(buffer));
pkt = (struct Packet *)buffer;
if((pkt->ether.type[0] == 0X08) && (pkt->ether.type[1] ==0x06))
{
printf("ARP :");
Print_Arp_Packet(pkt);
Send_Arp_Packet(pkt);
}




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux