If I want to send (and receive) a packet through IP (without TCP or UDP),
  1. Is good to use SOCK_RAW?
 
Code example I use (send):
{
   s = socket(AF_INET, SOCK_RAW,255);
   ip = (struct iphdr *) buf;
   ip->ihl=5; ip->version=4;
   ip->tos=0; ip->frag_off=0;
   ip->tot_len=(pLen+20)*16;
   ip->ttl=64; ip->protocol=255;
 
   dpdir = gethostbyname( daddr );          /* Remote IP address */
   bcopy(dpdir->h_addr,  &ip->daddr, dpdir->h_length);
   Dir.sin_family=AF_INET;
   Dir.sin_port=0;
   bcopy(dpdir->h_addr,  &Dir.sin_addr, dpdir->h_length); 
   sendto(s, buf,pLen+20,0,(struct sockaddr *)&Dir,sizeof(Dir));
}
 
Example Code (receive):
{
 s = socket(AF_INET, SOCK_RAW,255);
 recv(s,pack,*pLen,0);:
}
 
The problem of using SOCK_RAW is the necessity of put a protocol number (I use 255), and when I want to receive any IP packet, only the packets with this protocol number are received.
 
Anyone knows a solution for receive all IP packets?
 
Thanks for all,
   Isra

Reply via email to