The packet socket in promiscuous mode receives only local traffic

I have a socket created using socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)), and I set it to promiscuous mode using:

struct ifreq ifr;
strncpy((char*)ifr.ifr_name, interface, IF_NAMESIZE);
if(ioctl(sock, SIOCGIFINDEX, &ifr)<0) fail(2);

struct packet_mreq mr;
memset(&mr, 0, sizeof(mr));
mr.mr_ifindex = ifr.ifr_ifindex;
mr.mr_type = PACKET_MR_PROMISC;
if(setsockopt(sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0) fail(2);

The problem is that when I make read()from a socket, it only returns data that goes or comes to my computer.

How can I make it read and process all packets on the network?

Wireshark shows all the packets in order, so I know that this is not my computer or network adapter. ifconfigreports that he PROMISCis when it is running.

+3
source share
4 answers

Wireshark, , . , ( ), .

, . , ioctl(), :

ifr.ifr_flags |= IFF_PROMISC;
if( ioctl(sock, SIOCSIFFLAGS, &ifr) != 0 )
{
    // handle error here
}

, , ifconfig PROMISC .

, .


, . . (- 102) TCP.

+4

SOCK_PACKET socket(), SOCK_RAW.

, , , , . .

+1

, .

, . , . , "", , , . , .

, . , -. , .

, , , , , . , , .

0
source

Source: https://habr.com/ru/post/1715949/


All Articles