Student Student - 1 year ago 106
Linux Question

How to receive bpdu traffic using raw socket in Linux C

How to get packets using

? And how to know is it bdpu traffic?
I read somesource but didn't find listen ethernet traffic.

int data_size, addr_size;
char reply[6000];
struct sockaddr_in addr;

addr_size = sizeof addr;
datasize = recvfrom(sock, reply, 6000, 0, &addr, &addr_size);

printf("nothing recv");



What is this? I don't know.

Answer Source

the reply variable is a pointer to a 6000 byte array. When recvfrom returns, if fills this array with datasize bytes. To see the content, iterate over reply from index 0, until datasize:

    printf("%02x ",reply[i]);

I suggest declaring reply as unsinged char reply[6000].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download