dect
/
libpcap
Archived
13
0
Fork 0
Commit Graph

57 Commits

Author SHA1 Message Date
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 980745815d Do some error checking when extracting the unit number from a device
name.
2004-07-22 20:18:38 +00:00
guy a9a1d85832 (Try to) squelch some compiler warnings on HP-UX. 2004-07-20 21:18:56 +00:00
guy 481a4015c4 From Rick Jones:
fix a comment;

	fix references to the send-side file descriptor in
	"pcap_open_live()";

	"dlrawdatareq()"s caller reports the error - we just return what
	"putmsg()" returns, so the caller knows whether there was an
	error.
2004-07-20 21:10:57 +00:00
guy e80b63b73e "sbh_drops" is cumulative, so we can't add it to the packet receive
count; instead, we add the cumulative drop count to the cumulative
receive count in the statistics we're returning.
2004-05-21 09:45:31 +00:00
guy dc95138209 Add the dropped packet count to the received packet count, so that the
counts work similarly to the way they work in BPF and 2.4 and later
Linux (and so that we don't run the risk of the dropped packet count
being bigger than the received packet count, which can result in dropped
packet percentages > 100).
2004-05-21 09:22:16 +00:00
guy 076135f7df On non-HP-UX systems, if we fail to open "/dev/{if}" or "/dev/{if}N"
because neither of them exist, just report that there was no DLPI device
found for "{if}N", so people don't think that they need to fix libpcap
(or the program using it) to look somewhere else for the device - the
problem is probably that they're trying to capture on a loopback device
and the lack of any DLPI device is just a symptom of the fact that the
loopback device, at least on Solaris, appears not to support DLPI and
thus isn't supported by libpcap....
2004-04-23 05:19:04 +00:00
guy 5b0754b7de Having gone through the trouble of creating "dl_doattach()", we might as
well use it....
2004-04-07 07:56:05 +00:00
guy 6c9206b958 Small whitespace style cleanup. 2004-04-03 20:53:48 +00:00
guy cec387867a Add support for sending packets on HP-UX if DL_HP_RAWDLS (for "raw
mode") is defined.
2004-04-03 20:52:41 +00:00
guy 5b35985840 If we get EAGAIN, return 0, as we do with EAGAIN and EWOULDBLOCK on
other platforms, and as the man page says we do (in non-blocking mode,
we return 0 if no packets are available).
2004-04-03 02:04:13 +00:00
guy f20514f49f From Rick Jones: the DL_HP_PPA_ACK_OBS #defines are gone in HP-UX 11.23;
check for DL_HP_PPA_REQ instead.
2004-04-02 06:18:22 +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 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 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 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 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 e592efb3bc According to the bufmod man page for Solaris 2.4 and 9 (meaning it's
probably true in all versions), "sbh_drops" is "the cumulative number of
input messages that this instance of bufmod has dropped due to flow
control or resource exhaustion."

"Cumulative" presumably means "don't add it to the count of drops, as
it's *already* a count since the capture started; just set the count of
drops to the value".  Do so.
2003-02-19 08:06:26 +00:00
guy 8b31d709a2 If we have bufmod, allocate a buffer big enough to hold the size of
chunk we ask bufmod to send upstream.

Yes, uint_t is always 32 bits, at least as I read the Solaris 8 code.

The chunk size is 8192, not 0, by default.

Don't do the chunk size stuff if we don't have bufmod.
2003-02-05 01:46:58 +00:00
guy 2256aabb91 As per suggestions from the anonymous SourceForge user who submitted bug
673958, make two changes on Solaris:

	don't set SB_NO_DROPS - doing so means that bufmod doesn't drop
	packets, so it can't report the number of drops, but packets
	probably still get dropped *somewhere*, if for no other reason
	than that the system refuses to allocate more mblks/dblks, even
	if it doesn't discard messages that arrive at the stream head if
	it's full;

	set the chunk size to 65536, as otherwise packets are dropped
	too easily.

snoop also appears not to set SB_NO_DROPS and also appears to set the
chunk size to 65536, so that's probably the right thing to do.
2003-02-04 05:42:03 +00:00
guy a8d3536171 Make "split_dname()" take a "char *" as an argument and return a "char
*", and arrange never to pass it the argument to "pcap_open_live()" -
copy the device name to a buffer before doing anything else to it.
2003-01-03 08:33:54 +00:00
guy 2b3d687c1e Constify the device argument to "pcap_open_live()", as was done for
other pcap-xxx.c files, and constify the argument to and return value
from "split_dname()" as well, to match.
2002-12-28 01:07:10 +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 243b20ec55 Add SunATM support, based on code from Yen Yen Lim at North Dakota State
University.
2002-07-11 09:06:30 +00:00
itojun 5918c491c1 whitespace cleanup 2002-06-11 17:04:44 +00:00
guy 5fd91ac78f Fix up some printf calls to cope with both 32-bit and 64-bit longs and
"size_t"s.
2002-05-31 11:03:02 +00:00
guy 0c86142e99 From John Bankier <jbankier@rainfinity.com>: the buffer into which we
read packets is "p->bufsize" bytes long, not MAXDLBUF bytes long
("p->bufsize" is set to (MAXDLBUF * sizeof sizeof(bpf_u_int32))), so
supply that as the "maxlen" value in the "data" argument to "getmsg()".
2002-03-05 04:05:56 +00:00
guy c9f3b70d22 The "sbh_timestamp" member of an "sb_hdr" structure isn't necessarily a
"struct timeval" - on Solaris 7 and 8, when compiling in LP64 or I32LPx
mode, it's a "struct timeval32" (presumably so that bufmod doesn't have
to worry about whether the stream is being read by a 32-bit program or a
64-bit program).  Set the "struct timeval" "pkthdr.ts" by copying the
individual members rather than by doing a structure assignment.
2002-02-22 11:49:13 +00:00
guy efc02fd2e3 Put more information into the comments for "pcap_stats()". 2001-12-10 07:14:14 +00:00
guy ee923fedbb AIX's DLPI devices are, at least in AIX 4.3 and later, in the
"/dev/dlpi" directory, not the "/dev" directory.
2001-11-17 21:07:59 +00:00
guy 366751fb69 Close a file descriptor leak, as per a patch that comes with Nessus and
Pavel Kankovsky's suggested fix to that patch.
2001-11-11 22:32:28 +00:00
guy 5ad8d9d9e2 As suggested by Hyung Sik Yoon <hsyn@kr.ibm.com>, use 2 rather than 0 as
the SAP on AIX if a SAP of 1537 doesn't work; he says that 2 works on
Token Ring but 0 doesn't.
2001-10-12 06:43:42 +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 a891a1d5d0 On AIX, if binding to the SAP 1537 fails, try binding to 0; Token Ring
devices appear to reject attempts to bind to 1537, perhaps because Token
Ring devices use SAPs rather than Ethertypes and 1537 isn't a valid SAP
value.

Try to supply a string rather than a numerical value for various DLPI
errors, and to supply a string rather than a numerical value for
unexpected DLPI primitives.

Cast the argument to <ctype.h> macros to "unsigned char", to eliminate
GCC warnings and to keep the macros from referring outside an array when
handed bytes with the 8th bit set.
2001-07-28 23:12:48 +00:00
guy db2a1d1e5e The "dl_module_id_1" and "dl_module_id_2" members of a
"dl_hp_ppa_info_t" are arrays of "u_char" (or "u_int8_t"), presumably to
get around the problems of signed characters; this causes complaints
from HP's C compiler if we pass them as an argument to "strcmp()", so
cast them to "const char *".
2001-06-27 05:22:44 +00:00
guy 469dc3588b Put the code to get a unit number from a device name into a common
routine, and use it both on HP-UX and other DLPI systems; this means
that, in case there is ever a network device on HP-UX with a number in
the device type name, we'll properly extract the unit number (i.e.,
we'll extract the last number from the name, not the first number) - I
don't think that'll ever happen, but putting it into a common routine is
cleaner in any case.
2001-05-21 07:33:56 +00:00
guy 60673d8144 Patch from Xianjie Zhang <xzhang@cup.hp.com> to handle HP-UX systems
with a large number of PPA's.
2001-05-21 03:50:08 +00:00
guy c711e1de8d Patch from Stefan Hudson <hudson@mbay.net> to handle, on Solaris, device
class names with digits in them.
2001-05-21 03:35:04 +00:00
guy bc0425f86c Patch from Onno van der Linden <onno@simplex.nl> to support Token Ring
on DLPI systems.
2001-02-21 09:07:40 +00:00
guy dc543edc9a Fix a couple of error messages. 2000-11-22 05:32:55 +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 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
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
guy 5c220490cb Change the message issued on HP-UX if we can't find the PPA for a
network device, so that

	1) you can infer from the message whether the program is using
	   the old version of the code to get the PPA (which didn't work
	   all that well) or the newer version, without having to prod a
	   user complaining about tcpdump/Ethereal/whatever not working
	   to tell you which version of libpcap they're using;

	2) programs can perhaps check the error message returned by
	   libpcap and, if it's the old error message, tell the user
	   that the problem may be that they're using an old libpcap.
2000-08-13 06:56:05 +00:00