title: bad file descriptor in raw socket
body: <p>I become use raw socket and i have this problem:</p>
  
  <p>bad file descriptor</p>
  
  <p>the code is:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;net/if.h&gt;
  #include &lt;unistd.h&gt;
  int main(int argc, char **argv)
  {
  int fd; //file descriptor raw socket
  
  int ioInt;
  
  struct ifreq req; //struttura per la chiamata di ioctl
  
  fd=socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
  
  if(fd==-1) {
  
  
  
  if(errno==EPROTONOSUPPORT)
      perror("socket o protocollo non supportato dal dominio");
  if(errno==EACCES)
      perror("mancano i privilegi per creare il socket");
  if(errno==EINVAL)
      perror("protocollo sconosciuto o dominio non disponibile");
  if(errno==ENOBUFS || errno==ENOMEM)
      perror("memoria non sufficente per la creazione del socket");
  
  }
  
   strncpy (req.ifr_name, "eth0", sizeof(req.ifr_name) - 1);
  
   ioInt=ioctl(fd, SIOCGIFINDEX, &amp;req);
  
   if(ioInt==-1) 
      perror("SIOCGIFINDEX");
  
  return 0;   
  </code></pre>
  
  <p>}</p>
  
  <p>I must access to eth0 and want send e receive a packet in that.  I use linux mint 12</p>