Socket programming-select + raw_sock

Neena M.S neenams
Thu Jul 28 04:56:50 PDT 2005


Yes.
 We can use select function with raw socket.

An example pgm is attached.



/**********************************************************************************/
/* NAME =  create_raw_socket                              */
/* FUNC =  This function create a raw socket */
/* IN   =  sznetwork_interface_name                           */
/* OUT  =  int                                    */
/* DATE =  09/05/2005                                 */       
/* AUTH =  Neena M.S                                  */ 
*/                                                    
/**********************************************************************************/
int create_raw_socket ( char* sznetwork_interface_name )
{
  int  ioctl_sock,raw_sock=0;
  struct sockaddr_ll addr;
  struct ifreq ifr;

       ioctl_sock = socket ( AF_INET, SOCK_DGRAM, ZERO );
      if ( ioctl_sock < ZERO )
	{
	  CX_LOG("\nFailed to create socket\n");
	 return -1;
	}
        
      /*Create raw socket*/
      raw_sock = socket ( AF_PACKET, SOCK_RAW, htons ( ETH_P_ALL ));
      if ( raw_sock < ZERO )
	{
	  CX_LOG("\nFailed to create socket\n");
	 return -1;
	}

        
      strncpy ( ifr.ifr_name, sznetwork_interface_name, sizeof (
ifr.ifr_name ));
      /*Get the interface index*/
      if ( ioctl ( ioctl_sock, SIOCGIFINDEX, &ifr ) != ZERO ) 
	{
	  CX_LOG ("\nFailed to call ioctl \n");
	  return -1;
	}

      addr.sll_family = AF_PACKET;
      addr.sll_ifindex =  ifr.ifr_ifindex;
        
      /*Bind to the raw socket*/
      if( bind(raw_sock, (struct sockaddr *)&addr, sizeof(addr)) < ZERO ) 
	{
	  CX_LOG("\nFailed to bind \n");
	   return -1;
	}
      return raw_sock;
}

thanks




More information about the Hostap mailing list