Quote:
Originally Posted by andryk
I've never been involved in such project but i guess you need to build the entire packet starting from link level header (eth) to arp and can use write() to send out packet, mac is used to route, no need of ip address required by sendto()
... and of course if u have multiple IF, you might want to bind to the correct IF owning the src mac of the pkt u are sending
Do let me know if my answer hinted u good
thanks andryk
Since I'm using SOCK_DGRAM I think I need not create any ethernet header the kernel functions parse the packet to remove the header and store it in the sockaddr_ll struct as I could figure out from the man page I need to create an ARP header for reply.
Now the problem comes to the location of address. With some more googling I'm getting the addresss of the client as sockaddr_ll structure ( as against normal sockaddr_in structure we declare the address used in recvfrom as sockaddr_ll and type cast it to sockaddr when passing to recvfrom) as shown below
struct sockaddr_ll client; //declaration for storing address of client sending ARP request
recvfrom(sock,buff,sizeof(buff),0,(struct sockaddr*)&client,&len);
And now I'm getting the address to be used in sendto function's secondlast argument (I guess that this argument is used to construct the ethernet header for reply)
int n = sendto(sock,buff,sizeof(buff),0,(struct sockaddr*)&client,len);
But still I'm not out of trouble as now the sendto doesn't give any error but if I check the characters transferred by sendto (in n above) it is 0. And also the other side doesn't show signs of recieving any packet as seen by monitors (same code as it is recieving the packet well).
So what can be the problem ..... can not binding create problems (I thought no binding will b requd for it makes the app to monitor just one interface and besides does it have to do anything with sending....I guess not) .
Also for that type conversion (from socaddr_ll to sockaddr I'm in doubt for wont it make us to lose some fields as the source is larger than destination).
If u get an answer instantly post it for I can't proceed without that.
And thanks again for showing interest.