title: recv with raw socket
body: <p>I am trying to recv raw packets from socket and failed. Message is printing only while sending packets on server site. When no packets are transferred - program hungs in recv (socket in synchronous mode).</p>
  
  <p>The problem is that printing message is "buffer" but without received data.</p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;linux/if_packet.h&gt;
  #include &lt;linux/if_ether.h&gt;
  #include &lt;linux/if_arp.h&gt;
  
  #define ETH_FRAME_LEN 1400
  
  int main(){
  
      int s; /*socketdescriptor*/
  
      s = socket(PF_PACKET, SOCK_RAW, htons(0x88b5));
      if (s == -1) { perror("socket"); }
  
          struct sockaddr_ll socket_address;
      int r;
      char ifName[IFNAMSIZ] = "eth0";
  
      struct ifreq ifr;  
          strncpy((char *)ifr.ifr_name ,device , IFNAMSIZ); 
  
      /* Get the index of the interface to send on */
      memset(&amp;if_idx, 0, sizeof(struct ifreq));
      strncpy(if_idx.ifr_name, ifName, IFNAMSIZ-1);
      if (ioctl(sockfd, SIOCGIFINDEX, &amp;if_idx) &lt; 0)
          perror("SIOCGIFINDEX");
  
      /* Get the MAC address of the interface to send on */   
      memset(&amp;if_mac, 0, sizeof(struct ifreq));
      strncpy(if_mac.ifr_name, ifName, IFNAMSIZ-1);
      if (ioctl(sockfd, SIOCGIFHWADDR, &amp;if_mac) &lt; 0)
          perror("SIOCGIFHWADDR");
  
          memset(&amp;socket_address, 0, sizeof(socket_address));
          socket_address.sll_ifindex = ifr.if_idx;
          socket_address.sll_protocol = htons(0x88b5);
          socket_address.sll_family = PF_PACKET;
          socket_address.sll_pkttype = PACKET_OUTGOING;
  
          r = bind(s, (struct sockaddr*)&amp;socket_address,
                      sizeof(socket_address));
      if ( r &lt; 0) { perror("bind")};
  
      void* buffer = (void*)malloc(ETH_FRAME_LEN); /*Buffer for ethernet frame*/
      int length = 0; /*length of the received frame*/ 
  
      length = recv(s, buffer, ETH_FRAME_LEN, 0,);
      if (length == -1) { perror("recvfrom"); }
      printf ("buffer %s\n", buffer);
  
  }
  </code></pre>