title: Socket C - Address family not supported by protocol
body: <p>So I am trying to create a packet sniffer in C. After following the <a href="https://man7.org/linux/man-pages/man7/packet.7.html" rel="nofollow noreferrer">man7 page</a> I inferred that the socket function should look like this</p>
  <pre><code>.....
  int socketfd = socket(AF_PACKET , SOCK_RAW , htons(ETH_P_ALL));
  if(socketfd &lt; 0)
  {
      perror(&quot;Socket Error&quot;);
      return 0;
  }
  .....
  </code></pre>
  <p>And the error is <code>Socket Error: Address family not supported by protocol</code> I looked it up but didn't find a solution to my problem. There is a question that <a href="https://stackoverflow.com/questions/20368832/address-family-not-supported-by-protocol">looks similar</a> but it's not even with the socket syscall. I didn't really try anything else because I didn't find any alternative parameters to put in the function.</p>