Blame doc/README.linux.md

Packit Service c0f7c7
In order for libpcap to be able to capture packets on a Linux system,
Packit Service c0f7c7
the "packet" protocol must be supported by your kernel.  If it is not,
Packit Service c0f7c7
you may get error messages such as
Packit Service c0f7c7
Packit Service c0f7c7
	modprobe: can't locate module net-pf-17
Packit Service c0f7c7
Packit Service c0f7c7
in "/var/adm/messages", or may get messages such as
Packit Service c0f7c7
Packit Service c0f7c7
	socket: Address family not supported by protocol
Packit Service c0f7c7
Packit Service c0f7c7
from applications using libpcap.
Packit Service c0f7c7
Packit Service c0f7c7
You must configure the kernel with the CONFIG_PACKET option for this
Packit Service c0f7c7
protocol; the following note is from the Linux "Configure.help" file for
Packit Service c0f7c7
the 2.0[.x] kernel:
Packit Service c0f7c7
Packit Service c0f7c7
	Packet socket
Packit Service c0f7c7
	CONFIG_PACKET
Packit Service c0f7c7
	  The Packet protocol is used by applications which communicate
Packit Service c0f7c7
	  directly with network devices without an intermediate network
Packit Service c0f7c7
	  protocol implemented in the kernel, e.g. tcpdump. If you want them
Packit Service c0f7c7
	  to work, choose Y.
Packit Service c0f7c7
Packit Service c0f7c7
	  This driver is also available as a module called af_packet.o ( =
Packit Service c0f7c7
	  code which can be inserted in and removed from the running kernel
Packit Service c0f7c7
	  whenever you want). If you want to compile it as a module, say M
Packit Service c0f7c7
	  here and read Documentation/modules.txt; if you use modprobe or
Packit Service c0f7c7
	  kmod, you may also want to add "alias net-pf-17 af_packet" to
Packit Service c0f7c7
	  /etc/modules.conf.
Packit Service c0f7c7
Packit Service c0f7c7
and the note for the 2.2[.x] kernel says:
Packit Service c0f7c7
Packit Service c0f7c7
	Packet socket
Packit Service c0f7c7
	CONFIG_PACKET
Packit Service c0f7c7
	  The Packet protocol is used by applications which communicate
Packit Service c0f7c7
	  directly with network devices without an intermediate network
Packit Service c0f7c7
	  protocol implemented in the kernel, e.g. tcpdump. If you want them
Packit Service c0f7c7
	  to work, choose Y. This driver is also available as a module called
Packit Service c0f7c7
	  af_packet.o ( = code which can be inserted in and removed from the
Packit Service c0f7c7
	  running kernel whenever you want). If you want to compile it as a
Packit Service c0f7c7
	  module, say M here and read Documentation/modules.txt.  You will
Packit Service c0f7c7
	  need to add 'alias net-pf-17 af_packet' to your /etc/conf.modules
Packit Service c0f7c7
	  file for the module version to function automatically.  If unsure,
Packit Service c0f7c7
	  say Y.
Packit Service c0f7c7
Packit Service c0f7c7
In addition, there is an option that, in 2.2 and later kernels, will
Packit Service c0f7c7
allow packet capture filters specified to programs such as tcpdump to be
Packit Service c0f7c7
executed in the kernel, so that packets that don't pass the filter won't
Packit Service c0f7c7
be copied from the kernel to the program, rather than having all packets
Packit Service c0f7c7
copied to the program and libpcap doing the filtering in user mode.
Packit Service c0f7c7
Packit Service c0f7c7
Copying packets from the kernel to the program consumes a significant
Packit Service c0f7c7
amount of CPU, so filtering in the kernel can reduce the overhead of
Packit Service c0f7c7
capturing packets if a filter has been specified that discards a
Packit Service c0f7c7
significant number of packets.  (If no filter is specified, it makes no
Packit Service c0f7c7
difference whether the filtering isn't performed in the kernel or isn't
Packit Service c0f7c7
performed in user mode. :-))
Packit Service c0f7c7
Packit Service c0f7c7
The option for this is the CONFIG_FILTER option; the "Configure.help"
Packit Service c0f7c7
file says:
Packit Service c0f7c7
Packit Service c0f7c7
	Socket filtering
Packit Service c0f7c7
	CONFIG_FILTER
Packit Service c0f7c7
	  The Linux Socket Filter is derived from the Berkeley Packet Filter.
Packit Service c0f7c7
	  If you say Y here, user-space programs can attach a filter to any
Packit Service c0f7c7
	  socket and thereby tell the kernel that it should allow or disallow
Packit Service c0f7c7
	  certain types of data to get through the socket. Linux Socket
Packit Service c0f7c7
	  Filtering works on all socket types except TCP for now. See the text
Packit Service c0f7c7
	  file linux/Documentation/networking/filter.txt for more information.
Packit Service c0f7c7
	  If unsure, say N.
Packit Service c0f7c7
Packit Service c0f7c7
Note that, by default, libpcap will, if libnl is present, build with it;
Packit Service c0f7c7
it uses libnl to support monitor mode on mac80211 devices.  There is a
Packit Service c0f7c7
configuration option to disable building with libnl, but, if that option
Packit Service c0f7c7
is chosen, the monitor-mode APIs (as used by tcpdump's "-I" flag, and as
Packit Service c0f7c7
will probably be used by other applications in the future) won't work
Packit Service c0f7c7
properly on mac80211 devices.
Packit Service c0f7c7
Packit Service c0f7c7
Linux's run-time linker allows shared libraries to be linked with other
Packit Service c0f7c7
shared libraries, which means that if an older version of a shared
Packit Service c0f7c7
library doesn't require routines from some other shared library, and a
Packit Service c0f7c7
later version of the shared library does require those routines, the
Packit Service c0f7c7
later version of the shared library can be linked with that other shared
Packit Service c0f7c7
library and, if it's otherwise binary-compatible with the older version,
Packit Service c0f7c7
can replace that older version without breaking applications built with
Packit Service c0f7c7
the older version, and without breaking configure scripts or the build
Packit Service c0f7c7
procedure for applications whose configure script doesn't use the
Packit Service c0f7c7
pcap-config script if they build with the shared library.  (The build
Packit Service c0f7c7
procedure for applications whose configure scripts use the pcap-config
Packit Service c0f7c7
script if present will not break even if they build with the static
Packit Service c0f7c7
library.)
Packit Service c0f7c7
Packit Service c0f7c7
Statistics:
Packit Service c0f7c7
Statistics reported by pcap are platform specific.  The statistics
Packit Service c0f7c7
reported by pcap_stats on Linux are as follows:
Packit Service c0f7c7
Packit Service c0f7c7
2.2.x
Packit Service c0f7c7
=====
Packit Service c0f7c7
ps_recv   Number of packets that were accepted by the pcap filter
Packit Service c0f7c7
ps_drop   Always 0, this statistic is not gathered on this platform
Packit Service c0f7c7
Packit Service c0f7c7
2.4.x and later
Packit Service c0f7c7
=====
Packit Service c0f7c7
ps_recv   Number of packets that were accepted by the pcap filter
Packit Service c0f7c7
ps_drop   Number of packets that had passed filtering but were not
Packit Service c0f7c7
          passed on to pcap due to things like buffer shortage, etc.
Packit Service c0f7c7
          This is useful because these are packets you are interested in
Packit Service c0f7c7
          but won't be reported by, for example, tcpdump output.