1

So I am trying to create a packet sniffer in C. After following the man7 page I inferred that the socket function should look like this

.....
int socketfd = socket(AF_PACKET , SOCK_RAW , htons(ETH_P_ALL));
if(socketfd < 0)
{
    perror("Socket Error");
    return 0;
}
.....

And the error is Socket Error: Address family not supported by protocol I looked it up but didn't find a solution to my problem. There is a question that looks similar 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.

Patch
  • 694
  • 1
  • 10
  • 29
  • 1
    Which platform are you targetting? Not all platforms support `AF_PACKET`. Is there a reason why you are writing a sniffer using a RAW socket and not an actual sniffing library, like libpcap? – Remy Lebeau Sep 24 '20 at 20:24
  • What do you mean by "platform" – Patch Sep 24 '20 at 20:26
  • 1
    By platform, I mean OS. Windows, Unix/Linux (which distro?), etc. – Remy Lebeau Sep 24 '20 at 20:27
  • @RemyLebeau ubuntu to compile the program (GCC). It is a WSL if it matters . The OS is windows. – Patch Sep 24 '20 at 20:28
  • 3
    WSL stands for "Windows Subsystem for Linux", so you are trying to run a Linux app on Windows? Per https://www.tutorialspoint.com/run-linux-natively-on-windows-10: "***WSL does not support AF_PACKET** for security restrictions. This means that you won't be able to put a Wi-Fi adapter in promiscuous mode (or monitor mode), and tools that require raw sockets to function properly won't work, such as Nmap.*" – Remy Lebeau Sep 24 '20 at 20:30
  • 1
    If you google "WSL AF_PACKET" the only results you will see will state something like "WSL is not supporting AF_PACKET" – Eugene Sh. Sep 24 '20 at 20:30

0 Answers0