maed
maed

Reputation: 1

C RAW socket communication with custom ETH type

So I have two userspace applications (lets say app A and B) running on linux 2.6 kernel.

app A sends raw packet with a custom ethernet type (ETH_FOO) using the socket below

socket(PF_PACKET, SOCK_RAW, htons(ETH_FOO));

if app B opens a raw socket with ETH_P_ALL and listens to all interfaces without binding, it can successfully receive pkts sent by A with type ETH_FOO.

But if B opens the socket with type ETH_FOO, no packet is observed. I just want to capture ETH_FOO pkts. What may be the problem?

This is my first question here. Pardon my mistakes if there is any. Also I can not copy the entire code since it's not mine and somewhat propriatery.

Upvotes: 0

Views: 489

Answers (1)

Iñaki Idigoras
Iñaki Idigoras

Reputation: 21

When you use ETH_P_ALL, you are listening all packets, both ingoing and outgoing.

If you are in the same machine, using the same network interface, when you send a packet, there is no ingoing packet. Using ETH_P_ALL will get you the outgoing packet.

When you specify other value than ETH_P_ALL, only incoming packets are listened to. And you get nothing if using the Ethernet interface in the same machine.

You have two options here:

  • use different machines
  • in the same machine, use the loopback adapter (which creates an ingoing packet for every outgoing packet). The loopback adapter is listed together with the Ethernet adapter when you type ip a.

It took me some time to learn this, and I did it here, where you can learn a bit more.

Upvotes: 1

Related Questions