dect
/
libpcap
Archived
13
0
Fork 0
Commit Graph

79 Commits

Author SHA1 Message Date
Guy Harris 84a1f947ba Squelch warnings about type punning. 2010-02-23 20:01:35 -08:00
Guy Harris dcf1642930 dlp->dl_length might be an unsigned long; cast it to unsigned long and
print it with %lu, so the code works regardless of whether it's an
unsigned int or an unsigned long.
2009-07-02 12:28:51 -07:00
guy 7d17ac06c0 From Albert Chin: the "ss" variable is defined only if bufmod is
available, but is set unconditionally.

In addition, we might as well just put all the code that handles bufmod
inside a single #ifdef HAVE_SYS_BUFMOD_H/#endif pair; on Solaris, you
always have bufmod, so the code would work, but it's cleaner that way.
2008-12-02 16:20:23 +00:00
guy 2527d1ac88 Turn close_op into cleanup_op; the routine that handles it can also be
used to clean up after a failed pcap_activate() call.  Convert the
existing close_op routines to cleanup_op routines, and use them to clean
up; rename pcap_close_common() to pcap_cleanup_live_common(), and use it
directly if there's no platform-dependent cleanup needed.  That means we
don't have to write the same cleanup code twice (and possibly forget
stuff in the version done on a failed pcap_activate() call).

Have the cleanup routines do whatever is necessary to indicate that
cleanup has been done, and not do any particular cleaning up if it's
already been done (i.e., don't free something if the pointer to it is
null and null out the pointer once it's been freed, don't close an FD if
it's -1 and set it to -1 once it's been closed, etc.).

For device types/platforms where we don't support monitor mode, check
for it and return PCAP_ERROR_RFMON_NOTSUP - but do so after we've
checked whether we can open the device, so we return "no such device" or
"permission denied" rather than "that device doesn't support monitor
mode" if we can't open the device in the first place.

Fix a comment.
2008-04-14 20:40:58 +00:00
guy 65f9878991 Catch another place where you could get told "no, you may not open that
device" and arrange that PCAP_ERROR_PERM_DENIED be returned.
2008-04-10 00:50:34 +00:00
guy 8dc3233229 Fix an sprintf call. 2008-04-09 22:02:44 +00:00
guy a590c21380 Add some PCAP_WARNING return values for "success, but you might want to
know that..."; currently, only pcap_activate() returns them, but we
might want some more warning returns for some other calls, such as the
ones that set filters.  It's a little cleaner than "clear out the error
message buffer and, if it's not empty after a successful return, it has
a warning", and a little cleaner than spewing a warning to the standard
error (as that might not be visible to the user if they're running a GUI
application).
2008-04-09 21:26:12 +00:00
guy 216c64a7ce Add an error for "you don't have permission to open that device", as
that often means "sorry, this platform requires you to run as root or to
somehow tweak the system to give you capture privileges", and
applications might want to explain that in a way that does a better job
of letting the user know what they have to do.

Try to return or PCAP_ERROR_PERM_DENIED for open errors, rather than
just returning PCAP_ERROR, so that the application can, if it chooses,
try to explain the error better (as those two errors are the ones that
don't mean "there's probably some obscure OS or libpcap problem", but
mean, instead, "you made an error" or "you need to get permission to
capture").

Check for monitor mode *after* checking whether the device exists in the
first place; a non-existent device doesn't support monitor mode, but
that's because it doesn't, well, exist, and the latter would be a more
meaningful error.

Have pcap_open_live() supply an error message for return values other
than PCAP_ERROR, PCAP_ERROR_NO_SUCH_DEVICE, and PCAP_ERROR_PERM_DENIED -
those all supply error strings (PCAP_ERROR because it's for various OS
problems that might require debugging, and the other two because there
might be multiple causes).
2008-04-09 19:58:02 +00:00
guy b043aa85c0 Fix some compile errors. 2008-04-05 05:25:38 +00:00
guy d9b420231a From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_t
handle" routine, an 'activate a pcap_t handle" routine, and some "set
the properties of the pcap_t handle" routines, so that, for example, the
buffer size can be set on a BPF device before the device is bound to an
interface.

Add additional routines to set monitor mode, and make at least an
initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and
10.5.  (Very much "initial" for Linux, which is a twisty little maze of
wireless drivers, many different.)

Have a "timeout" member of the pcap_md structure on all platforms, use
that on Windows instead of the "timeout" member of the pcap_t structure,
and get rid of the "timeout" member of that structure.
2008-04-04 19:37:44 +00:00
guy cb44cb0520 Support for libdlpi, and for enabling "passive mode" on Solaris systems
that support it, from Sagun Shakya.
2008-03-13 18:13:57 +00:00
guy ee4fa22844 As is done in the loop in pcap-bpf.c, check for non-positive values of
"cnt", not for non-negative values, so a "cnt" of 0 is treated the same
as a "cnt" of -1.
2008-02-02 20:58:18 +00:00
guy d46f258195 From Sagun Shakya: update a comment. 2008-01-30 09:41:52 +00:00
guy 91326ea08c Don't assume that p->fcode.bpf_insns remains unchanged while processing
a bufferfull of packets - it could get changed in a callback routine.
2007-12-05 23:37:26 +00:00
guy cbcd540a75 putmsg() returns 0 or -1, not the number of bytes written. 2006-04-04 05:32:27 +00:00
guy de054a43c1 From Don Ebright: clean out *uerror in recv_ack() before doing anything,
so that it's not EBUSY if we didn't get an EBUSY in a
DL_ERROR_ACK/DL_SYSERR reply, and our checks for EBUSY only catch that
case.

If we *did* get EBUSY on all the SAPs we tried, supply an error.

Make "dl_dohpuxbind()" always return a value, so we don't fall off the
end and return an error indication by accident.
2005-08-13 23:14:24 +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 14f186752d If we get EBUSY when binding to a SAP, clear out the error string we get
from it, so that our caller doesn't treat it as a warning.
2005-04-17 17:25:51 +00:00
guy ad93efab7c Typo fix, from Mark C. Brown. 2005-04-17 17:18:03 +00:00
guy 75e966b257 From Mark C. Brown: don't use hard-code values of 22 and 24 for the SAP
on HP-UX, just keep trying different SAPs until we find one that doesn't
return EBUSY, as attempting to use a SAP that some other descriptor is
already bound to returns EBUSY.
2005-04-17 00:47:40 +00:00
guy 16e088ff27 Update some comments. 2005-04-08 03:08:00 +00:00
guy 1b34dd0bbd Rename HAVE_HPUX10_20 to HAVE_HPUX10_20_OR_LATER, because it's also
defined for 11.x.
2005-04-08 02:15:49 +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 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