dect
/
libpcap
Archived
13
0
Fork 0
Commit Graph

202 Commits

Author SHA1 Message Date
guy c166082296 From Mike "Dragorn" Kershaw: add support for the new ARPHRD_ value for
802.11 with a radiotap header (used by the madwifi driver, and in the
pipeline to be officially assigned).
2005-08-16 04:18:32 +00:00
guy 75b14d240d OK, we'll be putting out 0.9.2 soon, so add the API changes back in
again.
2005-07-07 01:57:00 +00:00
guy 5e92dec088 0.9's already been released, so, for better or worse, we're stuck with
the old names.
2005-07-05 22:31:57 +00:00
guy 727beef298 Rename "direction_t" to "pcap_direction_t", and rename "D_IN" and
"D_OUT" to "PCAP_D_IN" and "PCAP_D_OUT", to avoid potential namespace
collisions, as per a suggestion by Dean Gaudet.
2005-07-05 22:12:17 +00:00
guy a0a4852137 From Gilbert Hoyek <gil_hoyek@hotmail.com>: support for capturing SS7
traffic on Intel Septel cards, and for filtering on SS7 MTP3 fields.

Clean up indentation.
2005-06-20 21:27:07 +00:00
guy e987a615e2 From Pawel Pokrywka: add support for requesting that only received
packets, only sent packets, or all packets be accepted, with an
implementation for Linux.

Add an implementation for BPF platforms that support BIOCSSEESENT.
2005-05-03 18:53:58 +00:00
guy e5aebee6d8 Add a "pcap_close_common()" routine which can be used as the close
routine for some pcap-XXX.c files and can be called by the close routine
in other pcap-XXX.c files.
2004-10-19 07:06:11 +00:00
guy c56022ef76 Not all Linuxes define ARPHRD_IRDA; define it if it's not defined. 2004-09-06 01:23:17 +00:00
guy 841b1f7f77 As per Mark Pizzolato, "sendto()" isn't necessary for sending packets,
at least on 2.2 and later kernels; the socket is bound (except for
sending on the "any" device, which we don't support), so a destination
address isn't necessary.

Generate the right error string for attempts to send on the "any"
device, and also disallow sends if we're in cooked mode.
2004-04-07 08:03:32 +00:00
guy 5f9f6317d2 Fixes from Mark Pizzolato. 2004-03-24 06:49:16 +00:00
guy 2d2890dd37 Add support for sending packets; includes contributions from Mark
Pizzolato <List-tcpdump-workers@subscriptions.pizzolato.net>.
2004-03-23 19:18:04 +00:00
guy 1924b620dc Don't use a static variable for the accumulated statistics, accumulate
the statistics in "handle->md.stat", so that the statistics are
maintained correctly if more than one pcap_t is in use.
2004-01-14 01:56:10 +00:00
hannes f2101dbb5d patch from Erik de Castro Lopo <erik.de.castro.lopo@sensorynetworks.com>:
In the Linux kernel the packet statistics are zeroed during each retrieval.
  In contrast, on FreeBSD, the packet statistics are retrived using
  ioctl(BIOCGSTATS):

  The patch adds a static variable to pcap_stats_linux() which
  holds a running total of the packet statistics so that the behaviour
  of pcap_stats() on Linux matches the behaviour of FreeBSD.
2004-01-02 11:25:26 +00:00
guy 619a9fe31b For devices that we have some reason to believe are real live Ethernet
devices, offer DLT_DOCSIS as one of the choices of link-layer type, and
support setting that type as meaning just "set libpcap's notion of the
link-layer type to DLT_DOCSIS" without telling the driver to use
DLT_DOCSIS.
2003-12-18 23:32:31 +00:00
guy c98ffbcabf Add a "pcap_get_selectable_fd()" API to get an FD on which you can do a
"select()" or "poll()" - or -1 if that won't work.
2003-11-21 10:19:33 +00:00
guy 2c618b93a0 Add "getnonblock" and "setnonblock" operations, and set the function
pointers appropriately, rather than using #ifdefs and run-time checks.

Get rid of declaration of non-existent "pcap_set_datalink_platform()"
routine.
2003-11-20 02:02:38 +00:00
guy a08248f680 From Jean Tourrilhes <jean2@sourceforge.net>: IrDA capture support for
Linux.
2003-11-18 21:06:50 +00:00
guy 30e89f192a Add _U_ to "rcsid[]" definitions, to eliminate "unused variable"
warnings from newer versions of GCC.
2003-11-15 23:23:57 +00:00
guy 4a0eb92022 From Jesper Peterson: fix a cut-and-pasteo (the Linux libpcap code calls
its pcap_t pointer "handle", not "p", unlike most other libpcap code).
2003-11-05 04:25:24 +00:00
guy 991d444f71 Add a "pcap_breakloop()" API to break out of the loop in
"pcap_dispatch()" and "pcap_loop()".
2003-11-04 07:05:32 +00:00
guy 00f79e19a4 From Krzysztof Halasa <khc@pm.waw.pl>:
support Linux Frame Relay ARPHRD_FRAD as Frame Relay with an FR
	header;

	support Linux Frame Relay ARPHRD_DLCI in cooked mode;

	current Linux kernels use the name ARPHRD_CISCO for Cisco HDLC
	(513).
2003-10-06 07:04:55 +00:00
guy cd0d893ef9 Add a "read" function pointer to the pcap_t structure, which handles
reading packets from a pcap_t, and make "pcap_read()" call it.  That
removes the last place where we have to check for a pcap_t that refers
to a DAG card rather than a live capture, so get rid of the "is_dag" flag.
2003-07-25 05:32:02 +00:00
guy 08658f1c93 Add a "set_datalink" function pointer to the pcap_t structure, whichhandles
setting a filter for a pcap_t.  Have "pcap_set_datalink()" call it,
rather than explicitly calling "pcap_set_datalink_platform()".
2003-07-25 05:07:01 +00:00
guy cd2807e08d Add a "setfilter" function pointer to the pcap_t structure, which
handles setting a filter for a pcap_t.  Have "pcap_setfilter()" call it,
rather than being a per-platform function.  The per-platform functions
don't need to check for an offline capture any more, as they're not
called for an offline capture (and the ones that just call
"install_bpf_program()" don't need to exist at all).
2003-07-25 04:42:02 +00:00
guy 9792990eb8 Add a "stats" function pointer to the pcap_t structure, which handles
getting statistics for a pcap_t.  Have "pcap_stats()" call it, rather
than being a per-platform function; have stats routines for non-live
pcap_t's that return an error.
2003-07-25 04:04:56 +00:00
guy e648c9e593 Add a "close" function pointer to the pcap_t structure, which handles
the platform-dependent part of closing a pcap_t (and the
live-vs-savefile part as well, so that function must close the file
descriptor and free up any buffers allocated).

In the Digital UNIX support, add in a check for a memory allocation
failure.
2003-07-25 03:25:45 +00:00
guy 77cade932c From Jesper Peterson <jesper@endace.com>: support for capturing from
Endace DAG devices.
2003-07-23 05:29:19 +00:00
guy b3833482d0 Don't turn allmulti mode on if "promisc" isn't set; that causes problems
with some interfaces (see bug 599857 in the SourceForge list of libpcap
bugs), and, even if it doesn't cause problems, it's different from
what's done on other platforms.
2003-04-09 07:19:49 +00:00
guy 2d1ac3b4d5 From Peter Fales <peter@fales-lorenz.net>: support for Linux ARCNET,
which supplies different headers from BSD ARCNET, and fixes to the
ARCNET code generator (the protocol ID field is 1 byte, so the values
for it shouldn't be byte-swapped).

Whitespace cleanups.

The "NetBSD-style" ARCNET headers are used in other BSDs as well, so
just call them "BSD-style".
2003-01-23 07:24:51 +00:00
guy 8cd68a0fa4 From Yoann Vandoorselaere <yoann@prelude-ids.org>: make the "device"
argument to "pcap_open_live()" a "const" pointer.

Constify some additional device name arguments, and update the man page
to reflect some arguments that were already consts.
2002-12-22 02:36:48 +00:00
guy 482fa426bc NetBSD support for multiple data link types on an interface, from David
Young <dyoung@ojctech.com>, with some minor changes by Jason R.  Thorpe
<thorpej@netbsd.org>, and further changes by me to support it on BPF
systems lacking BIOCGDLTLIST and other platforms lacking an equivalent
feature.

Update Jason Thorpe's e-mail address (Zembu is going away, if it hasn't
done so already).

Add APIs to map DLT names to DLT values and vice versa.
2002-12-19 09:05:45 +00:00
guy d1d0fe1d98 Add support for RFC 2625 IP-over-Fibre Channel, mapping all the Linux
ARPHRD_FC* types to it.
2002-10-18 08:46:13 +00:00
guy 9e6fbe3b4b Cut-and-pasteo fix, from Greg Stark <gsstark@mit.edu>. 2002-07-12 07:51:15 +00:00
guy 243b20ec55 Add SunATM support, based on code from Yen Yen Lim at North Dakota State
University.
2002-07-11 09:06:30 +00:00
guy 541d54330f Isn't Linux fun? You might have a distribution whose kernel is a shiny
new 2.2-or-later kernel, with PF_PACKET sockets including SOL_PACKET,
but with an older version of the C library whose headers don't define
SOL_PACKET.

On those systems, define SOL_PACKET to have the value it has in the
2.2.0 kernel; this means we can get rid of the "#ifdef
SOL_PACKET"/#endif stuff wrapped around the code to turn promiscuous
mode on or off (we don't want that #ifdeffed out, as if it's absent we
won't pay attention to the "promiscuous mode" flag argument to
"pcap_open_live()").
2002-07-06 21:22:35 +00:00
itojun 5918c491c1 whitespace cleanup 2002-06-11 17:04:44 +00:00
guy c26a724029 Fix white space. 2002-06-01 09:36:26 +00:00
guy a579c1219c Support for ARPHRD_RAWHDLC, as used by, for example, the Cyclades PC300
synchronous board in Raw HDLC mode, from Octavian Cerna
<tavy@ylabs.com>.
2002-03-07 11:27:57 +00:00
guy 6c3ce3a573 Bug fixes from Graeme Hewson <ghewson@cix.compulink.co.uk>:
1. During termination processing set up by atexit() under a 2.0.x
   kernel, if a socket had been previously closed and the handle freed
   due to an error, pcap_close_all() and pcap_close_linux() would
   nevertheless try to work with these structures and then crash.
   pcap_close_linux() is now called directly when necessary during
   error processing.

2. atexit() could get called more than once because the did_atexit
   flag wasn't being set.

3. If iface_get_arptype() returns an error because the ioctl() call
   failed (probably due to "no such device"), live_open_new() now
   returns a fatal error to pcap_open_live() and the call to
   live_open_old() is short-circuited.

4. Applications using libpcap would appear to listen on an interface
   that was down.

   a. iface_bind() and iface_bind_old() now check for pending errors
      after bind().  In turn, pcap_open_live() now returns an error
      status if there was a pending error after bind().

   b. After draining the socket, set_kernel_filter() now checks to see
      if the error was the expected EAGAIN and returns a fatal error
      to pcap_setfilter() if not.  In turn, pcap_setfilter() now
      returns an error status if there was a network error.

5. pcap_setfilter() was putting an error message into errbuf after a
   failed call to install_bpf_program().  This was unnecessary since
   install_bpf_program() puts its own error message into errbuf.
2002-02-22 09:20:11 +00:00
guy bb0918aeef Have "map_arphrd_to_dlt()" take a flag indicating whether it's OK to
return DLT_LINUX_SLL or not, and, if that flag is false, for those
interface types where we'd used DLT_LINUX_SLL, pick a DLT_ type that
works as well as possible in raw mode, or fail.

Pass 1 as that flag if we're using a PF_PACKET socket; pass 0 as that
flag if we're using a PF_INET/SOCK_PACKET socket.

For PF_INET/SOCK_PACKET sockets, try to get the link-layer type and map
it to a DLT_ value *before* turning promiscuous mode on, so that we
don't try to put the interface into promiscuous mode unless we know we
can handle its link-layer type (and thus that we can use the interface).
2002-02-10 00:05:14 +00:00
guy e1f3b3be1a From Solomon Peachy <pizza@shaftnet.org>: Linux 2.4.18pre4 defines
ARPHRD_IEEE80211_PRISM, for sniffing on Prism II-based 802.11 interfaces
and getting the special Prism header, so we should map it to
DLT_PRISM_HEADER.
2002-02-05 05:47:14 +00:00
guy 9f5a39497e Fix a typo in a comment. 2002-02-03 23:03:42 +00:00
guy fcfc446231 From Jan-Philip Velders <jpv@veldersjes.net>: Linux 2.0[.x] kernels
didn't define ARPHRD_HDLC - define it as per Linux 2.1.13, if it's not
defined.

Do the same with ARPHRD_FDDI, as that's not defined by 2.0, either.
2002-02-03 23:02:07 +00:00
guy efc02fd2e3 Put more information into the comments for "pcap_stats()". 2001-12-10 07:14:14 +00:00
guy 1a00bc6928 Fixes from Phil Wood:
Don't subtract "tp_drops" from "tp_packets" - "ps_recv", on BSD,
	at least, includes packets dropped due to lack of buffer space,
	so it should do so on Linux as well.

	The "len" argument to "getsockopt()" is a value-result
	parameter, initially containing the size of the buffer being
	supplied; set it before the call.

	Catch "getsockopt()" errors and, if it's an error other than
	EOPNOTSUPP, return an error.
2001-12-10 05:49:40 +00:00
guy c3736d4ff8 When using SOCK_PACKET sockets, which don't support cooked mode, reject
any link-layer types that would get mapped to cooked mode.
2001-10-25 18:09:59 +00:00
guy bc61a9fd37 We weren't returning a warning if the interface had an ARPHRD_ type we
didn't handle; fix the code to do so.

Remove the word "Warning" from the warning - tcpdump will add it when it
prints the warning, as will Ethereal and Tethereal.
2001-10-25 08:27:18 +00:00
guy 03c414f542 Don't print the warning for an ARP type not supported by libpcap, return
it in the error message buffer, as is done for warnings in other
implementations of "pcap_open_live()".
2001-10-25 06:46:14 +00:00
guy 9c0a593a2e From Scott Gifford:
Add a new "pcap_findalldevs()" routine to get a list of all
	interfaces that can be opened with "pcap_open_live()", and a
	"pcap_freealldevs()" routine to free the list.

	Make "pcap_lookupdev()" use it, which also arranges that it will
	not return a device that cannot be opened by "pcap_open_live()".

	Allow the "any" device to be opened, on Linux, with "promisc"
	non-zero; ignore the request for promiscuity, and return a
	warning message indicating that promiscuous mode isn't supported
	on the "any" device.

Document "pcap_findalldevs()" and "pcap_lookupdev()", and clean up some
items in the libpcap man page.
2001-10-08 01:06:20 +00:00
guy 2de302a362 ARPHRD_ARP doesn't uniquely specify the header that will appear on
packets before the network-layer header; we already deal with that in
tcpdump, and we could probably try to deal with that in the code
generator, but it's less of a pain to just punt to DLT_LINUX_SLL.
2001-09-23 22:43:57 +00:00
guy 545afab583 Changes from Pavel Kankovsky to reset the kernel filter in
"pcap_setfilter()" if we're not using a kernel filter, in case a
previous call to "pcap_setfilter()" had succeeded in adding a kernel
filter, as if we're doing userland filtering we need to get rid of all
kernel filters that might discard packets that'd pass the userland
filter.
2001-08-30 03:08:43 +00:00
guy cec0453730 Patch, based on a patch from Pavel Kankovsky <kan@dcit.cz>, to flush all
packets queued up on the socket when we set a kernel filter on the
socket, so that if there are any queue-up packets that wouldn't have
passed the new filter, we don't see them.  (Some other packet capture
mechanisms do this automatically; this prevents tcpdump, for example,
from showing or saving, when run with a filter, some packets that
wouldn't have passed the filter.)

XXX - do we have to do this on any other platforms?

Choose whether to compile in the code to modify filter programs for use
in the kernel, and to flush queued-up packet and set a kernel filter, on
whether SO_ATTACH_FILTER is defined (i.e., on whether we have kernel
filter support in our build environment), rather than on whether
HAVE_PF_PACKET_SOCKETS is defined (i.e., on whether we have PF_PACKET
support in our build environment), as we choose whether to *use* that
code based on whether SO_ATTACH_FILTER is defined.
2001-08-25 05:08:26 +00:00
guy 96943e6868 In "pcap_read_packet()", always use "handle->buffer + handle->offset" as
the pointer to the beginning of the link-layer header; never use just
"handle->buffer", as, if "handle->offset" is non-zero (as is the case
with many link-layer types, including Ethernet), "handle->buffer"
doesn't point to the beginning of the link-layer header.
2001-08-24 09:27:14 +00:00
guy 8d039ab3b6 Define MSG_TRUNC as 0x20 if it's not defined, so that if this is
compiled on a system that doesn't have it, it'll use it on systems that
do have it.

On systems with MSG_TRUNC support (i.e., 2.2 and later kernels), there's
no need to read in the entire packet in order to find out how large it
is, so just allocate a buffer big enough for a snapshot length's worth
of data, and just read that much data.

There's no need for a "readlen" member of the "pcap_md" structure, as
the byte count to "recvfrom()" is just the "bufsize" member of the
"pcap_t" structure.
2001-08-24 07:46:52 +00:00
guy 626de160d6 Move the code to allocate the packet buffer into "pcap_open_live()", so
that we don't have almost-duplicate code in "live_open_old()" and
"live_open_new()".  This fixes a bug wherein "live_open_new()" wasn't
making the buffer size the maximum of "enough to hold packets of the MTU
obtained from the socket" and "the snapshot length" (for some reason,
"recvfrom()" was copying more data than the MTU obtained from the
socket).
2001-08-23 16:36:41 +00:00
guy 380a3dbf49 From Scott Barron <sb125499@ohiou.edu>: use the
SOL_PACKET/PACKET_STATISTICS "getsockopt()" call, on Linux kernels that
support it, to get packet statistics, so that we can report the number
of dropped packets, and always use <linux/if_packet.h> to get
definitions for PF_PACKET sockets, so that we don't depend on glibc's
header files having been updated to support all the latest shiniest
kernel features (many systems with 2.4[.x] kernels don't have a
<netpacket/packet.h> that defines "struct tpacket_stats", for example,
so we wouldn't have been able to support that kernel feature on those
systems).
2001-07-29 18:25:46 +00:00
guy 11c1cf8ee2 Add comments to "pcap_stats()" indicating what the counters mean on the
various platforms (assuming the vendors' documentation is correct and
that I've correctly interpreted it).
2001-07-29 01:22:40 +00:00
guy 77d52cac81 Support for LocalTalk hardware, from Uns Lider <unslider@miranda.org>. 2001-06-18 08:46:28 +00:00
guy 6cd32e5cef 802.11 support, from Javier Achirica <achirica@ttd.net>. 2001-06-10 01:11:39 +00:00
guy 5f649f110e Patch from Marcus Felipe Pereira <marcus@task.com.br> to map ARPHRD_HDLC
to DLT_C_HDLC.

Arrange that if "map_arphrd_to_dlt()" supplies DLT_LINUX_SLL as the
link-layer DLT_ value, we capture in cooked mode.

Return DLT_LINUX_SLL for ARPHRD_PPP, as some PPP code in the kernel
supplies no link-layer header whatsoever to PF_PACKET sockets, other PPP
code supplies PPP link-layer headers ("syncppp.c"), and PPP-over-ISDN
appears to supply random link-layer headers (there's code in Ethereal,
for example, to cope with PPP-over-ISDN captures with which the Ethereal
developers have had to cope, heuristically trying to determine which of
the oddball link-layer headers particular packets have).
2001-04-09 05:55:39 +00:00
guy 534381a041 Attempt to put the link-layer payload of packets on a 4-byte boundary,
as is done in some other "pcap-XXX.c" modules.
2001-03-20 05:50:33 +00:00
guy a6e177c611 Patch from Igor Khristophorov <igor@atdot.org> to handle adaptive SLIP
interfaces on Linux just like standard SLIP interfaces.
2001-01-20 07:47:53 +00:00
guy 952a563412 Some platforms that lack <netpacket/packet.h> define PF_PACKET but don't
support PF_PACKET sockets, and, in particular, don't define in
<linux/if_packet.h> any of the stuff needed by the code to handle
PF_PACKET sockets.  Define HAVE_PF_PACKET_SOCKETS if either

	1) we have <netpacket/packet.h>

or

	2) PF_PACKET is defined *and* PACKET_HOST is defined by
	   <linux/if_packet.h>

and use HAVE_PF_PACKET_SOCKETS, not PF_PACKET, be what we use in #ifdefs
to conditionally compile in support for PF_PACKET sockets.

Not all platforms define ARPHRD_SIT, either; #define it if it's not
already defined.
2001-01-18 03:58:22 +00:00
guy 9c3650645f At least some libc5 systems don't have <netinet/if_ether.h> but do have
<net/if_arp.h>, and the stuff we want is in <net/if_arp.h>, so include
that rather than <netinet/if_ether.h>.

At least some libc5 systems don't have <netpacket/packet.h>, but have a
<sys/socket.h> that includes <linux/socket.h>, and the latter defines
SO_ATTACH_FILTER if the kernel is a 2.2 or later kernel, so there exist
systems that have SO_ATTACH_FILTER defined but don't have
<netpacket/packet.h>.  Work around that by:

	checking whether we have PF_PACKET sockets by checking whether
	PF_PACKET is defined, not whether we have <netpacket/packet.h>
	(but we still check whether we have <netpacket/packet.h> before
	including it);

	if PF_PACKET is defined but we don't have <netpacket/packet.h>,
	include <linux/if_packet.h> to get the relevant definitions.
2001-01-17 07:42:37 +00:00
guy c3c2ed00d5 Generate code to check for LLC SAP values on Linux cooked captures.
Set "off_linktype" to the correct value for the offset of the Ethernet
type field in the fake header for Linux cooked captures, so that the
correct code is generated for tests of that field.
2001-01-14 05:30:07 +00:00
guy 60ac80bd7a Remove the "select()" from the code path for reading live captures on
Linux; Linux isn't the only platform whose kernel doesn't support a
read timeout, and even some that *do* don't start the timer until at
least one packet has arrived (Solaris, for example), so no portable
application can depend on "pcap_dispatch()", say, blocking for no longer
than the timeout - they must do a "select()" themselves.  For
applications that do the "select()" themselves, or that don't need the
timeout for polling (tcpdump, for example), doing a "select()" in
libpcap just adds another system call to the code path.
2001-01-03 01:06:16 +00:00
guy 7574015989 It's a bit more convenient for Ethereal if the "sll_protocol" field is
at the end of the link-layer header; put it there.

Put in a comment indicating that the layout of the link-layer header
shouldn't be changed; if a new header is necessary, a new DLL_ type
should be introduced for it.
2000-12-23 07:50:18 +00:00
guy 5d92f34251 Fix a typo. 2000-12-23 03:04:06 +00:00
guy a4af073aa0 Check for "ippp" devices, as well as "isdn" and "isdY" devices, when
deciding whether to punt to cooked mode.
2000-12-22 12:30:04 +00:00
guy 54b14dde63 Just copy over the "sll_protocol" field - if it's not an Ethernet type,
we just treat the frame as an LLC frame (if we care about Novell
IPX-over-raw-802.3 frames, we'd have to handle them by checking for
0xFFFF as the first word - but we'd also have to do that when dissecting
Ethernet frames).
2000-12-22 12:24:20 +00:00
guy cf54e028ce Explicitly map PACKET_ values to LINUX_SLL_ values, so that even if a
future Linux kernel changes the PACKET_ values out from under us, the
values recorded in the packet header in DLT_LINUX_SLL captures does
*not* change.

Don't map ETH_P_802_2 to the packet length, map it and ETH_P_802_3 to
standardized LINUX_SLL_P_ values, so that even if a future Linux kernel
changes the ETH_P_ values out from under us, the values recorded in the
packet header in DLT_LINUX_SLL captures does *not* change, and so that
you don't have to be running on Linux to be able to handle DLT_LINUX_SLL
captures.
2000-12-22 12:11:36 +00:00
guy 4ee46797c7 Patch from Olaf Kirch to add support for ARPHRD_TUNNEL (or at least for
some tunnels).
2000-12-22 11:53:27 +00:00
guy 5b0a98d641 Add support for a new link layer type DLT_LINUX_SLL, for use when doing
live captures with a "cooked" (SOCK_DGRAM) rather than a "raw"
(SOCK_RAW) PF_PACKET socket; it includes a bunch of the fields from the
"struct sockaddr_ll" you get in a "recvfrom()", including the Ethernet
protocol field.

This requires us to rewrite the BPF program if we're stuffing it into
the kernel; as long as we're doing *ex post facto* rewriting, we might
as well also do the "ret <snaplen>" -> "ret 65535" fixup there as well,
rather than in the code generator.
2000-12-21 10:29:21 +00:00
guy 6fc6ca1eb5 Improve the error message printed if you try to use the "any" device on
a system where only SOCK_PACKET works.
2000-12-18 00:20:51 +00:00
guy c9452a7666 Clean up promiscuous mode, when using SOCK_PACKET, as best we can;
remember which pcap_t's were opened (with SOCK_PACKET) in promiscuous
mode on interfaces not already in promiscuous mode, turn promiscuous
mode off when closing such a pcap_t, and arrange that, when the program
exits, all pcap_t's of that sort not already closed have their
interfaces taken out of promiscuous mode.  (It's not sufficient to do
this on exit - applications may close a pcap_t without exiting, e.g.
Ethereal.)

This won't always work right (if somebody else requests promiscuous mode
after it's opened by libpcap, we'll turn promiscuous mode off when we
close the pcap_t, and if the program doesn't exit cleanly, it won't
clean up the interfaces), but neither of those problems are fixable -
the only way to get things to work correctly is to use PF_PACKET
sockets, which requires a 2.2 or later kernel.

On a 2.0[.x] kernel, when doing a "recvfrom()" on a SOCK_PACKET socket
to read a captured packet, don't pass a byte count value based on the
snapshot length - "recvfrom()" won't return the actual packet length if
you do that.  (2.2 and later kernels will return the actual packet
length if MSG_TRUNC is passed in.)
2000-12-16 10:43:26 +00:00
guy a91d72d3ed The Linux 2.4 kernel supplies ARPHRD_IEEE802_TR, rather than
ARPHRD_IEEE802, as the hardware type for Token Ring interfaces.  Map
both of them to DLT_IEEE802 (as that has become the DLT_ type for Token
Ring, the fact that it just says "802", not "802_5" or whatever,
nonwithstanding), and, if ARPHRD_IEEE802_TR isn't defined, define it
with the value it has in 2.4 (so that the resulting libpcap will work on
a 2.4 system regardless of whether the system on which it was built
defined ARPHRD_IEEE802_TR).
2000-12-03 09:07:27 +00:00
guy 525b970802 Patch from Arkadiusz Miskiewicz <misiek@pld.org.pl> to handle ARPHRD_SIT
(IPv6-inside-IPv4 tunnel).
2000-11-04 07:19:22 +00:00
guy 82547471f7 When attaching a "bpf_program" to a "pcap_t" to use as a userland
filter, always attach a copy, as "pcap-linux.c" does; that way, after a
program uses "pcap_setfilter()", it can safely use "pcap_freecode()" to
free up the BPF instructions allocated by "pcap_compile()".  Also,
always free it up when the "pcap_t" is closed.

Get rid of the "pcap_t *" argument to "pcap_freecode()", as it's not
necessary.

Document "pcap_freecode()", for the benefit of programs that might
repeatedly compile filter programs and attach them, so that they can
free them up after attaching them and avoid leaking memory for them.
2000-10-28 00:01:26 +00:00
guy 188fee53cc If we're receiving packets from a PF_PACKET socket, check whether the
interface index of the interface for the packet is the interface index
of the loopback interface and, if it is, check if the packet is an
outgoing packet; if so, ignore it, as we'll also be seeing that packet
as a received packet.

If we don't handle the arphrd type of an interface, and fall back on
cooked mode, report the arphrd type, so we know what type we should
consider supporting (if that type can't be supported well, e.g.  if you
don't get any link-layer header, as happens with PPP, we'd be silent).
2000-10-25 07:46:49 +00:00
guy c900791477 The Linux "pcap_setfilter()" makes a copy of the filter it's handed, and
installs that copy; when closing a pcap_t on Linux, free that copy.
2000-10-25 06:59:09 +00:00
guy fd8a7488b1 If we're reading from a savefile, don't try to install a kernel packet
filter.

It appears that "recvfrom()", in 2.2 and later kernels, doesn't check
whether the starting buffer address plus the byte count goes into an
unmapped region of the address space - it (or code it calls) presumably
only checks the locations into which it's actually copying data - so
there doesn't appear to be, on systems with 2.2 and later kernels, any
need to ensure that the buffer size is at least large as the snapshot
length.  We therefore only do so if we're using the old
PF_INET/SOCK_PACKET mechanism; if we're using PF_PACKET, we're on a
2.2 or later kernel, so we don't do it there.
2000-10-25 05:59:04 +00:00
guy edcaeb1db4 Don't declare "iface_get_id()" or "iface_bind()" if
"HAVE_NETPACKET_PACKET_H" isn't defined, as we won't define them if it's
not defined.

If the packet buffer size, as computed from the MTU of the interface, is
less than the user's requested snapshot length, set it to the user's
requested snapshot length; otherwise, the "recvfrom()" call will fail,
as the length specified in the call is the user's requested snapshot
length, and the kernel checks whether the buffer is big enough for that
much data and rejects the "recvfrom()" call if it's not.
2000-10-20 06:55:28 +00:00
torsten c7823f5045 pcap_read: Back out the last change. Now EINTR is handled as timeout
reached so that pcap-based applications can use alarm timers
	   to interrupt the pcap loop.
2000-10-18 23:51:48 +00:00
torsten 0ae7f68987 pcap_read: Check the error code of select against EINTR. Reported by
Sebastian.
2000-10-18 23:47:41 +00:00
guy 9cd2d87ddd Oops, I missed one PCAP_ENCAP_ value; revert it to the equivalent DLT_
value.
2000-10-18 08:32:55 +00:00
guy 2c961ff224 Get rid of the PCAP_ENCAP_ values - if an application uses them, that
application won't build with any other version of libpcap, which means
that a lot of applications won't use them.  In addition,
"pcap_linktype()" needs to return DLT_ values, so that platforms that
build libpcap as a shared library won't break binary compatibility if
they update to this version of libpcap.

Instead, we map from DLT_ values to LINKTYPE_ values when writing
savefiles, and map from LINKTYPE_ values to DLT_ values when reading
savefiles, so that savefiles don't have platform-dependent DLT_ values
in the header as the link type, they have platform-independent LINKTYPE_
values.

This means we don't need to make DLT_ATM_RFC1483, DLT_RAW, etc. have
platform-independent values starting at 100 - only the values in the
savefile header need to be like that.
2000-10-12 03:53:57 +00:00
torsten 45b3cb247a Added support for an "any" device based on a patch from Sebastian Krahmer. 2000-09-20 15:10:28 +00:00
guy da539dbb00 Give it an SCCS ID and an RCS ID. 2000-09-20 07:52:04 +00:00
guy 781fae3571 Introduce a set of PCAP_ENCAP_ codes to specify packet encapsulations.
For those PCAP_ENCAP_ codes corresponding to DLT_ codes that are
(believed to be) the same in all BSDs, the PCAP_ENCAP_ codes have the
same values as the corresponding DLT_ codes.

For those PCAP_ENCAP_ codes corresponding to DLT_ codes that were added
in libpcap 0.5 as "non-kernel" DLT_ codes, or had their values changed
in libpcap 0.5 in order to cope with the fact that those DLT_ codes
have different values in different systems, the PCAP_ENCAP_ codes have
the same values as the corresponding DLT_ codes.

We add some additional PCAP_ENCAP_ codes to handle IEEE 802.11 (which
currently has its link-layer information turned into an Ethernet header
by at least some of the BSDs, but John Hawkinson at MIT wants to add a
DLT_ value for 802.11 and pass up the full link-layer header) and the
Classical IP encapsulation for ATM on Linux (which isn't always the same
as DLT_ATM_RFC1483, from what I can tell, alas).

"pcap-bpf.c" maps DLT_ codes to PCAP_ENCAP_ codes, so as not to supply
to libpcap's callers any DLT_ codes other than the ones that have the
same values on all platforms; it supplies PCAP_ENCAP_ codes for all
others.

In libpcap's "bpf/net/bpf.h", we define the DLT_ values that aren't the
same on all platforms with the new values starting at 100 (to keep them
out of the way of the values various BSDs might assign to them), as we
did in 0.5, but do so only if they're not already defined; platforms
with <net/bpf.h> headers that come with the kernel (e.g., the BSDs)
should define them with the values that they have always had on that
platform, *not* with the values we used in 0.5.

(Code using this version of libpcap should check for the new PCAP_ENCAP_
codes; those are given the values that the corresponding DLT_ values had
in 0.5, so code that checks for them will handle 0.5 libpcap files
correctly even if the platform defines DLT_RAW, say, as something other
than 101.  If that code also checks for DLT_RAW - which means it can't
just use a switch statement, as DLT_RAW might be defined as 101 if the
platform doesn't itself define DLT_RAW with some other value - then it
will also handle old DLT_RAW captures, as long as they were made on the
same platform or on another platform that used the same value for
DLT_RAW.  It can't handle captures from a platform that uses that value
for another DLT_ code, but that's always been the case, and isn't easily
fixable.)

The intent here is to decouple the values that are returned by
"pcap_datalink()" and put into the header of tcpdump/libpcap save files
from the DLT_ values returned by BIOCGDLT in BSD kernels, allowing the
BSDs to assign values to DLT_ codes, in their kernels, as they choose,
without creating more incompatibilities between tcpdump/libpcap save
files from different platforms.
2000-09-17 04:04:36 +00:00
torsten d8d8ac33c8 Changed the indention of pcap-linux.c to match with the other source
files of libpcap.
2000-08-13 21:25:26 +00:00
torsten c2c579d32b Updated the comment on the MSG_TRUNC problem in connection with the Linux
packet filter. Work around to come.
2000-08-04 18:35:48 +00:00
assar 855d5eab07 conditionalize on USHRT_MAX and SOL_PACKET. From Love
<lha@stacken.kth.se>
2000-07-11 01:09:16 +00:00
assar b59cd6dc3c (MSG_TRUNC): define if it's not defined. From Love
<lha@stacken.kth.se>
2000-07-11 01:06:27 +00:00
assar 0e2f8c8892 add config.h, remove gnuc.h. remove __dead 2000-07-11 00:37:04 +00:00
assar be5b659ebf use snprintf instead of sprintf. From Juergen Schoenwaelder
<schoenw@ibr.cs.tu-bs.de>
2000-07-04 12:24:01 +00:00
torsten 94de442535 Merged the Linux v2.2 packet support into the main trunk (from
tag linux-2-2-packet). Please test this code :)
2000-06-08 06:40:09 +00:00
assar 742c75ef83 (pcap_open_live): remove duplicate PCAP_ERRBUF_SIZE 2000-05-13 13:14:41 +00:00
itojun a2b5a241a2 typo; snprint -> snprintf 2000-05-08 23:11:02 +00:00
itojun 466c37aaa3 s/PCAP_ERRBUFF_SIZE/PCAP_ERRBUF_SIZE/ (fatal typo) 2000-04-27 14:24:11 +00:00
itojun 6abf10866e nuke strcpy() 2000-04-27 11:16:19 +00:00
itojun 20d9e08cde do not use sprintf(). always use snprintf().
from NetBSD/OpenBSD src/lib/libpcap.

use freeifaddrs() if exists.
2000-04-27 09:11:11 +00:00
mcr b11ddf8a9b Initial revision 1999-10-07 23:46:40 +00:00