the structure
the structure

Reputation: 89

Raw socket: filter only packets coming from a certain IP address? (Linux C)

I have a C Linux program that uses raw sockets to read incoming tcp/udp packets.

I would like to apply a filter so that only packets sent from a certain IP address reach my socket.

Is it possibile or am I supposed to receive necessarily every packets and then check source address field? I'm a bit concerned about cpu usage in the latter case.

Thank you.

Upvotes: 0

Views: 1248

Answers (1)

Karthik Balaguru
Karthik Balaguru

Reputation: 7842

It also depends on the processor that is being used by you. Some processor have features such as built-in hardware to filter packets based on rules involving input port, source ip address and type of protocol(TCP / UDP / etc..). This in-turn can reduce the load as hardware filtering has better performance than software filtering.

Upvotes: 0

Related Questions