I was looking the most straightforward tutorial on making a tiny network sniffer and found this one. I followed it, but the method advised to sniff packets is:
sock_raw = socket( AF_PACKET , SOCK_RAW , htons(ETH_P_ALL)) ;;
while(1)
{
data_size = recvfrom(sock_raw , buffer , 65536 , 0 , &saddr , &saddr_size);
}
With the rational:
A raw socket when put in recvfrom loop receives all incoming packets. This is because it is not bound to a particular address or port.
It seemed to me that this would only monitor network traffic coming in and out of my own computer, and not the whole LAN. A test-run confirmed my intuition.
Is it correct? Can this method only sniff packets coming in and out of my laptop?
Which approach should I take to sniff all network traffic (ie: netsniff-ng, Wireshark)?
I want to avoid using libpcap in this case.