views:

83

answers:

2

Does libpcap get a copy of the packet or the actual packet?

By copy, I mean: the application using libpcap gets packet A, and the kernel also gets packet A.

By actual, I mean: only the application using libpcap gets packet A, but the kernel didn't get it.

+2  A: 

The kernel will get the packet then pass it through a list of filters (for example, there's usually a filter for IPsec, a firewall and so on) and once it's gone through all of these filters, it passes the packet on to the application. libpcap is another filter, but it simply adds the packet to an internal database for processing, rather than inspecting the packet, modifying or whatever else the other filters will do.

For what you want to do, the simplest solution would be to use a firewall.

Dean Harding
+2  A: 

libpcap will not allow you to do what you want. The goal of pcap is to transparently receive a copy of every packet in the system.

You should investigate how to inter-operate with the existing firewall in your system, or how to add your own filters to the netfilter system (on Linux)

Yann Ramin