dect
/
libpcap
Archived
13
0
Fork 0
Commit Graph

77 Commits

Author SHA1 Message Date
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