mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-26 20:12:44 +00:00
libpcap: Update to 1.10.5
Changes: https://git.tcpdump.org/libpcap/blob/bbcbc9174df3298a854daee2b3e666a4b6e5383a:/CHANGES Reviewed by: emaste Obtained from: https://www.tcpdump.org/release/libpcap-1.10.5.tar.gz Sponsored by: The FreeBSD Foundation
This commit is contained in:
commit
afdbf109c6
@ -1,3 +1,168 @@
|
||||
Friday, August 30, 2024 / The Tcpdump Group
|
||||
Summary for 1.10.5 libpcap release
|
||||
Source code:
|
||||
Spell WirelessHART details properly.
|
||||
Mark pcap_vasprintf() as printf-like.
|
||||
Finalize moving of bpf_filter.c. (GH #1166)
|
||||
Remove an unneeded argument from gen_mcode6().
|
||||
Don't do some Berkeley YACC workarounds with YACC releases not
|
||||
requiring them.
|
||||
Use correct data types rather than int in some cases.
|
||||
Squelch compiler warning in grammar.c.
|
||||
Fix findalldevtest compilation if IPv6 isn't enabled.
|
||||
Rename helper routines for pcap modules to have names beginning with
|
||||
pcapint_, to avoid namespace collisions for code linking statically
|
||||
with libpcap.
|
||||
Avoid casting hack for the Windows cleanup-on-exit routine.
|
||||
Use %zu format for one case of printing a size_t.
|
||||
Fix some Coverity errors.
|
||||
Fix availabilities of some functions to match reality.
|
||||
pcap: make the seconds and microseconds/nanoseconds fields unsigned.
|
||||
Remove the unused pcap-rpcap-int.h header file.
|
||||
Thread safety:
|
||||
Make some static variables thread-local; fixes issue #1174.
|
||||
Packet filtering:
|
||||
Improve reporting of some invalid filter expressions.
|
||||
Return an error from pcap_compile() if the scanner fails to initialize.
|
||||
Optimizer fix from Archit Shah to recompute dominators after
|
||||
moving code (#976); fixes #945 (although the resulting filter
|
||||
isn't empty).
|
||||
Optimizer fix from Archit Shah to mark value as unknown when store
|
||||
of that value is deleted (#972); fixes #143, #434, #436, #437,
|
||||
and #1076.
|
||||
Linux:
|
||||
Properly return warnings.
|
||||
Don't use DLT_LINUX_SLL2 for anything other than the "any" device.
|
||||
Avoid 32-bit unsigned integer overflow in USB captures. Fixes
|
||||
issues #1134 and #1205.
|
||||
Fix a file descriptor leak.
|
||||
Properly report warnings about unknown ARPHRD_ types.
|
||||
Fix DLT_CAN_SOCKETCAN handling of CAN FD.
|
||||
Add CAN XL support to DLT_CAN_SOCKETCAN.
|
||||
Clean up the code that sets the "real" ("original") length for
|
||||
isochronous USB transfers.
|
||||
Avoid unnecessary blocking on recvmsg() in the Bluetooth monitor and
|
||||
Bluetoth modules.
|
||||
Solaris:
|
||||
Handle BPF returning ESRCH for unknown devices.
|
||||
List the "any" device if it's supported.
|
||||
Report {non-existent zone}/{interface} errors appropriately.
|
||||
Allow attaching to links owned by a non-global zone. (Based on
|
||||
pull request #1202.)
|
||||
Fix AF_LINK handling on illumos.
|
||||
macOS:
|
||||
Redid the availability macros to be closer to what Apple's doing
|
||||
in recent SDKs, including tagging pcap-namedb.h routines.
|
||||
Fix the install name of the installed shared library to have a
|
||||
full path when building with CMake.
|
||||
Fix universal builds.
|
||||
Haiku:
|
||||
Convert the module to C. Fixes issue #1114.
|
||||
Address a few compiler warnings. Fixes issue #1114.
|
||||
Fix various build problems. Fixes issue #1114.
|
||||
Report non-existent devices correctly.
|
||||
Fix handling of packet statistics.
|
||||
Fix packet timestamping.
|
||||
Fix packet filtering with low snaplen.
|
||||
Improve connection status reporting.
|
||||
Add support for promiscuous mode.
|
||||
Detect DLTs and loopback capture support at run time.
|
||||
Report IEEE 802.11 as PCAP_IF_WIRELESS.
|
||||
Windows:
|
||||
Fix internal handling of "not supported" error codes from NPF.
|
||||
Work around a bug in Npcap 1.00 in case of driver version mismatch.
|
||||
Don't call WSACleanup() when handling a failed WSAStartup().
|
||||
BSD, macOS, AIX, Solaris 11, Linux:
|
||||
Add a new error PCAP_ERROR_CAPTURE_NOTSUP, for use if a capture
|
||||
mechanism is not present, in the hopes that, for example,
|
||||
attempts to capture on Windows Services for Linux 1, in which
|
||||
the NT kernel attempts to simulate Linux system calls but does
|
||||
not support packet sockets, can get an error that better
|
||||
indicates the underlying problem.
|
||||
AirPcap:
|
||||
Format an error message if we run out of memory.
|
||||
nflog:
|
||||
Fix count of dropped packets.
|
||||
Make sure we don't overflow when rounding up the TLV length.
|
||||
rpcap:
|
||||
Handle routines removed in at least some OpenSSL libraries.
|
||||
CVE-2023-7256: Clean up sock_initaddress() and its callers to avoid
|
||||
double frees in some cases.
|
||||
Don't define SOCKET ourselves; instead, define PCAP_SOCKET as int
|
||||
on UN*Xes and as SOCKET on Windows.
|
||||
CVE-2024-8006: Fix pcap_findalldevs_ex() not to crash if passed a
|
||||
file:// URL with a path to a directory that cannot be opened.
|
||||
Savefiles:
|
||||
Handle DLT_/LINKTYPE_ mapping better, to handle some
|
||||
OpenBSD-specific link types better.
|
||||
Treat if_tsoffset as signed in pcapng files, as the spec says.
|
||||
Don't try to fix the "real" length for isochronous USB
|
||||
transfers if the number of USB descriptors is too large.
|
||||
Reject pcap files where one of the reserved fields in the
|
||||
"link-layer type plus other stuff" is non-zero.
|
||||
Building and testing:
|
||||
Add a configure option to help debugging (--enable-instrument-functions).
|
||||
Improved tests and error reporting for uses of pkg-config, and
|
||||
improve help message.
|
||||
Fix Haiku build.
|
||||
With CMake, install headers in CMAKE_INSTALL_INCLUDEDIR rather
|
||||
than just include.
|
||||
Build libpcap.a before building test programs.
|
||||
Print address family numerically, as well as symbolically,
|
||||
in findalldevstest.
|
||||
Fail with suggestions, rather than failing over to no capture
|
||||
support, if no capture mechanism was found. Fixes issue #1016.
|
||||
Don't indent comments in Make, as that may cause them not to be
|
||||
recognized as comments.
|
||||
Don't check for libssl if we aren't going to use it.
|
||||
Better handle enabling and disabling of sanitizers. Fixes issue
|
||||
#1171.
|
||||
CMakeLists.txt: Print "Symlinking: /some/path to ..." conditionally.
|
||||
Evaluate CMAKE_INSTALL_PREFIX at install time.
|
||||
cmake: Update the minimum required version to 2.8.12 (except Windows).
|
||||
cmake: suppress CMP0042 OLD deprecated warning.
|
||||
Makefile.in: Add the releasecheck target.
|
||||
Cirrus CI: Add the "make releasecheck" command in the Linux task.
|
||||
Makefile.in: Add the whitespacecheck target.
|
||||
Cirrus CI: Run the "make whitespacecheck" command in the Linux task.
|
||||
Autoconf: Update config.{guess,sub}, timestamps 2024-01-01.
|
||||
Autoconf: Update the install-sh script to the 2020-11-14.01 version.
|
||||
Compile with '-Wnull-pointer-subtraction',
|
||||
'-Wunused-but-set-parameter', and '-Wunused-but-set-variable' in
|
||||
devel mode if supported.
|
||||
Don't ignore spaces between CMAKE_C_FLAGS and DPDK_C_FLAGS with
|
||||
CMake.
|
||||
Use noreturn and __format__ with XL C 7.0 and later.
|
||||
Check for the same -W flags in autotools and CMake.
|
||||
Autoconf: Add autogen.sh, remove configure and config.h.in and put
|
||||
these generated files in the release tarball.
|
||||
Autoconf: Get the size of a time_t.
|
||||
Fix propagation of cc_werr_cflags() output.
|
||||
Makefile.in(s): Fix the depend target.
|
||||
mkdep: Exit with a non-zero status if a command fails.
|
||||
Fix HCI_CHANNEL_MONITOR detection with musl libc.
|
||||
Extend "make shellcheck" onto mkdep too.
|
||||
Add initial support for building with TinyCC.
|
||||
Address all known compiler warnings specific to illumos, Linux, NetBSD,
|
||||
Solaris and Sun C; in CI expect warnings specific to TinyCC only.
|
||||
Documentation:
|
||||
Update and fix pcap-filter man page.
|
||||
Add a README.haiku.md file.
|
||||
Document pcap-config better.
|
||||
Man page formatting and prose fixes.
|
||||
Rename doc/README.Win32.md to doc/README.windows.md.
|
||||
Update pcap-savefile man page to match the Internet-Draft for
|
||||
pcap.
|
||||
Fix CMake issues for target used by other projects.
|
||||
Explain "any" device better in pcap_open_live(3PCAP).
|
||||
Update INSTALL.md.
|
||||
Note in man pages that errbuf arguments must point to an error
|
||||
buffer.
|
||||
Note that if pcap_findalldevs() fails it sets *alldevsp to NULL;
|
||||
there's no devices list to free.
|
||||
Explain "other addresses" in pcap_findalldevs(3PCAP).
|
||||
Document pcap_lookupnet(3PCAP) a bit better.
|
||||
|
||||
Friday, April 7, 2023 / The Tcpdump Group
|
||||
Summary for 1.10.4 libpcap release
|
||||
Source code:
|
||||
@ -58,7 +223,7 @@ Saturday, December 31, 2022 / The Tcpdump Group
|
||||
when reading a LINKTYPE_PFLOG file.
|
||||
Put CAN ID field in CAN pseudo-headers for LINUX_SLL2, as we do
|
||||
for LINUX_SLL.
|
||||
Fix inorrectly-computed "real" length for isochronous USB
|
||||
Fix incorrectly-computed "real" length for isochronous USB
|
||||
transfers when reading savefiles.
|
||||
Don't crash if pcap_can_set_rfmon() is called.
|
||||
Fix pcap_offline_read() loop.
|
||||
@ -139,7 +304,7 @@ Saturday, December 31, 2022 / The Tcpdump Group
|
||||
Return an error if the driver reports 0 timestamp modes supported.
|
||||
Close the ADAPTER handle for some errors in
|
||||
pcap_create_interface().
|
||||
Get rid of old umaintained VS project files.
|
||||
Get rid of old unmaintained VS project files.
|
||||
Fix deprecation warning for pcap_handle().
|
||||
Npcap is now at npcap.com, not npcap.org.
|
||||
Make sure "no such device" and "no permission to open device"
|
||||
@ -307,7 +472,7 @@ Tuesday, December 29, 2020
|
||||
Remove (unused) SITA support
|
||||
Capture file reading:
|
||||
Correctly handle pcapng captures with more than one IDB with a
|
||||
snspshot length greater than the supported maximum
|
||||
snapshot length greater than the supported maximum
|
||||
Capture file writing:
|
||||
Create the file in pcap_dump_open_append() if it doesn't exist
|
||||
Packet filtering:
|
||||
@ -421,7 +586,7 @@ Tuesday, December 29, 2020
|
||||
isn't called
|
||||
Fix compilation on Cygwin/MSYS
|
||||
Add pcap_handle(), and deprecate pcap_fileno()
|
||||
Report PCAP_ERROR_NO_SUCH_DEVICE for a non-existent device
|
||||
Report PCAP_ERROR_NO_SUCH_DEVICE for a nonexistent device
|
||||
Return an appropriate error message for device removed or
|
||||
device unusable due to a suspend/resume
|
||||
Report a warning for unknown NdisMedium types
|
||||
@ -503,7 +668,7 @@ Sunday, July 22, 2018
|
||||
Windows with WinPcap/Npcap (GitHub issue #824)
|
||||
Have pcap_dump_open_append() create the dump file if it doesn't
|
||||
exists (GitHub issue #247)
|
||||
Fix the maxmum snapshot length for DLT_USBPCAP
|
||||
Fix the maximum snapshot length for DLT_USBPCAP
|
||||
Use -fPIC when building for 64-bit SPARC on Linux (GitHub issue #837)
|
||||
Fix CMake 64-bit library installation directory on some Linux
|
||||
distributions
|
||||
@ -668,7 +833,7 @@ Wednesday Nov. 12, 2014 guy@alum.mit.edu/mcr@sandelman.ca
|
||||
|
||||
Monday Aug. 12, 2014 guy@alum.mit.edu
|
||||
Summary for 1.6.2 libpcap release
|
||||
Don't crash on filters testing a non-existent link-layer type
|
||||
Don't crash on filters testing a nonexistent link-layer type
|
||||
field.
|
||||
Fix sending in non-blocking mode on Linux with memory-mapped
|
||||
capture.
|
||||
@ -956,7 +1121,7 @@ Mon. October 27, 2008. ken@netfunctional.ca. Summary for 1.0.0 libpcap rele
|
||||
Autogenerate VERSION numbers better
|
||||
|
||||
Mon. September 10, 2007. ken@xelerance.com. Summary for 0.9.8 libpcap release
|
||||
Change build process to put public libpcap headers into pcap subir
|
||||
Change build process to put public libpcap headers into pcap subdir
|
||||
DLT: Add value for IPMI IPMB packets
|
||||
DLT: Add value for u10 Networks boards
|
||||
Require <net/pfvar.h> for pf definitions - allows reading of pflog formatted
|
||||
@ -1285,7 +1450,7 @@ v0.2.1 Sun Jul 14 03:02:26 PDT 1996
|
||||
(steve@research.oknet.com)
|
||||
|
||||
- Fixed to handle raw ip addresses such as 0.0.0.1 without "left
|
||||
justifing"
|
||||
justifying"
|
||||
|
||||
- Add "sca" keyword (for DEC cluster services) as suggested by Terry
|
||||
Kennedy (terry@spcvxa.spc.edu)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Alex Smith <44322503+MadAlexUK at users dot noreply dot github dot com>
|
||||
Alfredo Alvarez Fernandez <alfredoalvarezernandez at gmail dot com>
|
||||
Ali Abdulkadir <autostart dot ini at gmail dot com>
|
||||
Alois Klink <alois at aloisklink dot com>
|
||||
Alon Bar-Lev <alonbl at sourceforge dot net>
|
||||
Anders Broman <anders dot broman at ericsson dot com>
|
||||
Andres Perera <andres dot p at zoho dot com>
|
||||
@ -24,7 +25,9 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
<andy-1 at sourceforge dot net>
|
||||
Ani Sinha <ani at aristanetworks dot com>
|
||||
Anthony Kirby <Anthony dot Kirby at nominet dot uk>
|
||||
Antonio Vázquez Blanco <antonio dot vazquez at tarlogic dot com>
|
||||
Antti Kantee <pooka at netbsd dot org>
|
||||
Archit Shah <archit at cave32 dot com>
|
||||
Arien Vijn <arienvijn at sourceforge dot net>
|
||||
Arkadiusz Miskiewicz <misiek at pld dot org dot pl>
|
||||
Armando L. Caro Jr. <acaro at mail dot eecis dot udel dot edu>
|
||||
@ -49,6 +52,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Christian Peron <csjp at freebsd dot org>
|
||||
Christian Svensson <blue at cmd dot nu>
|
||||
Christopher K Lee <christopher dot lee at cspi dot com>
|
||||
Clément Péron <peron dot clem at gmail dot com>
|
||||
Daniel Borkmann <dborkman at redhat dot com>
|
||||
Daniele Orlandi <daniele at orlandi dot com>
|
||||
Daniel Lublin <daniel at lublin dot se>
|
||||
@ -69,6 +73,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Dug Song <dugsong at monkey dot org>
|
||||
Dustin Spicuzza <dustin at virtualroadside dot com>
|
||||
dzejarczech <dzejarczech at sourceforge dot net>
|
||||
Ed Maste <emaste at FreeBSD dot org>
|
||||
Edward Sheldrake <ejs1920 at sourceforge dot net>
|
||||
Eli Schwartz <eschwartz93 at gmail dot com>
|
||||
Eric Anderson <anderse at hpl dot hp dot com>
|
||||
@ -85,6 +90,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Fulko Hew <fulko dot hew at gmail dot com>
|
||||
Fumiyuki Shimizu <fumifumi at abacustech dot jp>
|
||||
Gabor Tatarka <gabor dot tatarka at ericsson dot com>
|
||||
Gabriel Ganne <gabriel dot ganne at gmail dot com>
|
||||
Garrett Cooper <yaberauneya at sourceforge dot net>
|
||||
George Neville-Neil <gnn at freebsd dot org>
|
||||
Gerald Combs <gerald at zing dot org>
|
||||
@ -99,8 +105,10 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Guillaume Pelat <endymion_ at users dot sourceforge dot net>
|
||||
Gustavo Zacarias <gustavo at zacarias dot com dot ar>
|
||||
Hagen Paul Pfeifer <hagen at jauu dot net>
|
||||
headshog <craaaaaachind at gmail dot com>
|
||||
Henri Doreau <hdoreau at sourceforge dot net>
|
||||
Hiroaki KAWAI <kawai at stratosphere dot co dot jp>
|
||||
hopper-vul <hopper dot vul at gmail dot com>
|
||||
Hyung Sik Yoon <hsyn at kr dot ibm dot com>
|
||||
Igor Khristophorov <igor at atdot dot org>
|
||||
Jakub Sitnicki <jsitnicki at gmail dot com>
|
||||
@ -120,16 +128,19 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
jingyu yang <jingleyang at users dot noreply dot github dot com>
|
||||
Jiri Slaby <jirislaby at gmail dot com>
|
||||
João Valverde <joao dot valverde at tecnico dot ulisboa dot pt>
|
||||
Joel <82591719+joelg989 at users dot noreply dot github dot com>
|
||||
Joerg Mayer <jmayer at loplof dot de>
|
||||
John Bankier <jbankier at rainfinity dot com>
|
||||
Jon Lindgren <jonl at yubyub dot net>
|
||||
Jon Smirl <jonsmirl at gmail dot com>
|
||||
Jorge Boncompte [DTI2] <jorge at dti2 dot net>
|
||||
Josh Soref <2119212+jsoref at users dot noreply dot github dot com>
|
||||
jromanr <jromanr at hotmail dot com>
|
||||
Juergen Schoenwaelder <schoenw at ibr dot cs dot tu-bs dot de>
|
||||
Julien Moutinho <julm at savines dot alpes dot fr dot eu dot org>
|
||||
Jung-uk Kim <jkim at FreeBSD dot org>
|
||||
Kazushi Sugyo <sugyo at pb dot jp dot nec dot com>
|
||||
Kenny Luong <kluong at cloudflare dot com>
|
||||
Kevin Boulain <kevin dot boulain at securactive dot net>
|
||||
Klaus Klein <kleink at netbsd dot org>
|
||||
Koryn Grant <koryn at endace dot com>
|
||||
@ -141,6 +152,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Lorenzo Cavallaro <sullivan at sikurezza dot org>
|
||||
Loris Degioanni <loris at netgroup-serv dot polito dot it>
|
||||
Love Hörnquist-Åstrand <lha at stacken dot kth dot se>
|
||||
Lubomir Varga <lubomir dot varga at qpp dot sk>
|
||||
Luis MartinGarcia <luis dot mgarc at gmail dot com>
|
||||
lxy <391861737 at qq dot com>
|
||||
Maciej W. Rozycki <macro at ds2 dot pg dot gda dot pl>
|
||||
@ -154,6 +166,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Markus Mayer <markus_mayer at sourceforge dot net>
|
||||
Martin Husemann <martin at netbsd dot org>
|
||||
Márton Németh <nm127 at freemail dot hu>
|
||||
Matias Karhumaa <matias dot karhumaa at gmail dot com>
|
||||
Matt Eaton <agnosticdev at gmail dot com>
|
||||
Matthew Luckie <mjl at luckie dot org dot nz>
|
||||
Matthias Hannig <matthias at hannig dot cc>
|
||||
@ -174,8 +187,10 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Nan Xiao <nan at chinadtrace dot org>
|
||||
nic-kaczinsky <68271784+nic-kaczinsky at users dot noreply dot github dot com>
|
||||
Nick Kelsey <nickk at silicondust dot com>
|
||||
Nicolas Badoux <n dot badoux at hotmail dot com>
|
||||
Nicolas Dade <ndade at nsd dot dyndns dot org>
|
||||
Niko Delarich <niko dot delarich at gmail dot com>
|
||||
Nikolay Edigaryev <edigaryev at gmail dot com>
|
||||
N. Leiten <nleiten at sourceforge dot net>
|
||||
nnposter <nnposter at users dot noreply dot github dot com>
|
||||
<nvercamm at sourceforge dot net>
|
||||
@ -209,6 +224,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Roland Dreier <roland at purestorage dot com>
|
||||
Romain Francoise <rfrancoise at debian dot org>
|
||||
Rongxi Li <rongxi dot li at chaitin dot com>
|
||||
Rose <83477269+AtariDreams at users dot noreply dot github dot com>
|
||||
Sagun Shakya <sagun dot shakya at sun dot com>
|
||||
Scott Barron <sb125499 at ohiou dot edu>
|
||||
Scott Gifford <sgifford at tir dot com>
|
||||
@ -218,6 +234,7 @@ Additional people who have contributed patches (in alphabetical order):
|
||||
Sepherosa Ziehau <sepherosa at gmail dot com>
|
||||
Shane Kerr <shane at time-travellers dot org>
|
||||
Shaun Clowes <delius at progsoc dot uts dot edu dot au>
|
||||
Shunyang Zhang <shyzhang at grandstream dot cn>
|
||||
solofox <wensg100 at sina dot com>
|
||||
Solomon Peachy <pizza at shaftnet dot org>
|
||||
Stefan Hudson <hudson at mbay dot net>
|
||||
|
@ -4,10 +4,18 @@ with CMake and any build system supported by CMake.
|
||||
|
||||
To build libpcap with the configure script and `make`:
|
||||
|
||||
* If you build from a git clone rather than from a release archive,
|
||||
run `./autogen.sh` (a shell script). The autogen.sh script will
|
||||
build the `configure` and `config.h.in` files.
|
||||
|
||||
On some system, you may need to set the `AUTORECONF` variable, like:
|
||||
`AUTORECONF=autoreconf-2.69 ./autogen.sh`
|
||||
to select the `autoreconf` version you want to use.
|
||||
|
||||
* Run `./configure` (a shell script). The configure script will
|
||||
determine your system attributes and generate an appropriate `Makefile`
|
||||
from `Makefile.in`. The configure script has a number of options to
|
||||
control the configuration of libpcap; `./configure --help`` will show
|
||||
control the configuration of libpcap; `./configure --help` will show
|
||||
them.
|
||||
|
||||
* Next, run `make`. If everything goes well, you can
|
||||
@ -15,6 +23,10 @@ them.
|
||||
libpcap if you just want to build tcpdump; just make sure the tcpdump
|
||||
and libpcap directory trees have the same parent directory.
|
||||
|
||||
On OpenBSD, you may need to set, before the `make`, the `AUTOCONF_VERSION`
|
||||
variable like:
|
||||
`AUTOCONF_VERSION=2.69 make`
|
||||
|
||||
To build libpcap with CMake and the build system of your choice, from
|
||||
the command line:
|
||||
|
||||
@ -62,7 +74,7 @@ forget to include an autoconf fragment suitable for use in
|
||||
`configure.ac`.
|
||||
|
||||
It is possible to override the default packet capture type with the
|
||||
`--with-pcap`` option to `./configure` or the `-DPCAP_TYPE` option to
|
||||
`--with-pcap` option to `./configure` or the `-DPCAP_TYPE` option to
|
||||
CMake, although the circumstances where this works are limited. One
|
||||
possible reason to do that would be to force a supported packet capture
|
||||
type in the case where the configure or CMake scripts fails to detect
|
||||
@ -186,37 +198,44 @@ in `/usr/include/sys/dlpi.h`, and find the corresponding value.
|
||||
CONTRIBUTING.md - guidelines for contributing
|
||||
CREDITS - people that have helped libpcap along
|
||||
INSTALL.md - this file
|
||||
LICENSE - the license under which tcpdump is distributed
|
||||
LICENSE - the license under which libpcap is distributed
|
||||
Makefile.in - compilation rules (input to the configure script)
|
||||
README.md - description of distribution
|
||||
doc/README.aix - notes on using libpcap on AIX
|
||||
doc/README.dag - notes on using libpcap to capture on Endace DAG devices
|
||||
doc/README.haiku.md - notes on using libpcap on Haiku
|
||||
doc/README.hpux - notes on using libpcap on HP-UX
|
||||
doc/README.linux - notes on using libpcap on Linux
|
||||
doc/README.macos - notes on using libpcap on macOS
|
||||
doc/README.septel - notes on using libpcap to capture on Intel/Septel devices
|
||||
doc/README.sita - notes on using libpcap to capture on SITA devices
|
||||
doc/README.solaris.md - notes on using libpcap on Solaris
|
||||
doc/README.Win32.md - notes on using libpcap on Win32 systems (with Npcap)
|
||||
doc/README.windows.md - notes on using libpcap on Windows systems (with Npcap)
|
||||
VERSION - version of this release
|
||||
aclocal.m4 - autoconf macros
|
||||
arcnet.h - ARCNET definitions
|
||||
atmuni31.h - ATM Q.2931 definitions
|
||||
autogen.sh - build configure and config.h.in (run this first)
|
||||
bpf_dump.c - BPF program printing routines
|
||||
bpf_filter.c - BPF filtering routines
|
||||
bpf_image.c - BPF disassembly routine
|
||||
charconv.c - Windows Unicode routines
|
||||
charconv.h - Windows Unicode prototypes
|
||||
config.guess - autoconf support
|
||||
config.h.in - autoconf input
|
||||
config.sub - autoconf support
|
||||
configure - configure script (run this first)
|
||||
configure.ac - configure script source
|
||||
diag-control.h - compiler diagnostics control macros
|
||||
dlpisubs.c - DLPI-related functions for pcap-dlpi.c and pcap-libdlpi.c
|
||||
dlpisubs.h - DLPI-related function declarations
|
||||
etherent.c - /etc/ethers support routines
|
||||
extract.h - Alignment definitions
|
||||
ethertype.h - Ethernet protocol types and names definitions
|
||||
fad-getad.c - pcap_findalldevs() for systems with getifaddrs()
|
||||
fad-gifc.c - pcap_findalldevs() for systems with only SIOCGIFLIST
|
||||
fad-glifc.c - pcap_findalldevs() for systems with SIOCGLIFCONF
|
||||
fmtutils.c - error message formatting routines
|
||||
fmtutils.h - error message formatting prototypes
|
||||
ftmacros.h - feature test macros
|
||||
testprogs/filtertest.c - test program for BPF compiler
|
||||
testprogs/findalldevstest.c - test program for pcap_findalldevs()
|
||||
gencode.c - BPF code generation routines
|
||||
@ -224,54 +243,107 @@ in `/usr/include/sys/dlpi.h`, and find the corresponding value.
|
||||
grammar.y - filter string grammar
|
||||
ieee80211.h - 802.11 definitions
|
||||
install-sh - BSD style install script
|
||||
instrument-functions.c - functions instrumentation calls for entry/exit
|
||||
lbl/os-*.h - OS-dependent defines and prototypes
|
||||
llc.h - 802.2 LLC SAP definitions
|
||||
missing/* - replacements for missing library functions
|
||||
mkdep - construct Makefile dependency list
|
||||
msdos/* - drivers for MS-DOS capture support
|
||||
nametoaddr.c - hostname to address routines
|
||||
nametoaddr.h - hostname to address prototypes
|
||||
nlpid.h - OSI network layer protocol identifier definitions
|
||||
optimize.c - BPF optimization routines
|
||||
optimize.h - BPF optimization prototypes
|
||||
pcap/bluetooth.h - public definition of DLT_BLUETOOTH_HCI_H4_WITH_PHDR header
|
||||
pcap/bpf.h - BPF definitions
|
||||
pcap/can_socketcan.h - SocketCAN header
|
||||
pcap/compiler-tests.h - compiler version comparison and other macros
|
||||
pcap/dlt.h - Link-layer header type codes.
|
||||
pcap/funcattrs.h - function attribute macros
|
||||
pcap/ipnet.h - Solaris IPnet definitions
|
||||
pcap/namedb.h - public libpcap name database definitions
|
||||
pcap/nflog.h - NFLOG-related definitions
|
||||
pcap/pcap.h - public libpcap definitions
|
||||
pcap/pcap-inttypes.h - header for OS-specific integer type includes
|
||||
pcap/sll.h - public definitions of DLT_LINUX_SLL and DLT_LINUX_SLL2 headers
|
||||
pcap/socket.h - IP sockets support for various OSes
|
||||
pcap/usb.h - public definition of DLT_USB header
|
||||
pcap/vlan.h - VLAN-specific definitions
|
||||
pcap-airpcap.c - AirPcap device capture support
|
||||
pcap-airpcap.h - AirPcap device capture support
|
||||
pcap-bpf.c - BSD Packet Filter support
|
||||
pcap-bpf.h - header for backwards compatibility
|
||||
pcap-bt-linux.c - Bluetooth capture support for Linux
|
||||
pcap-bt-linux.h - Bluetooth capture support for Linux
|
||||
pcap-bt-monitor-linux.c - Bluetooth monitor capture support for Linux
|
||||
pcap-bt-monitor-linux.h - Bluetooth monitor capture support for Linux
|
||||
pcap-common.c - common code for pcap and pcapng files
|
||||
pcap-common.h - common code for pcap and pcapng files
|
||||
pcap-dag.c - Endace DAG device capture support
|
||||
pcap-dag.h - Endace DAG device capture support
|
||||
pcap-dbus.c - D-Bus capture support
|
||||
pcap-dbus.h - D-Bus capture support
|
||||
pcap-dlpi.c - Data Link Provider Interface support
|
||||
pcap-dos.c - MS-DOS capture support
|
||||
pcap-dos.h - headers for MS-DOS capture support
|
||||
pcap-dpdk.c - DPDK device support
|
||||
pcap-dpdk.h - DPDK device support
|
||||
pcap-enet.c - enet support
|
||||
pcap-haiku.c - Haiku capture support
|
||||
pcap-int.h - internal libpcap definitions
|
||||
pcap-libdlpi.c - Data Link Provider Interface support for systems with libdlpi
|
||||
pcap-linux.c - Linux packet socket support
|
||||
pcap-namedb.h - header for backwards compatibility
|
||||
pcap-netfilter-linux.c - Linux netfilter support
|
||||
pcap-netfilter-linux.h - Linux netfilter support
|
||||
pcap-netmap.c - netmap support
|
||||
pcap-netmap.h - netmap support
|
||||
pcap-nit.c - SunOS Network Interface Tap support
|
||||
pcap-npf.c - Npcap capture support
|
||||
pcap-null.c - dummy monitor support (allows offline use of libpcap)
|
||||
pcap-pf.c - Ultrix and Digital/Tru64 UNIX Packet Filter support
|
||||
pcap-rdmasniff.c - RDMA/InfiniBand capture support
|
||||
pcap-rdmasniff.h - RDMA/InfiniBand capture support
|
||||
pcap-rpcap.c - RPCAP protocol capture support
|
||||
pcap-rpcap.h - RPCAP protocol capture support
|
||||
pcap-septel.c - Intel/Septel device capture support
|
||||
pcap-septel.h - Intel/Septel device capture support
|
||||
pcap-sita.c - SITA device capture support
|
||||
pcap-sita.h - SITA device capture support
|
||||
pcap-sita.html - SITA device capture documentation
|
||||
pcap-snf.c - Myricom SNF device capture support
|
||||
pcap-snf.h - Myricom SNF device capture support
|
||||
pcap-snit.c - SunOS 4.x STREAMS-based Network Interface Tap support
|
||||
pcap-snoop.c - IRIX Snoop network monitoring support
|
||||
pcap-tc.c - TurboCap device capture support
|
||||
pcap-tc.h - TurboCap device capture support
|
||||
pcap-types.h - header for OS-specific type includes
|
||||
pcap-usb-linux.c - USB capture support for Linux
|
||||
pcap-usb-linux.h - USB capture support for Linux
|
||||
pcap-usb-linux-common.c - Linux USB common routines
|
||||
pcap-usb-linux-common.h - Linux USB common prototypes
|
||||
pcap-util.c - common code for various files
|
||||
pcap-util.h - common code for various files
|
||||
pcap.3pcap - manual entry for the library
|
||||
pcap.c - pcap utility routines
|
||||
pcap.h - header for backwards compatibility
|
||||
pcap_*.3pcap - manual entries for library functions
|
||||
pcap-filter.manmisc.in - manual entry for filter syntax
|
||||
pcap-linktype.manmisc.in - manual entry for link-layer header types
|
||||
pflog.h - header for DLT_PFLOG handling in filter code
|
||||
portability.h - Portability declarations/definitions
|
||||
ppp.h - Point to Point Protocol definitions
|
||||
rpcap-protocol.c - RPCAP client/server common routines
|
||||
rpcap-protocol.h - RPCAP client/server common prototypes
|
||||
savefile.c - offline support
|
||||
scanner.l - filter string scanner
|
||||
sf-pcap.c - routines for .pcap savefiles
|
||||
sf-pcap.h - prototypes for .pcap savefiles
|
||||
sf-pcapng.c - routines for .pcapng savefiles
|
||||
sf-pcapng.h - prototypes for .pcapng savefiles
|
||||
sockutils.c - socket and name lookup API routines
|
||||
sockutils.h - socket and name lookup API prototypes
|
||||
sslutils.c - OpenSSL interface routines
|
||||
sslutils.h - OpenSSL interface prototypes
|
||||
sunatmpos.h - definitions for SunATM capturing
|
||||
varattrs.h - variable attribute macros
|
||||
|
@ -70,7 +70,6 @@ INSTALL_RPCAPD=@INSTALL_RPCAPD@
|
||||
|
||||
# Standard CFLAGS for building members of a shared library
|
||||
FULL_CFLAGS = $(CCOPT) @V_LIB_CCOPT_FAT@ $(SHLIB_CCOPT) $(INCLS) $(DEFS) $(CFLAGS)
|
||||
CXXFLAGS = $(CCOPT) @V_LIB_CCOPT_FAT@ $(SHLIB_CCOPT) $(INCLS) $(DEFS) $(CFLAGS)
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
@ -88,24 +87,22 @@ BISON_BYACC = @BISON_BYACC@
|
||||
$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
|
||||
|
||||
PLATFORM_C_SRC = @PLATFORM_C_SRC@
|
||||
PLATFORM_CXX_SRC = @PLATFORM_CXX_SRC@
|
||||
MODULE_C_SRC = @MODULE_C_SRC@
|
||||
REMOTE_C_SRC = @REMOTE_C_SRC@
|
||||
COMMON_C_SRC = pcap.c gencode.c optimize.c nametoaddr.c etherent.c \
|
||||
fmtutils.c pcap-util.c \
|
||||
savefile.c sf-pcap.c sf-pcapng.c pcap-common.c \
|
||||
pcap-usb-linux-common.c bpf_image.c bpf_filter.c bpf_dump.c
|
||||
bpf_image.c bpf_filter.c bpf_dump.c
|
||||
GENERATED_C_SRC = scanner.c grammar.c
|
||||
LIBOBJS = @LIBOBJS@
|
||||
|
||||
SRC = $(PLATFORM_C_SRC) $(PLATFORM_CXX_SRC) \
|
||||
SRC = $(PLATFORM_C_SRC) \
|
||||
$(MODULE_C_SRC) $(REMOTE_C_SRC) $(COMMON_C_SRC) \
|
||||
$(GENERATED_C_SRC)
|
||||
|
||||
# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
|
||||
# hack the extra indirection, and we have to handle PLATFORM_CXX_SRC
|
||||
# differently from the defines for C source
|
||||
OBJ = $(PLATFORM_C_SRC:.c=.o) $(PLATFORM_CXX_SRC:.cpp=.o) \
|
||||
# hack the extra indirection
|
||||
OBJ = $(PLATFORM_C_SRC:.c=.o) \
|
||||
$(MODULE_C_SRC:.c=.o) $(REMOTE_C_SRC:.c=.o) $(COMMON_C_SRC:.c=.o) \
|
||||
$(GENERATED_C_SRC:.c=.o) \
|
||||
$(LIBOBJS)
|
||||
@ -157,6 +154,7 @@ HDR = $(PUBHDR) \
|
||||
sf-pcap.h \
|
||||
sf-pcapng.h \
|
||||
sunatmpos.h \
|
||||
thread-local.h \
|
||||
varattrs.h
|
||||
|
||||
GENHDR = \
|
||||
@ -167,7 +165,7 @@ TAGFILES = \
|
||||
|
||||
CLEANFILES = $(OBJ) libpcap.a libpcap.so.`cat $(srcdir)/VERSION` \
|
||||
$(PROG)-`cat $(srcdir)/VERSION`.tar.gz $(GENERATED_C_SRC) $(GENHDR) \
|
||||
lex.yy.c pcap-config libpcap.pc
|
||||
lex.yy.c pcap-config libpcap.pc libpcap.$(DYEXT)
|
||||
|
||||
MAN1 = pcap-config.1
|
||||
|
||||
@ -254,19 +252,21 @@ EXTRA_DIST = \
|
||||
Makefile.in \
|
||||
Makefile-devel-adds \
|
||||
README.md \
|
||||
doc/README.Win32.md \
|
||||
doc/README.aix \
|
||||
doc/README.dag \
|
||||
doc/README.haiku.md \
|
||||
doc/README.hpux \
|
||||
doc/README.linux \
|
||||
doc/README.macos \
|
||||
doc/README.septel \
|
||||
doc/README.sita \
|
||||
doc/README.solaris.md \
|
||||
doc/README.windows.md \
|
||||
CONTRIBUTING.md \
|
||||
TODO \
|
||||
VERSION \
|
||||
aclocal.m4 \
|
||||
autogen.sh \
|
||||
charconv.c \
|
||||
charconv.h \
|
||||
chmod_bpf \
|
||||
@ -282,9 +282,7 @@ EXTRA_DIST = \
|
||||
cmake/Modules/FindTC.cmake \
|
||||
cmake/have_siocglifconf.c \
|
||||
config.guess \
|
||||
config.h.in \
|
||||
config.sub \
|
||||
configure \
|
||||
configure.ac \
|
||||
dlpisubs.c \
|
||||
dlpisubs.h \
|
||||
@ -340,7 +338,7 @@ EXTRA_DIST = \
|
||||
pcap-dpdk.c \
|
||||
pcap-dpdk.h \
|
||||
pcap-enet.c \
|
||||
pcap-haiku.cpp \
|
||||
pcap-haiku.c \
|
||||
pcap-int.h \
|
||||
pcap-libdlpi.c \
|
||||
pcap-linux.c \
|
||||
@ -357,7 +355,6 @@ EXTRA_DIST = \
|
||||
pcap-rdmasniff.c \
|
||||
pcap-rdmasniff.h \
|
||||
pcap-rpcap.c \
|
||||
pcap-rpcap-int.h \
|
||||
pcap-septel.c \
|
||||
pcap-septel.h \
|
||||
pcap-sita.h \
|
||||
@ -423,7 +420,7 @@ EXTRA_DIST = \
|
||||
testprogs/visopts.py \
|
||||
testprogs/writecaptest.c
|
||||
|
||||
TEST_DIST = `git ls-files tests | grep -v 'tests/\..*'`
|
||||
TEST_DIST = `git -C "$$DIR" ls-files tests | grep -v 'tests/\..*'`
|
||||
|
||||
RELEASE_FILES = $(COMMON_C_SRC) $(HDR) $(MAN1) $(MAN3PCAP_EXPAND) \
|
||||
$(MAN3PCAP_NOEXPAND) $(MANFILE) $(MANMISC) $(EXTRA_DIST) \
|
||||
@ -536,7 +533,7 @@ scanner.o: scanner.c grammar.h
|
||||
#
|
||||
# and this is an explicit target entry.
|
||||
#
|
||||
# Therefore, instead of using $<, we explicitly put in $(srcdir)/libpcap.pc.in.
|
||||
# Therefore, instead of using $<, we explicitly put in $(srcdir)/grammar.y.in.
|
||||
#
|
||||
grammar.y: $(srcdir)/grammar.y.in ./config.status
|
||||
@rm -f $@ $@.tmp
|
||||
@ -610,8 +607,8 @@ build-rpcapd: libpcap.a
|
||||
#
|
||||
# Test programs - not built by default, and not installed.
|
||||
#
|
||||
testprogs: FORCE
|
||||
(cd testprogs; $(MAKE))
|
||||
testprogs: FORCE libpcap.a
|
||||
(cd testprogs; $(MAKE) CFLAGS="$(CFLAGS)")
|
||||
|
||||
FORCE:
|
||||
|
||||
@ -716,31 +713,31 @@ install-shared-sl: libpcap.sl
|
||||
MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
|
||||
$(INSTALL_PROGRAM) libpcap.$$MAJOR_VER $(DESTDIR)$(libdir)
|
||||
ln -sf libpcap.$$MAJOR_VER $(DESTDIR)$(libdir)/libpcap.sl
|
||||
#
|
||||
# AIX shared libraries are weird. They're archive libraries
|
||||
# with one or more shared object components.
|
||||
#
|
||||
install-shared-shareda: libpcap.shareda
|
||||
#
|
||||
# AIX shared libraries are weird. They're archive libraries
|
||||
# with one or more shared object components.
|
||||
#
|
||||
[ -d $(DESTDIR)$(libdir) ] || \
|
||||
(mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
|
||||
$(INSTALL_PROGRAM) libpcap.shareda $(DESTDIR)$(libdir)/libpcap.a
|
||||
install-shared-none:
|
||||
|
||||
install-archive: install-archive-$(DYEXT)
|
||||
#
|
||||
# Most platforms have separate suffixes for shared and
|
||||
# archive libraries, so we install both.
|
||||
#
|
||||
install-archive-so install-archive-dylib install-archive-sl install-archive-none: libpcap.a
|
||||
#
|
||||
# Most platforms have separate suffixes for shared and
|
||||
# archive libraries, so we install both.
|
||||
#
|
||||
[ -d $(DESTDIR)$(libdir) ] || \
|
||||
(mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
|
||||
$(INSTALL_DATA) libpcap.a $(DESTDIR)$(libdir)/libpcap.a
|
||||
$(RANLIB) $(DESTDIR)$(libdir)/libpcap.a
|
||||
#
|
||||
# AIX, however, doesn't, so we don't install the archive
|
||||
# library on AIX.
|
||||
#
|
||||
install-archive-shareda:
|
||||
#
|
||||
# AIX, however, doesn't, so we don't install the archive
|
||||
# library on AIX.
|
||||
#
|
||||
|
||||
install-rpcapd:
|
||||
(cd rpcapd; $(MAKE) DESTDIR=$(DESTDIR) install)
|
||||
@ -803,14 +800,13 @@ uninstall-rpcapd:
|
||||
(cd rpcapd; $(MAKE) DESTDIR=$(DESTDIR) uninstall)
|
||||
|
||||
clean:
|
||||
rm -f $(CLEANFILES)
|
||||
rm -f $(CLEANFILES) config.h.in~ configure~ configure.ac~
|
||||
(cd rpcapd; $(MAKE) clean)
|
||||
(cd testprogs; $(MAKE) clean)
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile grammar.y config.cache config.log config.status \
|
||||
config.h config.h.in~ configure~ configure.ac~ \
|
||||
net os-proto.h libpcap.pc pcap-config stamp-h stamp-h.in
|
||||
config.h os-proto.h libpcap.pc pcap-config stamp-h stamp-h.in
|
||||
rm -f $(MAN3PCAP_EXPAND:.in=) $(MANFILE:.in=) $(MANMISC:.in=)
|
||||
rm -rf autom4te.cache
|
||||
(cd rpcapd; $(MAKE) distclean)
|
||||
@ -822,22 +818,116 @@ extags: $(TAGFILES)
|
||||
tags: $(TAGFILES)
|
||||
ctags -wtd $(TAGFILES)
|
||||
|
||||
#
|
||||
# Use git archive piped to tar to construct a subdirectory whose name
|
||||
# is libpcap-{release}, containing all the checked-in source files,
|
||||
# and then run autoreconf in that directory to generate the configure
|
||||
# script and other files from that source. Then remove autom4te.cache,
|
||||
# construct the release tarball from that subdirectory, and remove
|
||||
# the subdirectory.
|
||||
#
|
||||
# The --format=tar is to force git archive to write a non-compressed
|
||||
# archive, in case the platform's tar command doesn't have built-in
|
||||
# decompression.
|
||||
#
|
||||
# The ^{tree} is there to force git archive not to write out the
|
||||
# "helpful" global extended pax header with a commit ID, as not all
|
||||
# versions of tar can handle that (Solaris tar can't, for example).
|
||||
# (It turns HEAD, or a tag, both of which are apparently "tree-ish"es,
|
||||
# into a tree; apparently, unlike HEAD, or a tag, which have a commit
|
||||
# ID associated with them, the tree associated with them doesn't have
|
||||
# a commit ID, so no commit ID is available to write, and thus
|
||||
# git archive doesn't write one.)
|
||||
#
|
||||
releasetar:
|
||||
@TAG=$(PROG)-`cat VERSION` && \
|
||||
if git show-ref --tags --quiet --verify -- "refs/tags/$$TAG"; then \
|
||||
git archive --prefix="$$TAG"/ -o "$$TAG".tar.gz "$$TAG" \
|
||||
$(RELEASE_FILES) && \
|
||||
if [ ! -d .git ]; then echo 'Not in a git clone, stop.'; exit 1; fi && \
|
||||
TMPTESTFILE=`mktemp -t tmptestfile_XXXXXXXX` && \
|
||||
rm -f "$$TMPTESTFILE" && \
|
||||
AUTORECONF_DIR=`dirname "$$TMPTESTFILE"`/"$(PROG)"_build_autoreconf_$$$$ && \
|
||||
DIR=`pwd` && \
|
||||
rm -rf "$$AUTORECONF_DIR" && \
|
||||
mkdir "$$AUTORECONF_DIR" && \
|
||||
cd "$$AUTORECONF_DIR" && \
|
||||
if git -C "$$DIR" show-ref --tags --quiet --verify -- "refs/tags/$$TAG"; then \
|
||||
(git -C "$$DIR" archive --format=tar --prefix="$$TAG"/ "$$TAG^{tree}" $(RELEASE_FILES) | \
|
||||
tar xf -) && \
|
||||
echo "Archive build from tag $$TAG."; \
|
||||
else \
|
||||
git archive --prefix="$$TAG"/ -o "$$TAG".tar.gz HEAD \
|
||||
$(RELEASE_FILES) && \
|
||||
(git -C "$$DIR" archive --format=tar --prefix="$$TAG"/ "HEAD^{tree}" $(RELEASE_FILES) | \
|
||||
tar xf -) && \
|
||||
echo "No $$TAG tag. Archive build from HEAD."; \
|
||||
fi && \
|
||||
(cd "$$TAG" && "$${AUTORECONF:-autoreconf}" && rm -rf autom4te.cache) && \
|
||||
tar cf "$$DIR/$$TAG".tar "$$TAG" && \
|
||||
rm -f "$$DIR/$$TAG".tar.gz && \
|
||||
gzip --best "$$DIR/$$TAG".tar && \
|
||||
cd "$$DIR" && \
|
||||
rm -rf "$$AUTORECONF_DIR"
|
||||
|
||||
releasecheck: releasetar
|
||||
@TAG=$(PROG)-`cat VERSION` && \
|
||||
INSTALL_DIR=/tmp/install_"$$TAG"_$$$$ && \
|
||||
DIR=`pwd` && \
|
||||
cd /tmp && \
|
||||
rm -rf "$$TAG" && \
|
||||
rm -rf "$$INSTALL_DIR" && \
|
||||
tar xf "$$DIR"/"$$TAG".tar.gz && \
|
||||
cd "$$TAG" && \
|
||||
echo "[$@] $$ touch .devel" && \
|
||||
touch .devel && \
|
||||
echo "[$@] $$ ./configure --enable-remote --quiet --prefix=$$INSTALL_DIR" && \
|
||||
./configure --enable-remote --quiet --prefix="$$INSTALL_DIR" && \
|
||||
echo '[$@] $$ $(MAKE) -s all testprogs' && \
|
||||
$(MAKE) -s all testprogs && \
|
||||
echo '[$@] $$ $(MAKE) -s install' && \
|
||||
$(MAKE) -s install && \
|
||||
cd .. && \
|
||||
rm -rf "$$TAG" && \
|
||||
rm -rf "$$INSTALL_DIR" && \
|
||||
tar xf "$$DIR"/"$$TAG".tar.gz && \
|
||||
cd "$$TAG" && \
|
||||
echo "[$@] $$ touch .devel" && \
|
||||
touch .devel && \
|
||||
mkdir build && \
|
||||
cd build && \
|
||||
echo '[$@] $$ cmake -DENABLE_REMOTE=yes [...] ..' && \
|
||||
cmake -DENABLE_REMOTE=yes \
|
||||
-DCMAKE_INSTALL_PREFIX="$$INSTALL_DIR" \
|
||||
-DCMAKE_MESSAGE_LOG_LEVEL=NOTICE \
|
||||
-DCMAKE_RULE_MESSAGES=OFF \
|
||||
-DCMAKE_INSTALL_MESSAGE=NEVER \
|
||||
.. && \
|
||||
echo '[$@] $$ $(MAKE) -s all testprogs' && \
|
||||
$(MAKE) -s all testprogs && \
|
||||
echo '[$@] $$ $(MAKE) -s install' && \
|
||||
$(MAKE) -s install && \
|
||||
cd ../.. && \
|
||||
rm -rf "$$TAG" && \
|
||||
rm -rf "$$INSTALL_DIR" && \
|
||||
echo '[$@] Done.'
|
||||
|
||||
whitespacecheck:
|
||||
@# trailing space(s)?
|
||||
@if git grep -I -n ' $$' $$(git ls-files|grep -v '^tests/'); then \
|
||||
echo 'Error: Trailing space(s).'; \
|
||||
exit 1; \
|
||||
fi
|
||||
@# trailing tab(s)?
|
||||
@if git grep -I -n ' $$' $$(git ls-files|grep -v '^tests/'); then \
|
||||
echo 'Error: Trailing tabs(s).'; \
|
||||
exit 1; \
|
||||
fi
|
||||
@# space(s) before tab(s)?
|
||||
@if git grep -I -n '[ ][ ]' $$(git ls-files|grep -v '^tests/'); then \
|
||||
echo 'Error: space(s) before tab(s).'; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
depend: $(GENERATED_C_SRC) $(GENHDR)
|
||||
$(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
|
||||
$(MKDEP) -c $(CC) -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
|
||||
(cd rpcapd; $(MAKE) depend)
|
||||
(cd testprogs; $(MAKE) depend)
|
||||
|
||||
shellcheck:
|
||||
shellcheck -f gcc -e SC2006 build.sh build_matrix.sh build_common.sh
|
||||
shellcheck -f gcc -e SC2006 autogen.sh build.sh build_matrix.sh build_common.sh mkdep .ci-coverity-scan-build.sh
|
||||
|
@ -6,10 +6,6 @@ Important stuff (to be done before the next release)
|
||||
|
||||
General
|
||||
|
||||
- configure should not be in Git. Most open source projects have an
|
||||
autogen.sh script to run autoconf etc. after checkout. I think we
|
||||
should stick to the standard.
|
||||
|
||||
- The source files should be better documented. There is no official
|
||||
design guideline for what is done where. There should be a common coding
|
||||
style (okay, you can guess that by looking at the code) and a guide for
|
||||
@ -20,7 +16,6 @@ Less urgent items
|
||||
|
||||
- Better documentation and cleanup of the interface. I am seeing a few
|
||||
problems at the first glance which needs fixing:
|
||||
+ pcap_lookupnet makes little to no sense with protocols != IPv4
|
||||
+ not very well suited for interactive programs (think ethereal). There
|
||||
should be a way for the application to get a file descriptor which it
|
||||
has to monitor and a callback in pcap which has to be called on
|
||||
|
@ -1 +1 @@
|
||||
1.10.4
|
||||
1.10.5
|
||||
|
227
contrib/libpcap/aclocal.m4
vendored
227
contrib/libpcap/aclocal.m4
vendored
@ -296,7 +296,7 @@ AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
|
||||
# https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
|
||||
#
|
||||
# This may, as per those two messages, be fixed in autoconf 2.70,
|
||||
# but we only require 2.64 or newer for now.
|
||||
# but we only require 2.69 or newer for now.
|
||||
#
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE([[int main(void) { return 0; }]])],
|
||||
@ -836,21 +836,22 @@ AC_DEFUN(AC_LBL_DEVEL,
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -W)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma)
|
||||
# Warns about safeguards added in case the enums are
|
||||
# extended
|
||||
# AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
|
||||
# Warns about safeguards added in case the enums are
|
||||
# extended
|
||||
# AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
|
||||
#
|
||||
# This can cause problems with ntohs(), ntohl(),
|
||||
# htons(), and htonl() on some platforms, such
|
||||
@ -863,7 +864,7 @@ AC_DEFUN(AC_LBL_DEVEL,
|
||||
# on whether it is, does a compile-time swap or
|
||||
# a run-time swap; perhaps the compiler always
|
||||
# considers one of the two results of the
|
||||
# conditional expressin is never evaluated,
|
||||
# conditional expression is never evaluated,
|
||||
# because the conditional check is done at
|
||||
# compile time, and thus always says "that
|
||||
# expression is never executed".
|
||||
@ -886,7 +887,10 @@ testme(unsigned short a)
|
||||
}
|
||||
],
|
||||
[generates warnings from ntohs()])
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
|
||||
AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
|
||||
fi
|
||||
AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
|
||||
#
|
||||
@ -975,35 +979,44 @@ fi
|
||||
dnl
|
||||
dnl AC_LBL_LIBRARY_NET
|
||||
dnl
|
||||
dnl This test is for network applications that need socket functions and
|
||||
dnl getaddrinfo()/getnameinfo()-ish functions. We now require
|
||||
dnl getaddrinfo() and getnameinfo(). We also prefer versions of
|
||||
dnl recvmsg() that conform to the Single UNIX Specification, so that we
|
||||
dnl can check whether a datagram received with recvmsg() was truncated
|
||||
dnl when received due to the buffer being too small.
|
||||
dnl Look for various networking-related libraries that we may need.
|
||||
dnl
|
||||
dnl On most operating systems, they're available in the system library.
|
||||
dnl We need getaddrinfo() to translate host names in filters to IP
|
||||
dnl addresses. We use getaddrinfo() because we want a portable
|
||||
dnl thread-safe way of getting information for a host name or port;
|
||||
dnl there exist _r versions of gethostbyname() and getservbyname() on
|
||||
dnl some platforms, but not on all platforms.
|
||||
dnl
|
||||
dnl Under Solaris, we need to link with libsocket and libnsl to get
|
||||
dnl getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
|
||||
dnl link with libxnet before libsocket to get a version of recvmsg()
|
||||
dnl that conforms to the Single UNIX Specification.
|
||||
dnl We may also need socket() and other socket functions to support:
|
||||
dnl
|
||||
dnl We use getaddrinfo() because we want a portable thread-safe way
|
||||
dnl of getting information for a host name or port; there exist _r
|
||||
dnl versions of gethostbyname() and getservbyname() on some platforms,
|
||||
dnl but not on all platforms.
|
||||
dnl Local packet capture with capture mechanisms that use sockets.
|
||||
dnl
|
||||
dnl Local capture device enumeration if a socket call is needed to
|
||||
dnl enumerate devices or get device attributes.
|
||||
dnl
|
||||
dnl Packet capture from services that put captured packets on the
|
||||
dnl network, such as rpcap servers.
|
||||
dnl
|
||||
dnl We may also need getnameinfo() for packet capture from services
|
||||
dnl that put packets on the network.
|
||||
dnl
|
||||
AC_DEFUN(AC_LBL_LIBRARY_NET, [
|
||||
#
|
||||
# Most operating systems have getaddrinfo() in the default searched
|
||||
# libraries (i.e. libc). Check there first.
|
||||
# Most operating systems have getaddrinfo(), and the other routines
|
||||
# we may need, in the default searched libraries (e.g., libc).
|
||||
# Check there first.
|
||||
#
|
||||
AC_CHECK_FUNC(getaddrinfo,,
|
||||
[
|
||||
#
|
||||
# Not found in the standard system libraries.
|
||||
# Try libsocket, which requires libnsl.
|
||||
#
|
||||
# In some versions of Solaris, we need to link with libsocket
|
||||
# and libnsl, so check in libsocket and also link with liblnsl
|
||||
# when doing this test.
|
||||
#
|
||||
# Linking with libsocket and libnsl will find all the routines
|
||||
# we need.
|
||||
#
|
||||
AC_CHECK_LIB(socket, getaddrinfo,
|
||||
[
|
||||
@ -1017,6 +1030,9 @@ AC_DEFUN(AC_LBL_LIBRARY_NET, [
|
||||
# Not found in libsocket; test for it in libnetwork, which
|
||||
# is where it is in Haiku.
|
||||
#
|
||||
# Linking with libnetwork will find all the routines we
|
||||
# need.
|
||||
#
|
||||
AC_CHECK_LIB(network, getaddrinfo,
|
||||
[
|
||||
#
|
||||
@ -1033,18 +1049,36 @@ AC_DEFUN(AC_LBL_LIBRARY_NET, [
|
||||
], -lnsl)
|
||||
|
||||
#
|
||||
# OK, do we have recvmsg() in libxnet?
|
||||
# We also link with libsocket and libnsl.
|
||||
# We require a version of recvmsg() that conforms to the Single
|
||||
# UNIX Specification, so that we can check whether a datagram
|
||||
# received with recvmsg() was truncated when received due to the
|
||||
# buffer being too small.
|
||||
#
|
||||
# On most systems, the version of recvmsg() in the libraries
|
||||
# found above conforms to the SUS.
|
||||
#
|
||||
# On at least some versions of Solaris, it does not conform to
|
||||
# the SUS, and we need the version in libxnet, which does
|
||||
# conform.
|
||||
#
|
||||
# Check whether libxnet exists and has a version of recvmsg();
|
||||
# if it does, link with libxnet before we link with libsocket,
|
||||
# to get that version.
|
||||
#
|
||||
# This test also links with libsocket and libnsl.
|
||||
#
|
||||
AC_CHECK_LIB(xnet, recvmsg,
|
||||
[
|
||||
#
|
||||
# Yes - link with it as well.
|
||||
# libxnet has recvmsg(); link with it as well.
|
||||
#
|
||||
LIBS="-lxnet $LIBS"
|
||||
], , -lsocket -lnsl)
|
||||
])
|
||||
# DLPI needs putmsg under HPUX so test for -lstr while we're at it
|
||||
|
||||
#
|
||||
# DLPI needs putmsg under HP-UX, so test for -lstr while we're at it.
|
||||
#
|
||||
AC_SEARCH_LIBS(putmsg, str)
|
||||
])
|
||||
|
||||
@ -1128,12 +1162,12 @@ if test -n "$PKG_CONFIG"; then
|
||||
fi[]dnl
|
||||
])dnl PKG_PROG_PKG_CONFIG
|
||||
|
||||
dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl -------------------------------------------------------------------
|
||||
dnl Since: 0.18
|
||||
dnl
|
||||
dnl Check to see whether a particular set of modules exists. Similar to
|
||||
dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
|
||||
dnl Check to see whether a particular module exists. Similar to
|
||||
dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
|
||||
AC_DEFUN([PKG_CHECK_EXISTS],
|
||||
[
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
@ -1143,7 +1177,34 @@ m4_ifvaln([$3], [else
|
||||
$3])dnl
|
||||
fi])
|
||||
|
||||
dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULES])
|
||||
dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
|
||||
dnl ---------------------------------------------
|
||||
dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
|
||||
dnl pkg-config fails, reporting the error and quitting.
|
||||
m4_define([_PKG_CONFIG_WITH_FLAGS],
|
||||
[if test ! -n "$$1"; then
|
||||
$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
|
||||
if test "x$?" != "x0"; then
|
||||
#
|
||||
# That failed - report an error.
|
||||
# Re-run the command, telling pkg-config to print an error
|
||||
# message, capture the error message, and report it.
|
||||
# This causes the configuration script to fail, as it means
|
||||
# the script is almost certainly doing something wrong.
|
||||
#
|
||||
_PKG_SHORT_ERRORS_SUPPORTED
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
_pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
|
||||
else
|
||||
_pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
|
||||
fi
|
||||
AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
|
||||
fi
|
||||
fi[]dnl
|
||||
])dnl _PKG_CONFIG_WITH_FLAGS
|
||||
|
||||
|
||||
dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
|
||||
dnl ---------------------------------------------
|
||||
dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
|
||||
dnl pkg_failed based on the result.
|
||||
@ -1173,97 +1234,55 @@ fi[]dnl
|
||||
])dnl _PKG_SHORT_ERRORS_SUPPORTED
|
||||
|
||||
|
||||
dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
|
||||
dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
|
||||
dnl [ACTION-IF-NOT-FOUND])
|
||||
dnl --------------------------------------------------------------
|
||||
dnl Since: 0.4.0
|
||||
AC_DEFUN([PKG_CHECK_MODULES],
|
||||
AC_DEFUN([PKG_CHECK_MODULE],
|
||||
[
|
||||
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
|
||||
|
||||
pkg_failed=no
|
||||
AC_MSG_CHECKING([for $2 with pkg-config])
|
||||
PKG_CHECK_EXISTS($2,
|
||||
[
|
||||
if test -n "$PKG_CONFIG"; then
|
||||
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
|
||||
|
||||
if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
|
||||
#
|
||||
# The package was found, so try to get its C flags and
|
||||
# libraries.
|
||||
#
|
||||
_PKG_CONFIG([$1][_CFLAGS], [--cflags], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS], [--libs], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS_STATIC], [--libs --static], [$2])
|
||||
|
||||
m4_define([_PKG_TEXT], [
|
||||
Alternatively, you may set the environment variables $1[]_CFLAGS
|
||||
and $1[]_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details.])
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
#
|
||||
# That failed - report an error.
|
||||
#
|
||||
AC_MSG_RESULT([error])
|
||||
_PKG_SHORT_ERRORS_SUPPORTED
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
|
||||
else
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
|
||||
|
||||
m4_default([$4], [AC_MSG_ERROR(
|
||||
[Package requirements ($2) were not met:
|
||||
|
||||
$$1_PKG_ERRORS
|
||||
|
||||
Consider adjusting the PKG_CONFIG_PATH environment variable if you
|
||||
installed software in a non-standard prefix.
|
||||
|
||||
_PKG_TEXT])[]dnl
|
||||
])
|
||||
elif test $pkg_failed = untried; then
|
||||
#
|
||||
# We don't have pkg-config, so it didn't work.
|
||||
#
|
||||
AC_MSG_RESULT([not found (pkg-config not found)])
|
||||
else
|
||||
#
|
||||
# We found the package.
|
||||
#
|
||||
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
|
||||
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
|
||||
$1[]_LIBS_STATIC=$pkg_cv_[]$1[]_LIBS_STATIC
|
||||
AC_MSG_RESULT([found])
|
||||
$3
|
||||
fi[]dnl
|
||||
],
|
||||
[
|
||||
#
|
||||
# The package isn't present.
|
||||
#
|
||||
AC_MSG_RESULT([not found])
|
||||
])
|
||||
])dnl PKG_CHECK_MODULES
|
||||
AC_MSG_RESULT([found])
|
||||
_PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
|
||||
_PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
|
||||
_PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
|
||||
m4_default([$3], [:])
|
||||
else
|
||||
AC_MSG_RESULT([not found])
|
||||
m4_default([$4], [:])
|
||||
fi
|
||||
else
|
||||
# No pkg-config, so obviously not found with pkg-config.
|
||||
AC_MSG_RESULT([pkg-config not found])
|
||||
m4_default([$4], [:])
|
||||
fi
|
||||
])dnl PKG_CHECK_MODULE
|
||||
|
||||
|
||||
dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
|
||||
dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
|
||||
dnl [ACTION-IF-NOT-FOUND])
|
||||
dnl ---------------------------------------------------------------------
|
||||
dnl Since: 0.29
|
||||
dnl
|
||||
dnl Checks for existence of MODULES and gathers its build flags with
|
||||
dnl Checks for existence of MODULE and gathers its build flags with
|
||||
dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
|
||||
dnl and VARIABLE-PREFIX_LIBS from --libs.
|
||||
AC_DEFUN([PKG_CHECK_MODULES_STATIC],
|
||||
AC_DEFUN([PKG_CHECK_MODULE_STATIC],
|
||||
[
|
||||
_save_PKG_CONFIG=$PKG_CONFIG
|
||||
PKG_CONFIG="$PKG_CONFIG --static"
|
||||
PKG_CHECK_MODULES($@)
|
||||
PKG_CHECK_MODULE($@)
|
||||
PKG_CONFIG=$_save_PKG_CONFIG[]dnl
|
||||
])dnl PKG_CHECK_MODULES_STATIC
|
||||
])dnl PKG_CHECK_MODULE_STATIC
|
||||
|
||||
|
||||
dnl PKG_INSTALLDIR([DIRECTORY])
|
||||
|
@ -68,7 +68,7 @@
|
||||
#define B_BEARER 0x5e /* broadband bearer capability */
|
||||
#define B_LOWER 0x5f /* broadband lower information */
|
||||
#define CALLING_PARTY 0x6c /* calling party number */
|
||||
#define CALLED_PARTY 0x70 /* called party nmber */
|
||||
#define CALLED_PARTY 0x70 /* called party number */
|
||||
|
||||
#define Q2931 0x09
|
||||
|
||||
|
25
contrib/libpcap/autogen.sh
Executable file
25
contrib/libpcap/autogen.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
: "${AUTORECONF:=autoreconf}"
|
||||
|
||||
AUTORECONFVERSION=`$AUTORECONF --version 2>&1 | grep "^autoreconf" | sed 's/.*) *//'`
|
||||
|
||||
maj=`echo "$AUTORECONFVERSION" | cut -d. -f1`
|
||||
min=`echo "$AUTORECONFVERSION" | cut -d. -f2`
|
||||
# The minimum required version of autoconf is currently 2.69.
|
||||
if [ "$maj" = "" ] || [ "$min" = "" ] || \
|
||||
[ "$maj" -lt 2 ] || { [ "$maj" -eq 2 ] && [ "$min" -lt 69 ]; }; then
|
||||
cat >&2 <<-EOF
|
||||
Please install the 'autoconf' package version 2.69 or later.
|
||||
If version 2.69 or later is already installed and there is no
|
||||
autoconf default, it may be necessary to set the AUTORECONF
|
||||
environment variable to enable the one to use, like:
|
||||
AUTORECONF=autoreconf-2.69 ./autogen.sh
|
||||
or
|
||||
AUTORECONF=autoreconf-2.71 ./autogen.sh
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$AUTORECONF identification: $AUTORECONFVERSION"
|
||||
"$AUTORECONF" -f
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap.h>
|
||||
#include <stdio.h>
|
||||
|
@ -38,9 +38,7 @@
|
||||
* @(#)bpf.c 7.5 (Berkeley) 7/15/91
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
#include "pcap-types.h"
|
||||
@ -86,11 +84,11 @@ enum {
|
||||
*/
|
||||
#if defined(SKF_AD_VLAN_TAG_PRESENT)
|
||||
u_int
|
||||
pcap_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
|
||||
pcapint_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
|
||||
u_int wirelen, u_int buflen, const struct pcap_bpf_aux_data *aux_data)
|
||||
#else
|
||||
u_int
|
||||
pcap_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
|
||||
pcapint_filter_with_aux_data(const struct bpf_insn *pc, const u_char *p,
|
||||
u_int wirelen, u_int buflen, const struct pcap_bpf_aux_data *aux_data _U_)
|
||||
#endif
|
||||
{
|
||||
@ -388,10 +386,10 @@ DIAG_ON_DEFAULT_ONLY_SWITCH
|
||||
}
|
||||
|
||||
u_int
|
||||
pcap_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
||||
pcapint_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
||||
u_int buflen)
|
||||
{
|
||||
return pcap_filter_with_aux_data(pc, p, wirelen, buflen, NULL);
|
||||
return pcapint_filter_with_aux_data(pc, p, wirelen, buflen, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -406,7 +404,7 @@ pcap_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
||||
* Otherwise, a bogus program could easily crash the system.
|
||||
*/
|
||||
int
|
||||
pcap_validate_filter(const struct bpf_insn *f, int len)
|
||||
pcapint_validate_filter(const struct bpf_insn *f, int len)
|
||||
{
|
||||
u_int i, from;
|
||||
const struct bpf_insn *p;
|
||||
@ -536,11 +534,11 @@ u_int
|
||||
bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
|
||||
u_int buflen)
|
||||
{
|
||||
return pcap_filter(pc, p, wirelen, buflen);
|
||||
return pcapint_filter(pc, p, wirelen, buflen);
|
||||
}
|
||||
|
||||
int
|
||||
bpf_validate(const struct bpf_insn *f, int len)
|
||||
{
|
||||
return pcap_validate_filter(f, len);
|
||||
return pcapint_validate_filter(f, len);
|
||||
}
|
||||
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap-types.h>
|
||||
|
||||
@ -44,6 +42,8 @@
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "thread-local.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
@ -130,7 +130,7 @@ char *
|
||||
bpf_image(const struct bpf_insn *p, int n)
|
||||
{
|
||||
const char *op;
|
||||
static char image[256];
|
||||
static thread_local char image[256];
|
||||
char operand_buf[64];
|
||||
const char *operand;
|
||||
|
||||
|
@ -185,14 +185,14 @@ utf_8_to_acp_truncated(char *errbuf)
|
||||
|
||||
/*
|
||||
* Now, convert that to the local code page.
|
||||
* Use the current thread's code page. For unconvertable
|
||||
* Use the current thread's code page. For unconvertible
|
||||
* characters, let it pick the "best fit" character.
|
||||
*
|
||||
* XXX - we'd like some way to do what utf_16le_to_utf_8_truncated()
|
||||
* does if the buffer isn't big enough, but we don't want to have
|
||||
* to handle all local code pages ourselves; doing so requires
|
||||
* knowledge of all those code pages, including knowledge of how
|
||||
* characters are formed in thoe code pages so that we can avoid
|
||||
* characters are formed in those code pages so that we can avoid
|
||||
* cutting a multi-byte character into pieces.
|
||||
*
|
||||
* Converting to an un-truncated string using Windows APIs, and
|
||||
|
@ -86,7 +86,7 @@ if(dpdk_FOUND)
|
||||
# Please keep this in mind when changing any CMake files,
|
||||
# and keep in mind what versions of CMake come with, for
|
||||
# example, commonly-used versions of commonly-used
|
||||
# Linux distributiions.)
|
||||
# Linux distributions.)
|
||||
#
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.19)
|
||||
if(NOT TARGET dpdk::cflags)
|
||||
|
@ -150,6 +150,9 @@
|
||||
/* On solaris */
|
||||
#cmakedefine HAVE_SOLARIS 1
|
||||
|
||||
/* target host supports Solaris "any" device */
|
||||
#cmakedefine HAVE_SOLARIS_ANY_DEVICE 1
|
||||
|
||||
/* define if we have the Solaris/IRIX getnetbyname_r() */
|
||||
#cmakedefine HAVE_SOLARIS_IRIX_GETNETBYNAME_R 1
|
||||
|
||||
@ -162,9 +165,6 @@
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#cmakedefine HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#cmakedefine HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#cmakedefine HAVE_STRINGS_H 1
|
||||
|
||||
|
62
contrib/libpcap/config.guess
vendored
62
contrib/libpcap/config.guess
vendored
@ -1,10 +1,10 @@
|
||||
#! /bin/sh
|
||||
# Attempt to guess a canonical system name.
|
||||
# Copyright 1992-2023 Free Software Foundation, Inc.
|
||||
# Copyright 1992-2024 Free Software Foundation, Inc.
|
||||
|
||||
# shellcheck disable=SC2006,SC2268 # see below for rationale
|
||||
|
||||
timestamp='2023-01-01'
|
||||
timestamp='2024-01-01'
|
||||
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
@ -47,7 +47,7 @@ me=`echo "$0" | sed -e 's,.*/,,'`
|
||||
usage="\
|
||||
Usage: $0 [OPTION]
|
||||
|
||||
Output the configuration name of the system \`$me' is run on.
|
||||
Output the configuration name of the system '$me' is run on.
|
||||
|
||||
Options:
|
||||
-h, --help print this help, then exit
|
||||
@ -60,13 +60,13 @@ version="\
|
||||
GNU config.guess ($timestamp)
|
||||
|
||||
Originally written by Per Bothner.
|
||||
Copyright 1992-2023 Free Software Foundation, Inc.
|
||||
Copyright 1992-2024 Free Software Foundation, Inc.
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
|
||||
|
||||
help="
|
||||
Try \`$me --help' for more information."
|
||||
Try '$me --help' for more information."
|
||||
|
||||
# Parse command line
|
||||
while test $# -gt 0 ; do
|
||||
@ -102,8 +102,8 @@ GUESS=
|
||||
# temporary files to be created and, as you can see below, it is a
|
||||
# headache to deal with in a portable fashion.
|
||||
|
||||
# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
|
||||
# use `HOST_CC' if defined, but it is deprecated.
|
||||
# Historically, 'CC_FOR_BUILD' used to be named 'HOST_CC'. We still
|
||||
# use 'HOST_CC' if defined, but it is deprecated.
|
||||
|
||||
# Portable tmp directory creation inspired by the Autoconf team.
|
||||
|
||||
@ -155,6 +155,9 @@ Linux|GNU|GNU/*)
|
||||
|
||||
set_cc_for_build
|
||||
cat <<-EOF > "$dummy.c"
|
||||
#if defined(__ANDROID__)
|
||||
LIBC=android
|
||||
#else
|
||||
#include <features.h>
|
||||
#if defined(__UCLIBC__)
|
||||
LIBC=uclibc
|
||||
@ -162,6 +165,8 @@ Linux|GNU|GNU/*)
|
||||
LIBC=dietlibc
|
||||
#elif defined(__GLIBC__)
|
||||
LIBC=gnu
|
||||
#elif defined(__LLVM_LIBC__)
|
||||
LIBC=llvm
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
/* First heuristic to detect musl libc. */
|
||||
@ -169,6 +174,7 @@ Linux|GNU|GNU/*)
|
||||
LIBC=musl
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
|
||||
eval "$cc_set_libc"
|
||||
@ -459,7 +465,7 @@ case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in
|
||||
UNAME_RELEASE=`uname -v`
|
||||
;;
|
||||
esac
|
||||
# Japanese Language versions have a version number like `4.1.3-JL'.
|
||||
# Japanese Language versions have a version number like '4.1.3-JL'.
|
||||
SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'`
|
||||
GUESS=sparc-sun-sunos$SUN_REL
|
||||
;;
|
||||
@ -904,7 +910,7 @@ EOF
|
||||
fi
|
||||
;;
|
||||
*:FreeBSD:*:*)
|
||||
UNAME_PROCESSOR=`/usr/bin/uname -p`
|
||||
UNAME_PROCESSOR=`uname -p`
|
||||
case $UNAME_PROCESSOR in
|
||||
amd64)
|
||||
UNAME_PROCESSOR=x86_64 ;;
|
||||
@ -976,7 +982,27 @@ EOF
|
||||
GUESS=$UNAME_MACHINE-unknown-minix
|
||||
;;
|
||||
aarch64:Linux:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
|
||||
set_cc_for_build
|
||||
CPU=$UNAME_MACHINE
|
||||
LIBCABI=$LIBC
|
||||
if test "$CC_FOR_BUILD" != no_compiler_found; then
|
||||
ABI=64
|
||||
sed 's/^ //' << EOF > "$dummy.c"
|
||||
#ifdef __ARM_EABI__
|
||||
#ifdef __ARM_PCS_VFP
|
||||
ABI=eabihf
|
||||
#else
|
||||
ABI=eabi
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'`
|
||||
eval "$cc_set_abi"
|
||||
case $ABI in
|
||||
eabi | eabihf) CPU=armv8l; LIBCABI=$LIBC$ABI ;;
|
||||
esac
|
||||
fi
|
||||
GUESS=$CPU-unknown-linux-$LIBCABI
|
||||
;;
|
||||
aarch64_be:Linux:*:*)
|
||||
UNAME_MACHINE=aarch64_be
|
||||
@ -1042,6 +1068,15 @@ EOF
|
||||
k1om:Linux:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
|
||||
;;
|
||||
kvx:Linux:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
|
||||
;;
|
||||
kvx:cos:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-cos
|
||||
;;
|
||||
kvx:mbr:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-mbr
|
||||
;;
|
||||
loongarch32:Linux:*:* | loongarch64:Linux:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-linux-$LIBC
|
||||
;;
|
||||
@ -1197,7 +1232,7 @@ EOF
|
||||
GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION
|
||||
;;
|
||||
i*86:OS/2:*:*)
|
||||
# If we were able to find `uname', then EMX Unix compatibility
|
||||
# If we were able to find 'uname', then EMX Unix compatibility
|
||||
# is probably installed.
|
||||
GUESS=$UNAME_MACHINE-pc-os2-emx
|
||||
;;
|
||||
@ -1338,7 +1373,7 @@ EOF
|
||||
GUESS=ns32k-sni-sysv
|
||||
fi
|
||||
;;
|
||||
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
|
||||
PENTIUM:*:4.0*:*) # Unisys 'ClearPath HMP IX 4000' SVR4/MP effort
|
||||
# says <Richard.M.Bartel@ccMail.Census.GOV>
|
||||
GUESS=i586-unisys-sysv4
|
||||
;;
|
||||
@ -1560,6 +1595,9 @@ EOF
|
||||
*:Unleashed:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE
|
||||
;;
|
||||
*:Ironclad:*:*)
|
||||
GUESS=$UNAME_MACHINE-unknown-ironclad
|
||||
;;
|
||||
esac
|
||||
|
||||
# Do we have a guess based on uname results?
|
||||
|
@ -6,6 +6,9 @@
|
||||
/* Enable optimizer debugging */
|
||||
#undef BDEBUG
|
||||
|
||||
/* define if you want to build the instrument functions code */
|
||||
#undef ENABLE_INSTRUMENT_FUNCTIONS
|
||||
|
||||
/* Define to 1 if remote packet capture is to be supported */
|
||||
#undef ENABLE_REMOTE
|
||||
|
||||
@ -102,9 +105,6 @@
|
||||
/* Define to 1 if you have the <linux/wireless.h> header file. */
|
||||
#undef HAVE_LINUX_WIRELESS_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <netpacket/packet.h> header file. */
|
||||
#undef HAVE_NETPACKET_PACKET_H
|
||||
|
||||
@ -156,6 +156,9 @@
|
||||
/* On solaris */
|
||||
#undef HAVE_SOLARIS
|
||||
|
||||
/* target host supports Solaris "any" device */
|
||||
#undef HAVE_SOLARIS_ANY_DEVICE
|
||||
|
||||
/* define if we have the Solaris/IRIX getnetbyname_r() */
|
||||
#undef HAVE_SOLARIS_IRIX_GETNETBYNAME_R
|
||||
|
||||
@ -165,12 +168,12 @@
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#undef HAVE_STDIO_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
@ -319,13 +322,15 @@
|
||||
/* target host supports RDMA sniffing */
|
||||
#undef PCAP_SUPPORT_RDMASNIFF
|
||||
|
||||
/* The size of `const void *', as computed by sizeof. */
|
||||
#undef SIZEOF_CONST_VOID_P
|
||||
/* The size of `time_t', as computed by sizeof. */
|
||||
#undef SIZEOF_TIME_T
|
||||
|
||||
/* The size of `void *', as computed by sizeof. */
|
||||
#undef SIZEOF_VOID_P
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
/* Define to 1 if all of the C90 standard headers exist (not just the ones
|
||||
required in a freestanding environment). This macro is provided for
|
||||
backward compatibility; new code need not use it. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to 1 if strings.h declares `ffs' */
|
||||
@ -341,11 +346,6 @@
|
||||
`char[]'. */
|
||||
#undef YYTEXT_POINTER
|
||||
|
||||
/* Enable large inode numbers on Mac OS X 10.5. */
|
||||
#ifndef _DARWIN_USE_64_BIT_INODE
|
||||
# define _DARWIN_USE_64_BIT_INODE 1
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
|
230
contrib/libpcap/config.sub
vendored
230
contrib/libpcap/config.sub
vendored
@ -1,10 +1,10 @@
|
||||
#! /bin/sh
|
||||
# Configuration validation subroutine script.
|
||||
# Copyright 1992-2023 Free Software Foundation, Inc.
|
||||
# Copyright 1992-2024 Free Software Foundation, Inc.
|
||||
|
||||
# shellcheck disable=SC2006,SC2268 # see below for rationale
|
||||
|
||||
timestamp='2023-01-21'
|
||||
timestamp='2024-01-01'
|
||||
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
@ -76,13 +76,13 @@ Report bugs and patches to <config-patches@gnu.org>."
|
||||
version="\
|
||||
GNU config.sub ($timestamp)
|
||||
|
||||
Copyright 1992-2023 Free Software Foundation, Inc.
|
||||
Copyright 1992-2024 Free Software Foundation, Inc.
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
|
||||
|
||||
help="
|
||||
Try \`$me --help' for more information."
|
||||
Try '$me --help' for more information."
|
||||
|
||||
# Parse command line
|
||||
while test $# -gt 0 ; do
|
||||
@ -130,7 +130,7 @@ IFS=$saved_IFS
|
||||
# Separate into logical components for further validation
|
||||
case $1 in
|
||||
*-*-*-*-*)
|
||||
echo Invalid configuration \`"$1"\': more than four components >&2
|
||||
echo "Invalid configuration '$1': more than four components" >&2
|
||||
exit 1
|
||||
;;
|
||||
*-*-*-*)
|
||||
@ -145,7 +145,8 @@ case $1 in
|
||||
nto-qnx* | linux-* | uclinux-uclibc* \
|
||||
| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
|
||||
| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
|
||||
| storm-chaos* | os2-emx* | rtmk-nova* | managarm-*)
|
||||
| storm-chaos* | os2-emx* | rtmk-nova* | managarm-* \
|
||||
| windows-* )
|
||||
basic_machine=$field1
|
||||
basic_os=$maybe_os
|
||||
;;
|
||||
@ -943,7 +944,7 @@ $basic_machine
|
||||
EOF
|
||||
IFS=$saved_IFS
|
||||
;;
|
||||
# We use `pc' rather than `unknown'
|
||||
# We use 'pc' rather than 'unknown'
|
||||
# because (1) that's what they normally are, and
|
||||
# (2) the word "unknown" tends to confuse beginning users.
|
||||
i*86 | x86_64)
|
||||
@ -1180,7 +1181,7 @@ case $cpu-$vendor in
|
||||
case $cpu in
|
||||
1750a | 580 \
|
||||
| a29k \
|
||||
| aarch64 | aarch64_be \
|
||||
| aarch64 | aarch64_be | aarch64c | arm64ec \
|
||||
| abacus \
|
||||
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
|
||||
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
|
||||
@ -1199,12 +1200,14 @@ case $cpu-$vendor in
|
||||
| d10v | d30v | dlx | dsp16xx \
|
||||
| e2k | elxsi | epiphany \
|
||||
| f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \
|
||||
| javascript \
|
||||
| h8300 | h8500 \
|
||||
| hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
|
||||
| hexagon \
|
||||
| i370 | i*86 | i860 | i960 | ia16 | ia64 \
|
||||
| ip2k | iq2000 \
|
||||
| k1om \
|
||||
| kvx \
|
||||
| le32 | le64 \
|
||||
| lm32 \
|
||||
| loongarch32 | loongarch64 \
|
||||
@ -1213,36 +1216,13 @@ case $cpu-$vendor in
|
||||
| m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
|
||||
| m88110 | m88k | maxq | mb | mcore | mep | metag \
|
||||
| microblaze | microblazeel \
|
||||
| mips | mipsbe | mipseb | mipsel | mipsle \
|
||||
| mips16 \
|
||||
| mips64 | mips64eb | mips64el \
|
||||
| mips64octeon | mips64octeonel \
|
||||
| mips64orion | mips64orionel \
|
||||
| mips64r5900 | mips64r5900el \
|
||||
| mips64vr | mips64vrel \
|
||||
| mips64vr4100 | mips64vr4100el \
|
||||
| mips64vr4300 | mips64vr4300el \
|
||||
| mips64vr5000 | mips64vr5000el \
|
||||
| mips64vr5900 | mips64vr5900el \
|
||||
| mipsisa32 | mipsisa32el \
|
||||
| mipsisa32r2 | mipsisa32r2el \
|
||||
| mipsisa32r3 | mipsisa32r3el \
|
||||
| mipsisa32r5 | mipsisa32r5el \
|
||||
| mipsisa32r6 | mipsisa32r6el \
|
||||
| mipsisa64 | mipsisa64el \
|
||||
| mipsisa64r2 | mipsisa64r2el \
|
||||
| mipsisa64r3 | mipsisa64r3el \
|
||||
| mipsisa64r5 | mipsisa64r5el \
|
||||
| mipsisa64r6 | mipsisa64r6el \
|
||||
| mipsisa64sb1 | mipsisa64sb1el \
|
||||
| mipsisa64sr71k | mipsisa64sr71kel \
|
||||
| mipsr5900 | mipsr5900el \
|
||||
| mipstx39 | mipstx39el \
|
||||
| mips* \
|
||||
| mmix \
|
||||
| mn10200 | mn10300 \
|
||||
| moxie \
|
||||
| mt \
|
||||
| msp430 \
|
||||
| nanomips* \
|
||||
| nds32 | nds32le | nds32be \
|
||||
| nfp \
|
||||
| nios | nios2 | nios2eb | nios2el \
|
||||
@ -1274,6 +1254,7 @@ case $cpu-$vendor in
|
||||
| ubicom32 \
|
||||
| v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \
|
||||
| vax \
|
||||
| vc4 \
|
||||
| visium \
|
||||
| w65 \
|
||||
| wasm32 | wasm64 \
|
||||
@ -1285,7 +1266,7 @@ case $cpu-$vendor in
|
||||
;;
|
||||
|
||||
*)
|
||||
echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2
|
||||
echo "Invalid configuration '$1': machine '$cpu-$vendor' not recognized" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@ -1306,11 +1287,12 @@ esac
|
||||
|
||||
# Decode manufacturer-specific aliases for certain operating systems.
|
||||
|
||||
if test x$basic_os != x
|
||||
if test x"$basic_os" != x
|
||||
then
|
||||
|
||||
# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just
|
||||
# set os.
|
||||
obj=
|
||||
case $basic_os in
|
||||
gnu/linux*)
|
||||
kernel=linux
|
||||
@ -1510,10 +1492,16 @@ case $os in
|
||||
os=eabi
|
||||
;;
|
||||
*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
aout* | coff* | elf* | pe*)
|
||||
# These are machine code file formats, not OSes
|
||||
obj=$os
|
||||
os=
|
||||
;;
|
||||
*)
|
||||
# No normalization, but not necessarily accepted, that comes below.
|
||||
;;
|
||||
@ -1532,12 +1520,15 @@ else
|
||||
# system, and we'll never get to this point.
|
||||
|
||||
kernel=
|
||||
obj=
|
||||
case $cpu-$vendor in
|
||||
score-*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
spu-*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
*-acorn)
|
||||
os=riscix1.2
|
||||
@ -1547,28 +1538,35 @@ case $cpu-$vendor in
|
||||
os=gnu
|
||||
;;
|
||||
arm*-semi)
|
||||
os=aout
|
||||
os=
|
||||
obj=aout
|
||||
;;
|
||||
c4x-* | tic4x-*)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
c8051-*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
clipper-intergraph)
|
||||
os=clix
|
||||
;;
|
||||
hexagon-*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
tic54x-*)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
tic55x-*)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
tic6x-*)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
# This must come before the *-dec entry.
|
||||
pdp10-*)
|
||||
@ -1590,19 +1588,24 @@ case $cpu-$vendor in
|
||||
os=sunos3
|
||||
;;
|
||||
m68*-cisco)
|
||||
os=aout
|
||||
os=
|
||||
obj=aout
|
||||
;;
|
||||
mep-*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
mips*-cisco)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
mips*-*)
|
||||
os=elf
|
||||
mips*-*|nanomips*-*)
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
or32-*)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
*-tti) # must be before sparc entry or we get the wrong os.
|
||||
os=sysv3
|
||||
@ -1611,7 +1614,8 @@ case $cpu-$vendor in
|
||||
os=sunos4.1.1
|
||||
;;
|
||||
pru-*)
|
||||
os=elf
|
||||
os=
|
||||
obj=elf
|
||||
;;
|
||||
*-be)
|
||||
os=beos
|
||||
@ -1692,10 +1696,12 @@ case $cpu-$vendor in
|
||||
os=uxpv
|
||||
;;
|
||||
*-rom68k)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
*-*bug)
|
||||
os=coff
|
||||
os=
|
||||
obj=coff
|
||||
;;
|
||||
*-apple)
|
||||
os=macos
|
||||
@ -1713,10 +1719,11 @@ esac
|
||||
|
||||
fi
|
||||
|
||||
# Now, validate our (potentially fixed-up) OS.
|
||||
# Now, validate our (potentially fixed-up) individual pieces (OS, OBJ).
|
||||
|
||||
case $os in
|
||||
# Sometimes we do "kernel-libc", so those need to count as OSes.
|
||||
musl* | newlib* | relibc* | uclibc*)
|
||||
llvm* | musl* | newlib* | relibc* | uclibc*)
|
||||
;;
|
||||
# Likewise for "kernel-abi"
|
||||
eabi* | gnueabi*)
|
||||
@ -1724,6 +1731,9 @@ case $os in
|
||||
# VxWorks passes extra cpu info in the 4th filed.
|
||||
simlinux | simwindows | spe)
|
||||
;;
|
||||
# See `case $cpu-$os` validation below
|
||||
ghcjs)
|
||||
;;
|
||||
# Now accept the basic system types.
|
||||
# The portable systems comes first.
|
||||
# Each alternative MUST end in a * to match a version number.
|
||||
@ -1732,7 +1742,7 @@ case $os in
|
||||
| hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
|
||||
| sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \
|
||||
| hiux* | abug | nacl* | netware* | windows* \
|
||||
| os9* | macos* | osx* | ios* \
|
||||
| os9* | macos* | osx* | ios* | tvos* | watchos* \
|
||||
| mpw* | magic* | mmixware* | mon960* | lnews* \
|
||||
| amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
|
||||
| aos* | aros* | cloudabi* | sortix* | twizzler* \
|
||||
@ -1741,11 +1751,11 @@ case $os in
|
||||
| mirbsd* | netbsd* | dicos* | openedition* | ose* \
|
||||
| bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \
|
||||
| ekkobsd* | freebsd* | riscix* | lynxos* | os400* \
|
||||
| bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
|
||||
| ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
|
||||
| bosx* | nextstep* | cxux* | oabi* \
|
||||
| ptx* | ecoff* | winnt* | domain* | vsta* \
|
||||
| udi* | lites* | ieee* | go32* | aux* | hcos* \
|
||||
| chorusrdb* | cegcc* | glidix* | serenity* \
|
||||
| cygwin* | msys* | pe* | moss* | proelf* | rtems* \
|
||||
| cygwin* | msys* | moss* | proelf* | rtems* \
|
||||
| midipix* | mingw32* | mingw64* | mint* \
|
||||
| uxpv* | beos* | mpeix* | udk* | moxiebox* \
|
||||
| interix* | uwin* | mks* | rhapsody* | darwin* \
|
||||
@ -1758,62 +1768,116 @@ case $os in
|
||||
| onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
|
||||
| midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \
|
||||
| nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \
|
||||
| fiwix* | mlibc* )
|
||||
| fiwix* | mlibc* | cos* | mbr* | ironclad* )
|
||||
;;
|
||||
# This one is extra strict with allowed versions
|
||||
sco3.2v2 | sco3.2v[4-9]* | sco5v6*)
|
||||
# Don't forget version if it is 3.2v4 or newer.
|
||||
;;
|
||||
# This refers to builds using the UEFI calling convention
|
||||
# (which depends on the architecture) and PE file format.
|
||||
# Note that this is both a different calling convention and
|
||||
# different file format than that of GNU-EFI
|
||||
# (x86_64-w64-mingw32).
|
||||
uefi)
|
||||
;;
|
||||
none)
|
||||
;;
|
||||
kernel* )
|
||||
kernel* | msvc* )
|
||||
# Restricted further below
|
||||
;;
|
||||
'')
|
||||
if test x"$obj" = x
|
||||
then
|
||||
echo "Invalid configuration '$1': Blank OS only allowed with explicit machine code file format" 1>&2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2
|
||||
echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
case $obj in
|
||||
aout* | coff* | elf* | pe*)
|
||||
;;
|
||||
'')
|
||||
# empty is fine
|
||||
;;
|
||||
*)
|
||||
echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Here we handle the constraint that a (synthetic) cpu and os are
|
||||
# valid only in combination with each other and nowhere else.
|
||||
case $cpu-$os in
|
||||
# The "javascript-unknown-ghcjs" triple is used by GHC; we
|
||||
# accept it here in order to tolerate that, but reject any
|
||||
# variations.
|
||||
javascript-ghcjs)
|
||||
;;
|
||||
javascript-* | *-ghcjs)
|
||||
echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# As a final step for OS-related things, validate the OS-kernel combination
|
||||
# (given a valid OS), if there is a kernel.
|
||||
case $kernel-$os in
|
||||
linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \
|
||||
| linux-musl* | linux-relibc* | linux-uclibc* | linux-mlibc* )
|
||||
case $kernel-$os-$obj in
|
||||
linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \
|
||||
| linux-mlibc*- | linux-musl*- | linux-newlib*- \
|
||||
| linux-relibc*- | linux-uclibc*- )
|
||||
;;
|
||||
uclinux-uclibc* )
|
||||
uclinux-uclibc*- )
|
||||
;;
|
||||
managarm-mlibc* | managarm-kernel* )
|
||||
managarm-mlibc*- | managarm-kernel*- )
|
||||
;;
|
||||
-dietlibc* | -newlib* | -musl* | -relibc* | -uclibc* | -mlibc* )
|
||||
windows*-msvc*-)
|
||||
;;
|
||||
-dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \
|
||||
| -uclibc*- )
|
||||
# These are just libc implementations, not actual OSes, and thus
|
||||
# require a kernel.
|
||||
echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2
|
||||
echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2
|
||||
exit 1
|
||||
;;
|
||||
-kernel* )
|
||||
echo "Invalid configuration \`$1': \`$os' needs explicit kernel." 1>&2
|
||||
-kernel*- )
|
||||
echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2
|
||||
exit 1
|
||||
;;
|
||||
*-kernel* )
|
||||
echo "Invalid configuration \`$1': \`$kernel' does not support \`$os'." 1>&2
|
||||
*-kernel*- )
|
||||
echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2
|
||||
exit 1
|
||||
;;
|
||||
kfreebsd*-gnu* | kopensolaris*-gnu*)
|
||||
*-msvc*- )
|
||||
echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2
|
||||
exit 1
|
||||
;;
|
||||
vxworks-simlinux | vxworks-simwindows | vxworks-spe)
|
||||
kfreebsd*-gnu*- | kopensolaris*-gnu*-)
|
||||
;;
|
||||
nto-qnx*)
|
||||
vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-)
|
||||
;;
|
||||
os2-emx)
|
||||
nto-qnx*-)
|
||||
;;
|
||||
*-eabi* | *-gnueabi*)
|
||||
os2-emx-)
|
||||
;;
|
||||
-*)
|
||||
*-eabi*- | *-gnueabi*-)
|
||||
;;
|
||||
none--*)
|
||||
# None (no kernel, i.e. freestanding / bare metal),
|
||||
# can be paired with an machine code file format
|
||||
;;
|
||||
-*-)
|
||||
# Blank kernel with real OS is always fine.
|
||||
;;
|
||||
*-*)
|
||||
echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2
|
||||
--*)
|
||||
# Blank kernel and OS with real machine code file format is always fine.
|
||||
;;
|
||||
*-*-*)
|
||||
echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@ -1896,7 +1960,7 @@ case $vendor in
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "$cpu-$vendor-${kernel:+$kernel-}$os"
|
||||
echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}"
|
||||
exit
|
||||
|
||||
# Local variables:
|
||||
|
9621
contrib/libpcap/configure
vendored
9621
contrib/libpcap/configure
vendored
File diff suppressed because it is too large
Load Diff
@ -24,17 +24,15 @@ AC_SUBST(PACKAGE_NAME)
|
||||
# These are the variables that are used in Makefile, pcap-config, and
|
||||
# libpcap.pc.
|
||||
#
|
||||
# CFLAGS: inherited from the environment, not modified by us (except
|
||||
# temporarily during tests that involve compilation). Used only when
|
||||
# compiling C source.
|
||||
#
|
||||
# CXXFLAGS: inherited from the environment, not modified by us. Used only
|
||||
# when compiling C++ source.
|
||||
# CFLAGS: inherited from the environment, not modified by us except
|
||||
# for flags required for the platform for which we're building (and
|
||||
# except temporarily during tests that involve compilation). Used only
|
||||
# when compiling C source.
|
||||
#
|
||||
# LDFLAGS: inherited from the environment, not modified by us.
|
||||
#
|
||||
# LIBS: inherited from the environment; we add libraries required by
|
||||
# libpcap. Librares that the core libpcap code requires are added
|
||||
# libpcap. Libraries that the core libpcap code requires are added
|
||||
# first; libraries required by additional pcap modules are first
|
||||
# added to ADDITIONAL_LIBS, and only added to LIBS at the end, after
|
||||
# we're finished doing configuration tests for the modules.
|
||||
@ -62,7 +60,7 @@ AC_SUBST(PACKAGE_NAME)
|
||||
# libpcap. Used in Makefile for both C and C++ source.
|
||||
#
|
||||
# ADDITIONAL_LIBS: additional libraries with which the libpcap dynamic
|
||||
# library needs to be linked. Used in Makwfile; not used in pcap-config
|
||||
# library needs to be linked. Used in Makefile; not used in pcap-config
|
||||
# or libpcap.pc, as, in all platforms on which we run, if a dynamic
|
||||
# library is linked with other dynamic libraries, a program using
|
||||
# that dynamic library doesn't have to link with those libraries -
|
||||
@ -121,39 +119,9 @@ AC_CHECK_SIZEOF([void *])
|
||||
ac_lbl_c_sizeof_void_p="$ac_cv_sizeof_void_p"
|
||||
|
||||
#
|
||||
# We only need a C++ compiler for Haiku; all code except for its
|
||||
# pcap module is in C.
|
||||
# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
|
||||
#
|
||||
case "$host_os" in
|
||||
haiku*)
|
||||
AC_PROG_CXX
|
||||
|
||||
#
|
||||
# Make sure C and C++ have the same pointer sizes with the flags
|
||||
# they're given; if they don't, it means that the compilers for the
|
||||
# languages will, with those flags, not produce code that can be
|
||||
# linked together.
|
||||
#
|
||||
# We have to use different data types, because the results of
|
||||
# a test are cached, so if we test for the size of a given type
|
||||
# in C, the subsequent test in C++ will use the cached variable.
|
||||
# We trick autoconf by testing the size of a "void *" in C and a
|
||||
# "const void *" in C++.
|
||||
#
|
||||
AC_LANG_PUSH([C++])
|
||||
AC_CHECK_SIZEOF([const void *])
|
||||
ac_lbl_cxx_sizeof_void_p="$ac_cv_sizeof_const_void_p"
|
||||
AC_LANG_POP([C++])
|
||||
if test "$ac_lbl_cxx_sizeof_void_p" -eq 0; then
|
||||
AC_MSG_ERROR([No C++ compiler was found])
|
||||
fi
|
||||
if test "$ac_lbl_c_sizeof_void_p" -ne "$ac_lbl_cxx_sizeof_void_p"; then
|
||||
AC_MSG_ERROR([C compiler $CC produces code with $ac_lbl_c_sizeof_void_p-byte pointers
|
||||
while C++ compiler $CXX produces code with $ac_lbl_cxx_sizeof_void_p-byte pointers. This prevents
|
||||
code in those languages from being combined.])
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
AC_CHECK_SIZEOF([time_t],,[#include <time.h>])
|
||||
|
||||
AC_LBL_C_INIT(V_CCOPT, V_INCLS)
|
||||
AC_LBL_SHLIBS_INIT
|
||||
@ -178,11 +146,16 @@ dnl
|
||||
AC_CHECK_HEADERS(sys/ioccom.h sys/sockio.h)
|
||||
AC_CHECK_HEADERS(netpacket/packet.h)
|
||||
|
||||
AC_LBL_SAVE_CHECK_STATE
|
||||
#
|
||||
# Check whether the platform for which we're compiling requires extra
|
||||
# defines and libraries. If so, add them to CFLAGS and LIBS, as we want
|
||||
# all subsequent tests to be done with those defines and libraries.
|
||||
#
|
||||
case "$host_os" in
|
||||
haiku*)
|
||||
#
|
||||
# Haiku needs _BSD_SOURCE for the _IO* macros because it doesn't use them.
|
||||
# Haiku needs _BSD_SOURCE for the _IO* macros because it doesn't
|
||||
# use them.
|
||||
#
|
||||
CFLAGS="$CFLAGS -D_BSD_SOURCE"
|
||||
#
|
||||
@ -192,10 +165,10 @@ haiku*)
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_LBL_SAVE_CHECK_STATE
|
||||
AC_LBL_FIXINCLUDES
|
||||
AC_LBL_RESTORE_CHECK_STATE
|
||||
|
||||
AC_CHECK_FUNCS(strerror)
|
||||
AC_CHECK_FUNC(strerror_r,
|
||||
[
|
||||
#
|
||||
@ -668,6 +641,26 @@ AC_CHECK_HEADER(pthread.h,
|
||||
]
|
||||
)
|
||||
|
||||
AC_MSG_CHECKING([whether to enable the instrument functions code])
|
||||
AC_ARG_ENABLE([instrument-functions],
|
||||
[AS_HELP_STRING([--enable-instrument-functions],
|
||||
[enable instrument functions code [default=no]])],
|
||||
[],
|
||||
[enableval=no])
|
||||
case "$enableval" in
|
||||
yes) AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(ENABLE_INSTRUMENT_FUNCTIONS, 1,
|
||||
[define if you want to build the instrument functions code])
|
||||
# Add '-finstrument-functions' instrumentation option to generate
|
||||
# instrumentation calls for entry and exit to functions.
|
||||
# Use '--enable-instrument-functions' also with tcpdump (or tcpslice)
|
||||
# to see the output. See also https://www.tcpdump.org/faq.html#q17.
|
||||
CFLAGS="$CFLAGS -O0 -ggdb -finstrument-functions"
|
||||
;;
|
||||
*) AC_MSG_RESULT(no)
|
||||
;;
|
||||
esac
|
||||
|
||||
dnl to pacify those who hate protochain insn
|
||||
AC_MSG_CHECKING(if --disable-protochain option is specified)
|
||||
AC_ARG_ENABLE(protochain,
|
||||
@ -819,11 +812,18 @@ else
|
||||
V_PCAP=haiku
|
||||
else
|
||||
#
|
||||
# Nothing we support.
|
||||
# We don't have any capture type we know about.
|
||||
# Report an error, and tell the user to configure with
|
||||
# --with-pcap=null if they want a libpcap that can't
|
||||
# capture but that can read capture files. That way,
|
||||
# nobody gets surprised by getting a no-capture
|
||||
# libpcap without asking for that.
|
||||
#
|
||||
V_PCAP=null
|
||||
AC_MSG_WARN(cannot determine packet capture interface)
|
||||
AC_MSG_WARN((see the INSTALL.md file for more info))
|
||||
AC_MSG_ERROR([No supported packet capture interface was found.
|
||||
See the INSTALL.md file for information on packet capture support in
|
||||
various operating systems.
|
||||
If you want a libpcap that cannot capture packets but that can read
|
||||
pcap and pcapng files, run configure with --with-pcap=null.])
|
||||
fi
|
||||
fi
|
||||
AC_MSG_CHECKING(packet capture type)
|
||||
@ -844,7 +844,7 @@ AC_PATH_PROG([BREW], [brew])
|
||||
# Solaris pkg-config is annoying. For at least one package (D-Bus, I'm
|
||||
# looking at *you*!), there are separate include files for 32-bit and
|
||||
# 64-bit builds (I guess using "unsigned long long" as a 64-bit integer
|
||||
# type on a 64-bit build is like crossing the beams or soething), and
|
||||
# type on a 64-bit build is like crossing the beams or something), and
|
||||
# there are two separate .pc files, so if we're doing a 32-bit build we
|
||||
# should make sure we look in /usr/lib/pkgconfig for .pc files and if
|
||||
# we're doing a 64-bit build we should make sure we look in
|
||||
@ -989,7 +989,7 @@ haiku)
|
||||
#
|
||||
# Capture module
|
||||
#
|
||||
PLATFORM_CXX_SRC="pcap-haiku.cpp"
|
||||
PLATFORM_C_SRC="pcap-haiku.c"
|
||||
|
||||
#
|
||||
# Just for the sake of it.
|
||||
@ -1030,7 +1030,7 @@ linux)
|
||||
#
|
||||
# Check for libnl-genl-3.0 with pkg-config.
|
||||
#
|
||||
PKG_CHECK_MODULES(LIBNL, libnl-genl-3.0,
|
||||
PKG_CHECK_MODULE(LIBNL, libnl-genl-3.0,
|
||||
[
|
||||
pkg_config_found_libnl=yes
|
||||
V_INCLS="$V_INCLS $LIBNL_CFLAGS"
|
||||
@ -1121,6 +1121,25 @@ bpf)
|
||||
#endif
|
||||
#include <net/bpf.h>
|
||||
])
|
||||
|
||||
#
|
||||
# Check whether there's a net/ipnet.h header and,
|
||||
# if so, whether it defines IPNET_ANY_LINK - if so,
|
||||
# we assume we have the "any" device (that's a
|
||||
# Solaris header, and later versions of Solaris
|
||||
# have an "any" device).
|
||||
#
|
||||
# Attempting to include it at compile time could
|
||||
# be a pain, as it's a kernel header.
|
||||
#
|
||||
AC_MSG_CHECKING(whether the Solaris "any" device is supported)
|
||||
if test -e /usr/include/inet/ipnet.h &&
|
||||
grep -q IPNET_ANY_LINK /usr/include/inet/ipnet.h; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_SOLARIS_ANY_DEVICE, 1, [target host supports Solaris "any" device])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
;;
|
||||
|
||||
pf)
|
||||
@ -1795,7 +1814,7 @@ yes) AC_MSG_RESULT(yes)
|
||||
openssl_pkgconfig_dir=`$BREW --env --plain openssl | sed -n 's/PKG_CONFIG_PATH: //p'`
|
||||
PKG_CONFIG_PATH="$openssl_pkgconfig_dir:$PKG_CONFIG_PATH"
|
||||
fi
|
||||
PKG_CHECK_MODULES(OPENSSL, openssl,
|
||||
PKG_CHECK_MODULE(OPENSSL, openssl,
|
||||
[
|
||||
#
|
||||
# We found OpenSSL/libressl.
|
||||
@ -1921,13 +1940,14 @@ return 0;
|
||||
ADDITIONAL_LIBS_STATIC="$ADDITIONAL_LIBS_STATIC $OPENSSL_LIBS_STATIC"
|
||||
LIBS_PRIVATE="$LIBS_PRIVATE $OPENSSL_LIBS_PRIVATE"
|
||||
REQUIRES_PRIVATE="$REQUIRES_PRIVATE $OPENSSL_REQUIRES_PRIVATE"
|
||||
REMOTE_C_SRC="$REMOTE_C_SRC sslutils.c"
|
||||
else
|
||||
AC_MSG_NOTICE(OpenSSL not found)
|
||||
fi
|
||||
|
||||
AC_DEFINE(ENABLE_REMOTE,,
|
||||
[Define to 1 if remote packet capture is to be supported])
|
||||
REMOTE_C_SRC="$REMOTE_C_SRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c sslutils.c"
|
||||
REMOTE_C_SRC="$REMOTE_C_SRC pcap-new.c pcap-rpcap.c rpcap-protocol.c sockutils.c"
|
||||
BUILD_RPCAPD=build-rpcapd
|
||||
INSTALL_RPCAPD=install-rpcapd
|
||||
;;
|
||||
@ -2556,7 +2576,7 @@ if test "xxx_only" != yes; then
|
||||
# software that looks for /dev/null or /dev/tty, for example,
|
||||
# so doing that is *REALLY* not a good idea), please provide
|
||||
# some mechanism to determine that directory at *run time*,
|
||||
# rather than *configure time*, so that it works when doinga
|
||||
# rather than *configure time*, so that it works when doing
|
||||
# a cross-build, and that works with *multiple* distributions,
|
||||
# with our without udev, and with multiple versions of udev,
|
||||
# with udevinfo or udevadm or any other mechanism to get the
|
||||
@ -2639,7 +2659,7 @@ if test "x$enable_netmap" != "xno" ; then
|
||||
#
|
||||
# Check whether net/netmap_user.h is usable if NETMAP_WITH_LIBS is
|
||||
# defined; it's not usable on DragonFly BSD 4.6 if NETMAP_WITH_LIBS
|
||||
# is defined, for example, as it includes a non-existent malloc.h
|
||||
# is defined, for example, as it includes a nonexistent malloc.h
|
||||
# header.
|
||||
#
|
||||
AC_MSG_CHECKING(whether we can compile the netmap support)
|
||||
@ -2725,7 +2745,7 @@ if test "$want_dpdk" != no; then
|
||||
if test -n "$dpdk_dir"; then
|
||||
PKG_CONFIG_PATH="$dpdk_dir:$PKG_CONFIG_PATH"
|
||||
fi
|
||||
PKG_CHECK_MODULES(DPDK, libdpdk,
|
||||
PKG_CHECK_MODULE(DPDK, libdpdk,
|
||||
[
|
||||
found_dpdk=yes
|
||||
])
|
||||
@ -2908,11 +2928,11 @@ if test "x$enable_bluetooth" != "xno" ; then
|
||||
#include <bluetooth/hci.h>
|
||||
],
|
||||
[
|
||||
u_int i = HCI_CHANNEL_MONITOR;
|
||||
int i = HCI_CHANNEL_MONITOR;
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(PCAP_SUPPORT_BT_MONITOR,,
|
||||
AC_DEFINE(PCAP_SUPPORT_BT_MONITOR, 1,
|
||||
[target host supports Bluetooth Monitor])
|
||||
MODULE_C_SRC="$MODULE_C_SRC pcap-bt-monitor-linux.c"
|
||||
],
|
||||
@ -2982,7 +3002,7 @@ if test "x$enable_dbus" != "xno"; then
|
||||
#
|
||||
# https://bugs.freedesktop.org/show_bug.cgi?id=74029
|
||||
#
|
||||
# The user dind't explicitly request it, so just
|
||||
# The user didn't explicitly request it, so just
|
||||
# silently refuse to enable it.
|
||||
#
|
||||
enable_dbus="no"
|
||||
@ -2992,7 +3012,7 @@ if test "x$enable_dbus" != "xno"; then
|
||||
fi
|
||||
|
||||
if test "x$enable_dbus" != "xno"; then
|
||||
PKG_CHECK_MODULES(DBUS, dbus-1,
|
||||
PKG_CHECK_MODULE(DBUS, dbus-1,
|
||||
[
|
||||
AC_LBL_SAVE_CHECK_STATE
|
||||
CFLAGS="$CFLAGS $DBUS_CFLAGS"
|
||||
@ -3043,7 +3063,7 @@ if test "xxx_only" = yes; then
|
||||
fi
|
||||
|
||||
if test "x$enable_rdma" != "xno"; then
|
||||
PKG_CHECK_MODULES(LIBIBVERBS, libibverbs,
|
||||
PKG_CHECK_MODULE(LIBIBVERBS, libibverbs,
|
||||
[
|
||||
found_libibverbs=yes
|
||||
LIBIBVERBS_REQUIRES_PRIVATE="libibverbs"
|
||||
@ -3105,7 +3125,7 @@ if test "x$enable_rdma" != "xno"; then
|
||||
|
||||
if test "x$found_usable_libibverbs" = "xyes"
|
||||
then
|
||||
AC_DEFINE(PCAP_SUPPORT_RDMASNIFF, , [target host supports RDMA sniffing])
|
||||
AC_DEFINE(PCAP_SUPPORT_RDMASNIFF, 1, [target host supports RDMA sniffing])
|
||||
MODULE_C_SRC="$MODULE_C_SRC pcap-rdmasniff.c"
|
||||
CFLAGS="$LIBIBVERBS_CFLAGS $CFLAGS"
|
||||
ADDITIONAL_LIBS="$LIBIBVERBS_LIBS $ADDITIONAL_LIBS"
|
||||
@ -3183,7 +3203,6 @@ AC_SUBST(RPATH)
|
||||
AC_SUBST(ADDLOBJS)
|
||||
AC_SUBST(ADDLARCHIVEOBJS)
|
||||
AC_SUBST(PLATFORM_C_SRC)
|
||||
AC_SUBST(PLATFORM_CXX_SRC)
|
||||
AC_SUBST(MODULE_C_SRC)
|
||||
AC_SUBST(REMOTE_C_SRC)
|
||||
AC_SUBST(PTHREAD_LIBS)
|
||||
|
@ -37,9 +37,11 @@
|
||||
|
||||
#include "pcap/compiler-tests.h"
|
||||
|
||||
#if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) || PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
|
||||
#if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8) || \
|
||||
PCAP_IS_AT_LEAST_GNUC_VERSION(4,6) || \
|
||||
PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
|
||||
/*
|
||||
* Clang and GCC both support this way of putting pragmas into #defines.
|
||||
* All these compilers support this way of putting pragmas into #defines.
|
||||
* We use it only if we have a compiler that supports it; see below
|
||||
* for the code that uses it and the #defines that control whether
|
||||
* that code is used.
|
||||
@ -62,9 +64,6 @@
|
||||
__pragma(warning(disable:4061))
|
||||
#define DIAG_ON_ENUM_SWITCH \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
#define DIAG_OFF_ENUM_SWITCH
|
||||
#define DIAG_ON_ENUM_SWITCH
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -78,9 +77,6 @@
|
||||
__pragma(warning(disable:4065))
|
||||
#define DIAG_ON_DEFAULT_ONLY_SWITCH \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
#define DIAG_OFF_DEFAULT_ONLY_SWITCH
|
||||
#define DIAG_ON_DEFAULT_ONLY_SWITCH
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -128,8 +124,31 @@
|
||||
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
|
||||
#define DIAG_ON_DEPRECATION \
|
||||
PCAP_DO_PRAGMA(clang diagnostic pop)
|
||||
#define DIAG_OFF_FORMAT_TRUNCATION
|
||||
#define DIAG_ON_FORMAT_TRUNCATION
|
||||
|
||||
/*
|
||||
* When Clang correctly detects an old-style function prototype after
|
||||
* preprocessing, the warning can be irrelevant to this source tree because
|
||||
* the prototype comes from a system header macro.
|
||||
*/
|
||||
#if PCAP_IS_AT_LEAST_CLANG_VERSION(5,0)
|
||||
#define DIAG_OFF_STRICT_PROTOTYPES \
|
||||
PCAP_DO_PRAGMA(clang diagnostic push) \
|
||||
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wstrict-prototypes")
|
||||
#define DIAG_ON_STRICT_PROTOTYPES \
|
||||
PCAP_DO_PRAGMA(clang diagnostic pop)
|
||||
#endif
|
||||
|
||||
#define DIAG_OFF_DOCUMENTATION \
|
||||
PCAP_DO_PRAGMA(clang diagnostic push) \
|
||||
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation")
|
||||
#define DIAG_ON_DOCUMENTATION \
|
||||
PCAP_DO_PRAGMA(clang diagnostic pop)
|
||||
|
||||
#define DIAG_OFF_SIGN_COMPARE \
|
||||
PCAP_DO_PRAGMA(clang diagnostic push) \
|
||||
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare")
|
||||
#define DIAG_ON_SIGN_COMPARE \
|
||||
PCAP_DO_PRAGMA(clang diagnostic pop)
|
||||
#elif defined(_MSC_VER)
|
||||
/*
|
||||
* This is Microsoft Visual Studio; we can use __pragma(warning(disable:XXXX))
|
||||
@ -165,8 +184,6 @@
|
||||
__pragma(warning(disable:4996))
|
||||
#define DIAG_ON_DEPRECATION \
|
||||
__pragma(warning(pop))
|
||||
#define DIAG_OFF_FORMAT_TRUNCATION
|
||||
#define DIAG_ON_FORMAT_TRUNCATION
|
||||
#elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
|
||||
/*
|
||||
* This is GCC 4.6 or later, or a compiler claiming to be that.
|
||||
@ -184,8 +201,6 @@
|
||||
/*
|
||||
* GCC currently doesn't issue any narrowing warnings.
|
||||
*/
|
||||
#define DIAG_OFF_NARROWING
|
||||
#define DIAG_ON_NARROWING
|
||||
|
||||
/*
|
||||
* Suppress deprecation warnings.
|
||||
@ -207,24 +222,16 @@
|
||||
PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wformat-truncation=")
|
||||
#define DIAG_ON_FORMAT_TRUNCATION \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic pop)
|
||||
#else
|
||||
#define DIAG_OFF_FORMAT_TRUNCATION
|
||||
#define DIAG_ON_FORMAT_TRUNCATION
|
||||
#endif
|
||||
#else
|
||||
#elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
|
||||
/*
|
||||
* Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
|
||||
* or a compiler claiming to be that; there's nothing we know of that
|
||||
* we can do.
|
||||
* Sun C compiler version 5.5 (Studio version 8) and later supports "#pragma
|
||||
* error_messages()".
|
||||
*/
|
||||
#define DIAG_OFF_FLEX
|
||||
#define DIAG_ON_FLEX
|
||||
#define DIAG_OFF_NARROWING
|
||||
#define DIAG_ON_NARROWING
|
||||
#define DIAG_OFF_DEPRECATION
|
||||
#define DIAG_ON_DEPRECATION
|
||||
#define DIAG_OFF_FORMAT_TRUNCATION
|
||||
#define DIAG_ON_FORMAT_TRUNCATION
|
||||
#define DIAG_OFF_FLEX \
|
||||
PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
|
||||
#define DIAG_ON_FLEX \
|
||||
PCAP_DO_PRAGMA(error_messages(default,E_STATEMENT_NOT_REACHED))
|
||||
#endif
|
||||
|
||||
#ifdef YYBYACC
|
||||
@ -268,12 +275,6 @@
|
||||
#define DIAG_OFF_BISON_BYACC \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wshadow") \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
|
||||
#else
|
||||
/*
|
||||
* Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
|
||||
* claiming to be that; there's nothing we know of that we can do.
|
||||
*/
|
||||
#define DIAG_OFF_BISON_BYACC
|
||||
#endif
|
||||
#else
|
||||
/*
|
||||
@ -310,15 +311,38 @@
|
||||
*/
|
||||
#define DIAG_OFF_BISON_BYACC \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
|
||||
#else
|
||||
#elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5)
|
||||
/*
|
||||
* Neither Clang 2.8 or later nor GCC 4.6 or later or a compiler
|
||||
* claiming to be that; there's nothing we know of that we can do.
|
||||
* Same as for DIAG_OFF_FLEX above.
|
||||
*/
|
||||
#define DIAG_OFF_BISON_BYACC
|
||||
#define DIAG_OFF_BISON_BYACC \
|
||||
PCAP_DO_PRAGMA(error_messages(off,E_STATEMENT_NOT_REACHED))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
|
||||
/*
|
||||
* Clang appears to let you ignore a result without a warning by
|
||||
* casting the function result to void, so we don't appear to
|
||||
* need this for Clang.
|
||||
*/
|
||||
#elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,5)
|
||||
/*
|
||||
* GCC warns about unused return values if a function is marked as
|
||||
* "warn about ignoring this function's return value".
|
||||
*/
|
||||
#define DIAG_OFF_WARN_UNUSED_RESULT \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic push) \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunused-result")
|
||||
#define DIAG_ON_WARN_UNUSED_RESULT \
|
||||
PCAP_DO_PRAGMA(GCC diagnostic pop)
|
||||
|
||||
/*
|
||||
* GCC does not currently generate any -Wstrict-prototypes warnings that
|
||||
* would need silencing as is done for Clang above.
|
||||
*/
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GCC needs this on AIX for longjmp().
|
||||
*/
|
||||
@ -331,8 +355,76 @@
|
||||
* So please remember to use this very carefully.
|
||||
*/
|
||||
#define PCAP_UNREACHABLE __builtin_unreachable();
|
||||
#else
|
||||
#define PCAP_UNREACHABLE
|
||||
#endif
|
||||
|
||||
#ifndef DIAG_OFF_ENUM_SWITCH
|
||||
#define DIAG_OFF_ENUM_SWITCH
|
||||
#endif
|
||||
#ifndef DIAG_ON_ENUM_SWITCH
|
||||
#define DIAG_ON_ENUM_SWITCH
|
||||
#endif
|
||||
#ifndef DIAG_OFF_DEFAULT_ONLY_SWITCH
|
||||
#define DIAG_OFF_DEFAULT_ONLY_SWITCH
|
||||
#endif
|
||||
#ifndef DIAG_ON_DEFAULT_ONLY_SWITCH
|
||||
#define DIAG_ON_DEFAULT_ONLY_SWITCH
|
||||
#endif
|
||||
#ifndef DIAG_OFF_FLEX
|
||||
#define DIAG_OFF_FLEX
|
||||
#endif
|
||||
#ifndef DIAG_ON_FLEX
|
||||
#define DIAG_ON_FLEX
|
||||
#endif
|
||||
#ifndef DIAG_OFF_NARROWING
|
||||
#define DIAG_OFF_NARROWING
|
||||
#endif
|
||||
#ifndef DIAG_ON_NARROWING
|
||||
#define DIAG_ON_NARROWING
|
||||
#endif
|
||||
#ifndef DIAG_OFF_DEPRECATION
|
||||
#define DIAG_OFF_DEPRECATION
|
||||
#endif
|
||||
#ifndef DIAG_ON_DEPRECATION
|
||||
#define DIAG_ON_DEPRECATION
|
||||
#endif
|
||||
#ifndef DIAG_OFF_FORMAT_TRUNCATION
|
||||
#define DIAG_OFF_FORMAT_TRUNCATION
|
||||
#endif
|
||||
#ifndef DIAG_ON_FORMAT_TRUNCATION
|
||||
#define DIAG_ON_FORMAT_TRUNCATION
|
||||
#endif
|
||||
#ifndef DIAG_OFF_BISON_BYACC
|
||||
#define DIAG_OFF_BISON_BYACC
|
||||
#endif
|
||||
//
|
||||
// DIAG_ON_BISON_BYACC does not need to be defined.
|
||||
//
|
||||
#ifndef DIAG_OFF_WARN_UNUSED_RESULT
|
||||
#define DIAG_OFF_WARN_UNUSED_RESULT
|
||||
#endif
|
||||
#ifndef DIAG_ON_WARN_UNUSED_RESULT
|
||||
#define DIAG_ON_WARN_UNUSED_RESULT
|
||||
#endif
|
||||
#ifndef DIAG_OFF_STRICT_PROTOTYPES
|
||||
#define DIAG_OFF_STRICT_PROTOTYPES
|
||||
#endif
|
||||
#ifndef DIAG_ON_STRICT_PROTOTYPES
|
||||
#define DIAG_ON_STRICT_PROTOTYPES
|
||||
#endif
|
||||
#ifndef DIAG_OFF_DOCUMENTATION
|
||||
#define DIAG_OFF_DOCUMENTATION
|
||||
#endif
|
||||
#ifndef DIAG_ON_DOCUMENTATION
|
||||
#define DIAG_ON_DOCUMENTATION
|
||||
#endif
|
||||
#ifndef DIAG_OFF_SIGN_COMPARE
|
||||
#define DIAG_OFF_SIGN_COMPARE
|
||||
#endif
|
||||
#ifndef DIAG_ON_SIGN_COMPARE
|
||||
#define DIAG_ON_SIGN_COMPARE
|
||||
#endif
|
||||
#ifndef PCAP_UNREACHABLE
|
||||
#define PCAP_UNREACHABLE
|
||||
#endif
|
||||
|
||||
#endif /* _diag_control_h */
|
||||
|
@ -11,9 +11,7 @@
|
||||
* by pcap-[dlpi,libdlpi].c.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef DL_IPATM
|
||||
#define DL_IPATM 0x12 /* ATM Classical IP interface */
|
||||
@ -195,7 +193,7 @@ pcap_process_pkts(pcap_t *p, pcap_handler callback, u_char *user,
|
||||
bufp += caplen;
|
||||
#endif
|
||||
++pd->stat.ps_recv;
|
||||
if (pcap_filter(p->fcode.bf_insns, pk, origlen, caplen)) {
|
||||
if (pcapint_filter(p->fcode.bf_insns, pk, origlen, caplen)) {
|
||||
#ifdef HAVE_SYS_BUFMOD_H
|
||||
pkthdr.ts.tv_sec = sbp->sbh_timestamp.tv_sec;
|
||||
pkthdr.ts.tv_usec = sbp->sbh_timestamp.tv_usec;
|
||||
@ -246,14 +244,14 @@ pcap_process_mactype(pcap_t *p, u_int mactype)
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *)malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return (-1);
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
break;
|
||||
|
||||
case DL_FDDI:
|
||||
@ -377,7 +375,7 @@ pcap_alloc_databuf(pcap_t *p)
|
||||
p->bufsize = PKTBUFSIZE;
|
||||
p->buffer = malloc(p->bufsize + p->offset);
|
||||
if (p->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return (-1);
|
||||
}
|
||||
@ -412,6 +410,6 @@ strioctl(int fd, int cmd, int len, char *dp)
|
||||
static void
|
||||
pcap_stream_err(const char *func, int err, char *errbuf)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, err, "%s", func);
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, err, "%s", func);
|
||||
}
|
||||
#endif
|
||||
|
57
contrib/libpcap/doc/README.haiku.md
Normal file
57
contrib/libpcap/doc/README.haiku.md
Normal file
@ -0,0 +1,57 @@
|
||||
# Compiling and using libpcap on Haiku
|
||||
|
||||
Haiku R1/beta4 and earlier versions do not support packet capture on the
|
||||
loopback interface. Using this version of libpcap, loopback capture works
|
||||
since Haiku revision hrev57585 and is expected to work in Haiku R1/beta5 when
|
||||
the latter becomes available. Packet timestamping and filtering always occur
|
||||
in userland. Wireless monitor mode is not supported. The "any"
|
||||
pseudo-interface is not supported.
|
||||
[**pcap_set_buffer_size**](https://www.tcpdump.org/manpages/pcap_set_buffer_size.3pcap.html)(3PCAP)
|
||||
has no effect.
|
||||
[**pcap_setdirection**](https://www.tcpdump.org/manpages/pcap_setdirection.3pcap.html)(3PCAP)
|
||||
is not supported.
|
||||
[**pcap_inject**](https://www.tcpdump.org/manpages/pcap_inject.3pcap.html)(3PCAP)
|
||||
is not supported.
|
||||
|
||||
The statistics reported by
|
||||
[**pcap_stats**](https://www.tcpdump.org/manpages/pcap_stats.3pcap.html)(3PCAP)
|
||||
on Haiku are as follows:
|
||||
* `ps_recv` is the number of packets successfully delivered by the kernel,
|
||||
before libpcap applies a filter.
|
||||
* `ps_drop` is the number of packets rejected by the filter.
|
||||
* `ps_ifdrop` is the number of packets dropped by the network interface (as
|
||||
seen via `SIOCGIFSTATS`) since the capture handle became active.
|
||||
|
||||
## 64-bit x86 R1/beta4
|
||||
|
||||
* Autoconf 2.71 works.
|
||||
* CMake 3.28.3 works.
|
||||
* GCC 13.2.0 works.
|
||||
* Clang 12.0.1 works with the latest llvm12_clang-12.0.1-5 version.
|
||||
* flex 2.6.4 works.
|
||||
* bison 3.8.2 works.
|
||||
|
||||
The following command will install respective non-default packages:
|
||||
```
|
||||
pkgman install cmake llvm12_clang
|
||||
```
|
||||
|
||||
For reference, the tests were done using a system installed from
|
||||
`haiku-r1beta4-x86_64-anyboot.iso`.
|
||||
|
||||
## 32-bit x86 R1/beta4
|
||||
|
||||
* Autoconf 2.71 works.
|
||||
* CMake 3.24.2 works.
|
||||
* GCC 11.2.0 works.
|
||||
* Clang does not work.
|
||||
* flex 2.6.4 works.
|
||||
* bison 3.0.5 works.
|
||||
|
||||
The following command will install respective non-default packages:
|
||||
```
|
||||
pkgman install cmake_x86
|
||||
```
|
||||
|
||||
For reference, the tests were done using a system installed from
|
||||
`haiku-r1beta4-x86_gcc2h-anyboot.iso`.
|
@ -155,7 +155,7 @@ promiscuous mode support.
|
||||
|
||||
An additional note, from Jost Martin, for HP-UX 10.20:
|
||||
|
||||
Q: How do I get ethereral on HPUX to capture the _outgoing_ packets
|
||||
Q: How do I get [Wireshark] on HPUX to capture the _outgoing_ packets
|
||||
of an interface
|
||||
A: You need to get PHNE_20892,PHNE_20725 and PHCO_10947 (or
|
||||
newer, this is as of 4.4.00) and its dependencies. Then you can
|
||||
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap-types.h>
|
||||
|
||||
@ -33,6 +31,8 @@
|
||||
|
||||
#include <pcap/namedb.h>
|
||||
|
||||
#include "thread-local.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
@ -87,7 +87,7 @@ pcap_next_etherent(FILE *fp)
|
||||
u_char d;
|
||||
char *bp;
|
||||
size_t namesize;
|
||||
static struct pcap_etherent e;
|
||||
static thread_local struct pcap_etherent e;
|
||||
|
||||
memset((char *)&e, 0, sizeof(e));
|
||||
for (;;) {
|
||||
|
@ -229,7 +229,7 @@ EXTRACT_BE_S_8(const void *p)
|
||||
* quantities the hard way - fetch the bytes one at a time and
|
||||
* assemble them.
|
||||
*
|
||||
* XXX - ARM is a special case. ARMv1 through ARMv5 didn't suppory
|
||||
* XXX - ARM is a special case. ARMv1 through ARMv5 didn't support
|
||||
* unaligned loads; ARMv6 and later support it *but* have a bit in
|
||||
* the system control register that the OS can set and that causes
|
||||
* unaligned loads to fault rather than succeeding.
|
||||
|
@ -32,9 +32,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@ -60,7 +58,7 @@
|
||||
* we end up including both the OS's <net/bpf.h> and our <pcap/bpf.h>,
|
||||
* and their definitions of some data structures collide.
|
||||
*/
|
||||
#if (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET)
|
||||
#if (defined(__linux__) || defined(__Lynx__)) && defined(AF_PACKET)
|
||||
# ifdef HAVE_NETPACKET_PACKET_H
|
||||
/* Linux distributions with newer glibc */
|
||||
# include <netpacket/packet.h>
|
||||
@ -75,7 +73,7 @@
|
||||
# include <linux/if_packet.h>
|
||||
# endif /* __Lynx__ */
|
||||
# endif /* HAVE_NETPACKET_PACKET_H */
|
||||
#endif /* (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET) */
|
||||
#endif /* (defined(__linux__) || defined(__Lynx__)) && defined(AF_PACKET) */
|
||||
|
||||
/*
|
||||
* This is fun.
|
||||
@ -99,6 +97,17 @@
|
||||
* but not in the final version). On the latter systems, we explicitly
|
||||
* check the AF_ type to determine the length; we assume that on
|
||||
* all those systems we have "struct sockaddr_storage".
|
||||
*
|
||||
* OSes that use this file are:
|
||||
* - FreeBSD (HAVE_STRUCT_SOCKADDR_SA_LEN is defined)
|
||||
* - Haiku (HAVE_STRUCT_SOCKADDR_SA_LEN is defined)
|
||||
* - Hurd (HAVE_STRUCT_SOCKADDR_SA_LEN is defined)
|
||||
* - illumos (HAVE_STRUCT_SOCKADDR_SA_LEN is not defined)
|
||||
* - Linux (HAVE_STRUCT_SOCKADDR_SA_LEN is not defined)
|
||||
* - macOS (HAVE_STRUCT_SOCKADDR_SA_LEN is defined)
|
||||
* - NetBSD (HAVE_STRUCT_SOCKADDR_SA_LEN is defined)
|
||||
* - OpenBSD (SA_LEN() is defined)
|
||||
* - Solaris 11 (HAVE_STRUCT_SOCKADDR_SA_LEN is not defined)
|
||||
*/
|
||||
#ifndef SA_LEN
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
@ -120,11 +129,16 @@ get_sa_len(struct sockaddr *addr)
|
||||
return (sizeof (struct sockaddr_in6));
|
||||
#endif
|
||||
|
||||
#if (defined(linux) || defined(__Lynx__)) && defined(AF_PACKET)
|
||||
#if (defined(__linux__) || defined(__Lynx__)) && defined(AF_PACKET)
|
||||
case AF_PACKET:
|
||||
return (sizeof (struct sockaddr_ll));
|
||||
#endif
|
||||
|
||||
#ifdef AF_LINK
|
||||
case AF_LINK:
|
||||
return (sizeof (struct sockaddr_dl));
|
||||
#endif
|
||||
|
||||
default:
|
||||
return (sizeof (struct sockaddr));
|
||||
}
|
||||
@ -143,7 +157,7 @@ get_sa_len(struct sockaddr *addr)
|
||||
* could be opened.
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
pcapint_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
int (*check_usable)(const char *), get_if_flags_func get_flags_func)
|
||||
{
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
@ -167,7 +181,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
* those.
|
||||
*/
|
||||
if (getifaddrs(&ifap) != 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "getifaddrs");
|
||||
return (-1);
|
||||
}
|
||||
@ -263,7 +277,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
/*
|
||||
* Add information for this address to the list.
|
||||
*/
|
||||
if (add_addr_to_if(devlistp, ifa->ifa_name, ifa->ifa_flags,
|
||||
if (pcapint_add_addr_to_if(devlistp, ifa->ifa_name, ifa->ifa_flags,
|
||||
get_flags_func,
|
||||
addr, addr_size, netmask, addr_size,
|
||||
broadaddr, broadaddr_size, dstaddr, dstaddr_size,
|
||||
|
@ -32,9 +32,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -87,6 +85,10 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||
* We assume that a UNIX that doesn't have "getifaddrs()" and doesn't have
|
||||
* SIOCGLIFCONF, but has SIOCGIFCONF, uses "struct sockaddr" for the
|
||||
* address in an entry returned by SIOCGIFCONF.
|
||||
*
|
||||
* OSes that use this file are:
|
||||
* - AIX 7 (SA_LEN() is not defined, HAVE_STRUCT_SOCKADDR_SA_LEN is defined)
|
||||
* - HP-UX 11 (HAVE_STRUCT_SOCKADDR_SA_LEN is not defined)
|
||||
*/
|
||||
#ifndef SA_LEN
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
@ -132,7 +134,7 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||
* we already have that.
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
pcapint_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
int (*check_usable)(const char *), get_if_flags_func get_flags_func)
|
||||
{
|
||||
register int fd;
|
||||
@ -154,7 +156,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
*/
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "socket");
|
||||
return (-1);
|
||||
}
|
||||
@ -180,7 +182,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
}
|
||||
buf = malloc(buf_size);
|
||||
if (buf == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
(void)close(fd);
|
||||
return (-1);
|
||||
@ -191,7 +193,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
memset(buf, 0, buf_size);
|
||||
if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0
|
||||
&& errno != EINVAL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCGIFCONF");
|
||||
(void)close(fd);
|
||||
free(buf);
|
||||
@ -264,7 +266,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifrflags) < 0) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCGIFFLAGS: %.*s",
|
||||
(int)sizeof(ifrflags.ifr_name),
|
||||
ifrflags.ifr_name);
|
||||
@ -287,7 +289,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
netmask = NULL;
|
||||
netmask_size = 0;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"SIOCGIFNETMASK: %.*s",
|
||||
(int)sizeof(ifrnetmask.ifr_name),
|
||||
@ -318,7 +320,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
broadaddr = NULL;
|
||||
broadaddr_size = 0;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"SIOCGIFBRDADDR: %.*s",
|
||||
(int)sizeof(ifrbroadaddr.ifr_name),
|
||||
@ -357,7 +359,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
dstaddr = NULL;
|
||||
dstaddr_size = 0;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"SIOCGIFDSTADDR: %.*s",
|
||||
(int)sizeof(ifrdstaddr.ifr_name),
|
||||
@ -409,7 +411,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
/*
|
||||
* Add information for this address to the list.
|
||||
*/
|
||||
if (add_addr_to_if(devlistp, ifrp->ifr_name,
|
||||
if (pcapint_add_addr_to_if(devlistp, ifrp->ifr_name,
|
||||
ifrflags.ifr_flags, get_flags_func,
|
||||
&ifrp->ifr_addr, SA_LEN(&ifrp->ifr_addr),
|
||||
netmask, netmask_size, broadaddr, broadaddr_size,
|
||||
|
@ -32,9 +32,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
@ -63,6 +61,10 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Only Solaris 10 uses this file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get a list of all interfaces that are up and that we can open.
|
||||
* Returns -1 on error, 0 otherwise.
|
||||
@ -74,7 +76,7 @@ struct rtentry; /* declarations in <net/if.h> */
|
||||
* SIOCGLIFCONF rather than SIOCGIFCONF in order to get IPv6 addresses.)
|
||||
*/
|
||||
int
|
||||
pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
pcapint_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
int (*check_usable)(const char *), get_if_flags_func get_flags_func)
|
||||
{
|
||||
register int fd4, fd6, fd;
|
||||
@ -96,7 +98,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
*/
|
||||
fd4 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd4 < 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "socket: AF_INET");
|
||||
return (-1);
|
||||
}
|
||||
@ -106,7 +108,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
*/
|
||||
fd6 = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (fd6 < 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "socket: AF_INET6");
|
||||
(void)close(fd4);
|
||||
return (-1);
|
||||
@ -119,7 +121,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
ifn.lifn_flags = 0;
|
||||
ifn.lifn_count = 0;
|
||||
if (ioctl(fd4, SIOCGLIFNUM, (char *)&ifn) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCGLIFNUM");
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
@ -132,7 +134,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
buf_size = ifn.lifn_count * sizeof (struct lifreq);
|
||||
buf = malloc(buf_size);
|
||||
if (buf == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
@ -148,7 +150,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
ifc.lifc_flags = 0;
|
||||
memset(buf, 0, buf_size);
|
||||
if (ioctl(fd4, SIOCGLIFCONF, (char *)&ifc) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCGLIFCONF");
|
||||
(void)close(fd6);
|
||||
(void)close(fd4);
|
||||
@ -197,7 +199,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
if (ioctl(fd, SIOCGLIFFLAGS, (char *)&ifrflags) < 0) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCGLIFFLAGS: %.*s",
|
||||
(int)sizeof(ifrflags.lifr_name),
|
||||
ifrflags.lifr_name);
|
||||
@ -219,7 +221,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
*/
|
||||
netmask = NULL;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"SIOCGLIFNETMASK: %.*s",
|
||||
(int)sizeof(ifrnetmask.lifr_name),
|
||||
@ -247,7 +249,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
*/
|
||||
broadaddr = NULL;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"SIOCGLIFBRDADDR: %.*s",
|
||||
(int)sizeof(ifrbroadaddr.lifr_name),
|
||||
@ -282,7 +284,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
*/
|
||||
dstaddr = NULL;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"SIOCGLIFDSTADDR: %.*s",
|
||||
(int)sizeof(ifrdstaddr.lifr_name),
|
||||
@ -326,7 +328,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
|
||||
/*
|
||||
* Add information for this address to the list.
|
||||
*/
|
||||
if (add_addr_to_if(devlistp, ifrp->lifr_name,
|
||||
if (pcapint_add_addr_to_if(devlistp, ifrp->lifr_name,
|
||||
ifrflags.lifr_flags, get_flags_func,
|
||||
(struct sockaddr *)&ifrp->lifr_addr,
|
||||
sizeof (struct sockaddr_storage),
|
||||
|
@ -35,9 +35,7 @@
|
||||
* Utilities for message formatting used both by libpcap and rpcapd.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ftmacros.h"
|
||||
|
||||
@ -62,19 +60,19 @@
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* True if we shouold use UTF-8.
|
||||
* True if we should use UTF-8.
|
||||
*/
|
||||
static int use_utf_8;
|
||||
|
||||
void
|
||||
pcap_fmt_set_encoding(unsigned int opts)
|
||||
pcapint_fmt_set_encoding(unsigned int opts)
|
||||
{
|
||||
if (opts == PCAP_CHAR_ENC_UTF_8)
|
||||
use_utf_8 = 1;
|
||||
}
|
||||
#else
|
||||
void
|
||||
pcap_fmt_set_encoding(unsigned int opts _U_)
|
||||
pcapint_fmt_set_encoding(unsigned int opts _U_)
|
||||
{
|
||||
/*
|
||||
* Nothing to do here.
|
||||
@ -154,7 +152,7 @@ utf_16le_to_utf_8_truncated(const wchar_t *utf_16, char *utf_8,
|
||||
uc = SURROGATE_VALUE(c, c2);
|
||||
} else {
|
||||
/*
|
||||
* Not a trailing surroage;
|
||||
* Not a trailing surrogate;
|
||||
* try to drop in a
|
||||
* REPLACEMENT CHARACTER.
|
||||
*/
|
||||
@ -266,18 +264,18 @@ utf_16le_to_utf_8_truncated(const wchar_t *utf_16, char *utf_8,
|
||||
* errno, with a message for the errno after the formatted output.
|
||||
*/
|
||||
void
|
||||
pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
|
||||
pcapint_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
pcap_vfmt_errmsg_for_errno(errbuf, errbuflen, errnum, fmt, ap);
|
||||
pcapint_vfmt_errmsg_for_errno(errbuf, errbuflen, errnum, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
pcap_vfmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
|
||||
pcapint_vfmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
size_t msglen;
|
||||
@ -334,43 +332,10 @@ pcap_vfmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
|
||||
*/
|
||||
if (!use_utf_8)
|
||||
utf_8_to_acp_truncated(errbuf);
|
||||
#elif defined(HAVE_GNU_STRERROR_R)
|
||||
/*
|
||||
* We have a GNU-style strerror_r(), which is *not* guaranteed to
|
||||
* do anything to the buffer handed to it, and which returns a
|
||||
* pointer to the error string, which may or may not be in
|
||||
* the buffer.
|
||||
*
|
||||
* It is, however, guaranteed to succeed.
|
||||
*/
|
||||
char strerror_buf[PCAP_ERRBUF_SIZE];
|
||||
char *errstring = strerror_r(errnum, strerror_buf, PCAP_ERRBUF_SIZE);
|
||||
snprintf(p, errbuflen_remaining, "%s", errstring);
|
||||
#elif defined(HAVE_POSIX_STRERROR_R)
|
||||
/*
|
||||
* We have a POSIX-style strerror_r(), which is guaranteed to fill
|
||||
* in the buffer, but is not guaranteed to succeed.
|
||||
*/
|
||||
int err = strerror_r(errnum, p, errbuflen_remaining);
|
||||
if (err == EINVAL) {
|
||||
/*
|
||||
* UNIX 03 says this isn't guaranteed to produce a
|
||||
* fallback error message.
|
||||
*/
|
||||
snprintf(p, errbuflen_remaining, "Unknown error: %d",
|
||||
errnum);
|
||||
} else if (err == ERANGE) {
|
||||
/*
|
||||
* UNIX 03 says this isn't guaranteed to produce a
|
||||
* fallback error message.
|
||||
*/
|
||||
snprintf(p, errbuflen_remaining,
|
||||
"Message for error %d is too long", errnum);
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* We have neither _wcserror_s() nor strerror_r(), so we're
|
||||
* stuck with using pcap_strerror().
|
||||
* Either Windows without _wcserror_s() or not Windows. Let pcap_strerror()
|
||||
* solve the non-UTF-16 part of this problem space.
|
||||
*/
|
||||
snprintf(p, errbuflen_remaining, "%s", pcap_strerror(errnum));
|
||||
#endif
|
||||
@ -382,18 +347,18 @@ pcap_vfmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
|
||||
* Win32 error, with a message for the Win32 error after the formatted output.
|
||||
*/
|
||||
void
|
||||
pcap_fmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
|
||||
pcapint_fmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
pcap_vfmt_errmsg_for_win32_err(errbuf, errbuflen, errnum, fmt, ap);
|
||||
pcapint_vfmt_errmsg_for_win32_err(errbuf, errbuflen, errnum, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
pcap_vfmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
|
||||
pcapint_vfmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
size_t msglen;
|
||||
|
@ -42,17 +42,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void pcap_fmt_set_encoding(unsigned int);
|
||||
void pcapint_fmt_set_encoding(unsigned int);
|
||||
|
||||
void pcap_fmt_errmsg_for_errno(char *, size_t, int,
|
||||
void pcapint_fmt_errmsg_for_errno(char *, size_t, int,
|
||||
PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5);
|
||||
void pcap_vfmt_errmsg_for_errno(char *, size_t, int,
|
||||
void pcapint_vfmt_errmsg_for_errno(char *, size_t, int,
|
||||
PCAP_FORMAT_STRING(const char *), va_list) PCAP_PRINTFLIKE(4, 0);
|
||||
|
||||
#ifdef _WIN32
|
||||
void pcap_fmt_errmsg_for_win32_err(char *, size_t, DWORD,
|
||||
void pcapint_fmt_errmsg_for_win32_err(char *, size_t, DWORD,
|
||||
PCAP_FORMAT_STRING(const char *), ...) PCAP_PRINTFLIKE(4, 5);
|
||||
void pcap_vfmt_errmsg_for_win32_err(char *, size_t, DWORD,
|
||||
void pcapint_vfmt_errmsg_for_win32_err(char *, size_t, DWORD,
|
||||
PCAP_FORMAT_STRING(const char *), va_list) PCAP_PRINTFLIKE(4, 0);
|
||||
#endif
|
||||
|
||||
|
@ -64,7 +64,7 @@
|
||||
/*
|
||||
* We need this to get the versions of socket functions that
|
||||
* use socklen_t. Define it only if it's not already defined,
|
||||
* so we don't get redefiniton warnings.
|
||||
* so we don't get redefinition warnings.
|
||||
*/
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
#define _XOPEN_SOURCE_EXTENDED
|
||||
@ -95,7 +95,7 @@
|
||||
*
|
||||
* Unfortunately, one thing it has to offer is a strerror_r()
|
||||
* that's not POSIX-compliant, but we deal with that in
|
||||
* pcap_fmt_errmsg_for_errno().
|
||||
* pcapint_fmt_errmsg_for_errno().
|
||||
*
|
||||
* We don't limit this to, for example, Linux and Cygwin, because
|
||||
* this might, for example, be GNU/HURD or one of Debian's kFreeBSD
|
||||
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
@ -67,7 +65,7 @@
|
||||
|
||||
#include "scanner.h"
|
||||
|
||||
#if defined(linux)
|
||||
#if defined(__linux__)
|
||||
#include <linux/types.h>
|
||||
#include <linux/if_packet.h>
|
||||
#include <linux/filter.h>
|
||||
@ -218,7 +216,7 @@ enum e_offrel {
|
||||
};
|
||||
|
||||
/*
|
||||
* We divy out chunks of memory rather than call malloc each time so
|
||||
* We divvy out chunks of memory rather than call malloc each time so
|
||||
* we don't have to worry about leaking memory. It's probably
|
||||
* not a big deal if all this memory was wasted but if this ever
|
||||
* goes into a library that would probably not be a good idea.
|
||||
@ -670,7 +668,7 @@ sdup(compiler_state_t *cstate, const char *s)
|
||||
|
||||
if (cp == NULL)
|
||||
return (NULL);
|
||||
pcap_strlcpy(cp, s, n);
|
||||
pcapint_strlcpy(cp, s, n);
|
||||
return (cp);
|
||||
}
|
||||
|
||||
@ -724,22 +722,23 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
|
||||
yyscan_t scanner = NULL;
|
||||
volatile YY_BUFFER_STATE in_buffer = NULL;
|
||||
u_int len;
|
||||
int rc;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* If this pcap_t hasn't been activated, it doesn't have a
|
||||
* link-layer type, so we can't use it.
|
||||
*/
|
||||
if (!p->activated) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
(void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"not-yet-activated pcap_t passed to pcap_compile");
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!done)
|
||||
if (!done) {
|
||||
pcap_wsockinit();
|
||||
done = 1;
|
||||
done = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_REMOTE
|
||||
@ -779,15 +778,18 @@ pcap_compile(pcap_t *p, struct bpf_program *program,
|
||||
|
||||
cstate.snaplen = pcap_snapshot(p);
|
||||
if (cstate.snaplen == 0) {
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
(void)snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"snaplen of 0 rejects all packets");
|
||||
rc = PCAP_ERROR;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (pcap_lex_init(&scanner) != 0)
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
if (pcap_lex_init(&scanner) != 0) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "can't initialize scanner");
|
||||
rc = PCAP_ERROR;
|
||||
goto quit;
|
||||
}
|
||||
in_buffer = pcap__scan_string(xbuf ? xbuf : "", scanner);
|
||||
|
||||
/*
|
||||
@ -871,7 +873,7 @@ quit:
|
||||
int
|
||||
pcap_compile_nopcap(int snaplen_arg, int linktype_arg,
|
||||
struct bpf_program *program,
|
||||
const char *buf, int optimize, bpf_u_int32 mask)
|
||||
const char *buf, int optimize, bpf_u_int32 mask)
|
||||
{
|
||||
pcap_t *p;
|
||||
int ret;
|
||||
@ -1707,15 +1709,15 @@ init_linktype(compiler_state_t *cstate, pcap_t *p)
|
||||
* For values in the range in which we've assigned new
|
||||
* DLT_ values, only raw "link[N:M]" filtering is supported.
|
||||
*/
|
||||
if (cstate->linktype >= DLT_MATCHING_MIN &&
|
||||
cstate->linktype <= DLT_MATCHING_MAX) {
|
||||
if (cstate->linktype >= DLT_HIGH_MATCHING_MIN &&
|
||||
cstate->linktype <= DLT_HIGH_MATCHING_MAX) {
|
||||
cstate->off_linktype.constant_part = OFFSET_NOT_SET;
|
||||
cstate->off_linkpl.constant_part = OFFSET_NOT_SET;
|
||||
cstate->off_nl = OFFSET_NOT_SET;
|
||||
cstate->off_nl_nosnap = OFFSET_NOT_SET;
|
||||
} else {
|
||||
bpf_set_error(cstate, "unknown data link type %d (min %d, max %d)",
|
||||
cstate->linktype, DLT_MATCHING_MIN, DLT_MATCHING_MAX);
|
||||
cstate->linktype, DLT_HIGH_MATCHING_MIN, DLT_HIGH_MATCHING_MAX);
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
@ -1834,7 +1836,7 @@ gen_load_a(compiler_state_t *cstate, enum e_offrel offrel, u_int offset,
|
||||
/*
|
||||
* Load the item at {offset of the link-layer payload} +
|
||||
* {offset, relative to the start of the link-layer
|
||||
* paylod, of the IPv4 header} + {length of the IPv4 header} +
|
||||
* payload, of the IPv4 header} + {length of the IPv4 header} +
|
||||
* {specified offset}.
|
||||
*
|
||||
* If the offset of the link-layer payload is variable,
|
||||
@ -1897,7 +1899,7 @@ gen_loadx_iphdrlen(compiler_state_t *cstate)
|
||||
} else {
|
||||
/*
|
||||
* The offset of the link-layer payload is a constant,
|
||||
* so no code was generated to load the (non-existent)
|
||||
* so no code was generated to load the (nonexistent)
|
||||
* variable part of that offset.
|
||||
*
|
||||
* This means we can use the 4*([k]&0xf) addressing
|
||||
@ -4087,7 +4089,16 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
|
||||
{
|
||||
struct block *b0, *b1;
|
||||
u_int offset;
|
||||
uint32_t *a, *m;
|
||||
/*
|
||||
* Code below needs to access four separate 32-bit parts of the 128-bit
|
||||
* IPv6 address and mask. In some OSes this is as simple as using the
|
||||
* s6_addr32 pseudo-member of struct in6_addr, which contains a union of
|
||||
* 8-, 16- and 32-bit arrays. In other OSes this is not the case, as
|
||||
* far as libpcap sees it. Hence copy the data before use to avoid
|
||||
* potential unaligned memory access and the associated compiler
|
||||
* warnings (whether genuine or not).
|
||||
*/
|
||||
bpf_u_int32 a[4], m[4];
|
||||
|
||||
switch (dir) {
|
||||
|
||||
@ -4141,8 +4152,8 @@ gen_hostop6(compiler_state_t *cstate, struct in6_addr *addr,
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
/* this order is important */
|
||||
a = (uint32_t *)addr;
|
||||
m = (uint32_t *)mask;
|
||||
memcpy(a, addr, sizeof(a));
|
||||
memcpy(m, mask, sizeof(m));
|
||||
b1 = gen_mcmp(cstate, OR_LINKPL, offset + 12, BPF_W, ntohl(a[3]), ntohl(m[3]));
|
||||
b0 = gen_mcmp(cstate, OR_LINKPL, offset + 8, BPF_W, ntohl(a[2]), ntohl(m[2]));
|
||||
gen_and(b0, b1);
|
||||
@ -5290,7 +5301,6 @@ gen_gateway(compiler_state_t *cstate, const u_char *eaddr,
|
||||
*/
|
||||
bpf_error(cstate,
|
||||
"'gateway' supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
|
||||
break;
|
||||
case DLT_IP_OVER_FC:
|
||||
b0 = gen_ipfchostop(cstate, eaddr, Q_OR);
|
||||
break;
|
||||
@ -6117,7 +6127,7 @@ gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
|
||||
/*
|
||||
* To quote a comment in optimize.c:
|
||||
*
|
||||
* "These data structures are used in a Cocke and Shwarz style
|
||||
* "These data structures are used in a Cocke and Schwartz style
|
||||
* value numbering scheme. Since the flowgraph is acyclic,
|
||||
* exit values can be propagated from a node's predecessors
|
||||
* provided it is uniquely defined."
|
||||
@ -6658,6 +6668,277 @@ gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a non-numeric name to a port number.
|
||||
*/
|
||||
static int
|
||||
nametoport(compiler_state_t *cstate, const char *name, int ipproto)
|
||||
{
|
||||
struct addrinfo hints, *res, *ai;
|
||||
int error;
|
||||
struct sockaddr_in *in4;
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6 *in6;
|
||||
#endif
|
||||
int port = -1;
|
||||
|
||||
/*
|
||||
* We check for both TCP and UDP in case there are
|
||||
* ambiguous entries.
|
||||
*/
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = (ipproto == IPPROTO_TCP) ? SOCK_STREAM : SOCK_DGRAM;
|
||||
hints.ai_protocol = ipproto;
|
||||
error = getaddrinfo(NULL, name, &hints, &res);
|
||||
if (error != 0) {
|
||||
switch (error) {
|
||||
|
||||
case EAI_NONAME:
|
||||
case EAI_SERVICE:
|
||||
/*
|
||||
* No such port. Just return -1.
|
||||
*/
|
||||
break;
|
||||
|
||||
#ifdef EAI_SYSTEM
|
||||
case EAI_SYSTEM:
|
||||
/*
|
||||
* We don't use strerror() because it's not
|
||||
* guaranteed to be thread-safe on all platforms
|
||||
* (probably because it might use a non-thread-local
|
||||
* buffer into which to format an error message
|
||||
* if the error code isn't one for which it has
|
||||
* a canned string; three cheers for C string
|
||||
* handling).
|
||||
*/
|
||||
bpf_set_error(cstate, "getaddrinfo(\"%s\" fails with system error: %d",
|
||||
name, errno);
|
||||
port = -2; /* a real error */
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
/*
|
||||
* This is a real error, not just "there's
|
||||
* no such service name".
|
||||
*
|
||||
* We don't use gai_strerror() because it's not
|
||||
* guaranteed to be thread-safe on all platforms
|
||||
* (probably because it might use a non-thread-local
|
||||
* buffer into which to format an error message
|
||||
* if the error code isn't one for which it has
|
||||
* a canned string; three cheers for C string
|
||||
* handling).
|
||||
*/
|
||||
bpf_set_error(cstate, "getaddrinfo(\"%s\") fails with error: %d",
|
||||
name, error);
|
||||
port = -2; /* a real error */
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* OK, we found it. Did it find anything?
|
||||
*/
|
||||
for (ai = res; ai != NULL; ai = ai->ai_next) {
|
||||
/*
|
||||
* Does it have an address?
|
||||
*/
|
||||
if (ai->ai_addr != NULL) {
|
||||
/*
|
||||
* Yes. Get a port number; we're done.
|
||||
*/
|
||||
if (ai->ai_addr->sa_family == AF_INET) {
|
||||
in4 = (struct sockaddr_in *)ai->ai_addr;
|
||||
port = ntohs(in4->sin_port);
|
||||
break;
|
||||
}
|
||||
#ifdef INET6
|
||||
if (ai->ai_addr->sa_family == AF_INET6) {
|
||||
in6 = (struct sockaddr_in6 *)ai->ai_addr;
|
||||
port = ntohs(in6->sin6_port);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string to a port number.
|
||||
*/
|
||||
static bpf_u_int32
|
||||
stringtoport(compiler_state_t *cstate, const char *string, size_t string_size,
|
||||
int *proto)
|
||||
{
|
||||
stoulen_ret ret;
|
||||
char *cpy;
|
||||
bpf_u_int32 val;
|
||||
int tcp_port = -1;
|
||||
int udp_port = -1;
|
||||
|
||||
/*
|
||||
* See if it's a number.
|
||||
*/
|
||||
ret = stoulen(string, string_size, &val, cstate);
|
||||
switch (ret) {
|
||||
|
||||
case STOULEN_OK:
|
||||
/* Unknown port type - it's just a number. */
|
||||
*proto = PROTO_UNDEF;
|
||||
break;
|
||||
|
||||
case STOULEN_NOT_OCTAL_NUMBER:
|
||||
case STOULEN_NOT_HEX_NUMBER:
|
||||
case STOULEN_NOT_DECIMAL_NUMBER:
|
||||
/*
|
||||
* Not a valid number; try looking it up as a port.
|
||||
*/
|
||||
cpy = malloc(string_size + 1); /* +1 for terminating '\0' */
|
||||
memcpy(cpy, string, string_size);
|
||||
cpy[string_size] = '\0';
|
||||
tcp_port = nametoport(cstate, cpy, IPPROTO_TCP);
|
||||
if (tcp_port == -2) {
|
||||
/*
|
||||
* We got a hard error; the error string has
|
||||
* already been set.
|
||||
*/
|
||||
free(cpy);
|
||||
longjmp(cstate->top_ctx, 1);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
udp_port = nametoport(cstate, cpy, IPPROTO_UDP);
|
||||
if (udp_port == -2) {
|
||||
/*
|
||||
* We got a hard error; the error string has
|
||||
* already been set.
|
||||
*/
|
||||
free(cpy);
|
||||
longjmp(cstate->top_ctx, 1);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to check /etc/services for ambiguous entries.
|
||||
* If we find an ambiguous entry, and it has the
|
||||
* same port number, change the proto to PROTO_UNDEF
|
||||
* so both TCP and UDP will be checked.
|
||||
*/
|
||||
if (tcp_port >= 0) {
|
||||
val = (bpf_u_int32)tcp_port;
|
||||
*proto = IPPROTO_TCP;
|
||||
if (udp_port >= 0) {
|
||||
if (udp_port == tcp_port)
|
||||
*proto = PROTO_UNDEF;
|
||||
#ifdef notdef
|
||||
else
|
||||
/* Can't handle ambiguous names that refer
|
||||
to different port numbers. */
|
||||
warning("ambiguous port %s in /etc/services",
|
||||
cpy);
|
||||
#endif
|
||||
}
|
||||
free(cpy);
|
||||
break;
|
||||
}
|
||||
if (udp_port >= 0) {
|
||||
val = (bpf_u_int32)udp_port;
|
||||
*proto = IPPROTO_UDP;
|
||||
free(cpy);
|
||||
break;
|
||||
}
|
||||
#if defined(ultrix) || defined(__osf__)
|
||||
/* Special hack in case NFS isn't in /etc/services */
|
||||
if (strcmp(cpy, "nfs") == 0) {
|
||||
val = 2049;
|
||||
*proto = PROTO_UNDEF;
|
||||
free(cpy);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
bpf_set_error(cstate, "'%s' is not a valid port", cpy);
|
||||
free(cpy);
|
||||
longjmp(cstate->top_ctx, 1);
|
||||
/*NOTREACHED*/
|
||||
|
||||
case STOULEN_ERROR:
|
||||
/* Error already set. */
|
||||
longjmp(cstate->top_ctx, 1);
|
||||
/*NOTREACHED*/
|
||||
|
||||
default:
|
||||
/* Should not happen */
|
||||
bpf_set_error(cstate, "stoulen returned %d - this should not happen", ret);
|
||||
longjmp(cstate->top_ctx, 1);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
return (val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string in the form PPP-PPP, which correspond to ports, to
|
||||
* a starting and ending port in a port range.
|
||||
*/
|
||||
static void
|
||||
stringtoportrange(compiler_state_t *cstate, const char *string,
|
||||
bpf_u_int32 *port1, bpf_u_int32 *port2, int *proto)
|
||||
{
|
||||
char *hyphen_off;
|
||||
const char *first, *second;
|
||||
size_t first_size, second_size;
|
||||
int save_proto;
|
||||
|
||||
if ((hyphen_off = strchr(string, '-')) == NULL)
|
||||
bpf_error(cstate, "port range '%s' contains no hyphen", string);
|
||||
|
||||
/*
|
||||
* Make sure there are no other hyphens.
|
||||
*
|
||||
* XXX - we support named ports, but there are some port names
|
||||
* in /etc/services that include hyphens, so this would rule
|
||||
* that out.
|
||||
*/
|
||||
if (strchr(hyphen_off + 1, '-') != NULL)
|
||||
bpf_error(cstate, "port range '%s' contains more than one hyphen",
|
||||
string);
|
||||
|
||||
/*
|
||||
* Get the length of the first port.
|
||||
*/
|
||||
first = string;
|
||||
first_size = hyphen_off - string;
|
||||
if (first_size == 0) {
|
||||
/* Range of "-port", which we don't support. */
|
||||
bpf_error(cstate, "port range '%s' has no starting port", string);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to convert it to a port.
|
||||
*/
|
||||
*port1 = stringtoport(cstate, first, first_size, proto);
|
||||
save_proto = *proto;
|
||||
|
||||
/*
|
||||
* Get the length of the second port.
|
||||
*/
|
||||
second = hyphen_off + 1;
|
||||
second_size = strlen(second);
|
||||
if (second_size == 0) {
|
||||
/* Range of "port-", which we don't support. */
|
||||
bpf_error(cstate, "port range '%s' has no ending port", string);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to convert it to a port.
|
||||
*/
|
||||
*port2 = stringtoport(cstate, second, second_size, proto);
|
||||
if (*proto != save_proto)
|
||||
*proto = PROTO_UNDEF;
|
||||
}
|
||||
|
||||
struct block *
|
||||
gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
|
||||
{
|
||||
@ -6675,7 +6956,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
|
||||
#endif /*INET6*/
|
||||
struct block *b, *tmp;
|
||||
int port, real_proto;
|
||||
int port1, port2;
|
||||
bpf_u_int32 port1, port2;
|
||||
|
||||
/*
|
||||
* Catch errors reported by us and routines below us, and return NULL
|
||||
@ -6884,8 +7165,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
|
||||
if (proto != Q_DEFAULT &&
|
||||
proto != Q_UDP && proto != Q_TCP && proto != Q_SCTP)
|
||||
bpf_error(cstate, "illegal qualifier of 'portrange'");
|
||||
if (pcap_nametoportrange(name, &port1, &port2, &real_proto) == 0)
|
||||
bpf_error(cstate, "unknown port in range '%s'", name);
|
||||
stringtoportrange(cstate, name, &port1, &port2, &real_proto);
|
||||
if (proto == Q_UDP) {
|
||||
if (real_proto == IPPROTO_TCP)
|
||||
bpf_error(cstate, "port in range '%s' is tcp", name);
|
||||
@ -6913,12 +7193,8 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
|
||||
/* override PROTO_UNDEF */
|
||||
real_proto = IPPROTO_SCTP;
|
||||
}
|
||||
if (port1 < 0)
|
||||
bpf_error(cstate, "illegal port number %d < 0", port1);
|
||||
if (port1 > 65535)
|
||||
bpf_error(cstate, "illegal port number %d > 65535", port1);
|
||||
if (port2 < 0)
|
||||
bpf_error(cstate, "illegal port number %d < 0", port2);
|
||||
if (port2 > 65535)
|
||||
bpf_error(cstate, "illegal port number %d > 65535", port2);
|
||||
|
||||
@ -7151,14 +7427,14 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
|
||||
|
||||
#ifdef INET6
|
||||
struct block *
|
||||
gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2,
|
||||
bpf_u_int32 masklen, struct qual q)
|
||||
gen_mcode6(compiler_state_t *cstate, const char *s, bpf_u_int32 masklen,
|
||||
struct qual q)
|
||||
{
|
||||
struct addrinfo *res;
|
||||
struct in6_addr *addr;
|
||||
struct in6_addr mask;
|
||||
struct block *b;
|
||||
uint32_t *a, *m;
|
||||
bpf_u_int32 a[4], m[4]; /* Same as in gen_hostop6(). */
|
||||
|
||||
/*
|
||||
* Catch errors reported by us and routines below us, and return NULL
|
||||
@ -7167,19 +7443,16 @@ gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2,
|
||||
if (setjmp(cstate->top_ctx))
|
||||
return (NULL);
|
||||
|
||||
if (s2)
|
||||
bpf_error(cstate, "no mask %s supported", s2);
|
||||
|
||||
res = pcap_nametoaddrinfo(s1);
|
||||
res = pcap_nametoaddrinfo(s);
|
||||
if (!res)
|
||||
bpf_error(cstate, "invalid ip6 address %s", s1);
|
||||
bpf_error(cstate, "invalid ip6 address %s", s);
|
||||
cstate->ai = res;
|
||||
if (res->ai_next)
|
||||
bpf_error(cstate, "%s resolved to multiple address", s1);
|
||||
bpf_error(cstate, "%s resolved to multiple address", s);
|
||||
addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr;
|
||||
|
||||
if (masklen > sizeof(mask.s6_addr) * 8)
|
||||
bpf_error(cstate, "mask length must be <= %u", (unsigned int)(sizeof(mask.s6_addr) * 8));
|
||||
bpf_error(cstate, "mask length must be <= %zu", sizeof(mask.s6_addr) * 8);
|
||||
memset(&mask, 0, sizeof(mask));
|
||||
memset(&mask.s6_addr, 0xff, masklen / 8);
|
||||
if (masklen % 8) {
|
||||
@ -7187,11 +7460,11 @@ gen_mcode6(compiler_state_t *cstate, const char *s1, const char *s2,
|
||||
(0xff << (8 - masklen % 8)) & 0xff;
|
||||
}
|
||||
|
||||
a = (uint32_t *)addr;
|
||||
m = (uint32_t *)&mask;
|
||||
memcpy(a, addr, sizeof(a));
|
||||
memcpy(m, &mask, sizeof(m));
|
||||
if ((a[0] & ~m[0]) || (a[1] & ~m[1])
|
||||
|| (a[2] & ~m[2]) || (a[3] & ~m[3])) {
|
||||
bpf_error(cstate, "non-network bits set in \"%s/%d\"", s1, masklen);
|
||||
bpf_error(cstate, "non-network bits set in \"%s/%d\"", s, masklen);
|
||||
}
|
||||
|
||||
switch (q.addr) {
|
||||
@ -7524,58 +7797,54 @@ gen_load_internal(compiler_state_t *cstate, int proto, struct arth *inst,
|
||||
inst->b = b;
|
||||
break;
|
||||
case Q_ICMPV6:
|
||||
/*
|
||||
* Do the computation only if the packet contains
|
||||
* the protocol in question.
|
||||
*/
|
||||
b = gen_proto_abbrev_internal(cstate, Q_IPV6);
|
||||
if (inst->b) {
|
||||
gen_and(inst->b, b);
|
||||
}
|
||||
inst->b = b;
|
||||
/*
|
||||
* Do the computation only if the packet contains
|
||||
* the protocol in question.
|
||||
*/
|
||||
b = gen_proto_abbrev_internal(cstate, Q_IPV6);
|
||||
if (inst->b)
|
||||
gen_and(inst->b, b);
|
||||
inst->b = b;
|
||||
|
||||
/*
|
||||
* Check if we have an icmp6 next header
|
||||
*/
|
||||
b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58);
|
||||
if (inst->b) {
|
||||
gen_and(inst->b, b);
|
||||
}
|
||||
inst->b = b;
|
||||
/*
|
||||
* Check if we have an icmp6 next header
|
||||
*/
|
||||
b = gen_cmp(cstate, OR_LINKPL, 6, BPF_B, 58);
|
||||
if (inst->b)
|
||||
gen_and(inst->b, b);
|
||||
inst->b = b;
|
||||
|
||||
s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl);
|
||||
/*
|
||||
* If "s" is non-null, it has code to arrange that the
|
||||
* X register contains the variable part of the offset
|
||||
* of the link-layer payload. Add to it the offset
|
||||
* computed into the register specified by "index",
|
||||
* and move that into the X register. Otherwise, just
|
||||
* load into the X register the offset computed into
|
||||
* the register specified by "index".
|
||||
*/
|
||||
if (s != NULL) {
|
||||
sappend(s, xfer_to_a(cstate, inst));
|
||||
sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
|
||||
sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
|
||||
} else
|
||||
s = xfer_to_x(cstate, inst);
|
||||
|
||||
s = gen_abs_offset_varpart(cstate, &cstate->off_linkpl);
|
||||
/*
|
||||
* If "s" is non-null, it has code to arrange that the
|
||||
* X register contains the variable part of the offset
|
||||
* of the link-layer payload. Add to it the offset
|
||||
* computed into the register specified by "index",
|
||||
* and move that into the X register. Otherwise, just
|
||||
* load into the X register the offset computed into
|
||||
* the register specified by "index".
|
||||
*/
|
||||
if (s != NULL) {
|
||||
sappend(s, xfer_to_a(cstate, inst));
|
||||
sappend(s, new_stmt(cstate, BPF_ALU|BPF_ADD|BPF_X));
|
||||
sappend(s, new_stmt(cstate, BPF_MISC|BPF_TAX));
|
||||
} else {
|
||||
s = xfer_to_x(cstate, inst);
|
||||
}
|
||||
/*
|
||||
* Load the item at the sum of the offset we've put in the
|
||||
* X register, the offset of the start of the network
|
||||
* layer header from the beginning of the link-layer
|
||||
* payload, and the constant part of the offset of the
|
||||
* start of the link-layer payload.
|
||||
*/
|
||||
tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
|
||||
tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40;
|
||||
|
||||
/*
|
||||
* Load the item at the sum of the offset we've put in the
|
||||
* X register, the offset of the start of the network
|
||||
* layer header from the beginning of the link-layer
|
||||
* payload, and the constant part of the offset of the
|
||||
* start of the link-layer payload.
|
||||
*/
|
||||
tmp = new_stmt(cstate, BPF_LD|BPF_IND|size_code);
|
||||
tmp->s.k = cstate->off_linkpl.constant_part + cstate->off_nl + 40;
|
||||
sappend(s, tmp);
|
||||
sappend(inst->s, s);
|
||||
|
||||
sappend(s, tmp);
|
||||
sappend(inst->s, s);
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
inst->regno = regno;
|
||||
s = new_stmt(cstate, BPF_ST);
|
||||
@ -8235,8 +8504,8 @@ gen_ifindex(compiler_state_t *cstate, int ifindex)
|
||||
/* match packets on this interface */
|
||||
b0 = gen_cmp(cstate, OR_LINKHDR, 4, BPF_W, ifindex);
|
||||
break;
|
||||
default:
|
||||
#if defined(linux)
|
||||
default:
|
||||
#if defined(__linux__)
|
||||
/*
|
||||
* This is Linux; we require PF_PACKET support.
|
||||
* If this is a *live* capture, we can look at
|
||||
@ -8247,17 +8516,16 @@ gen_ifindex(compiler_state_t *cstate, int ifindex)
|
||||
/* We have a FILE *, so this is a savefile */
|
||||
bpf_error(cstate, "ifindex not supported on %s when reading savefiles",
|
||||
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
|
||||
b0 = NULL;
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
/* match ifindex */
|
||||
b0 = gen_cmp(cstate, OR_LINKHDR, SKF_AD_OFF + SKF_AD_IFINDEX, BPF_W,
|
||||
ifindex);
|
||||
#else /* defined(linux) */
|
||||
#else /* defined(__linux__) */
|
||||
bpf_error(cstate, "ifindex not supported on %s",
|
||||
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
|
||||
/*NOTREACHED*/
|
||||
#endif /* defined(linux) */
|
||||
#endif /* defined(__linux__) */
|
||||
}
|
||||
return (b0);
|
||||
}
|
||||
@ -8387,7 +8655,7 @@ gen_inbound(compiler_state_t *cstate, int dir)
|
||||
* with newer capture APIs, allowing it to be saved
|
||||
* in pcapng files.
|
||||
*/
|
||||
#if defined(linux)
|
||||
#if defined(__linux__)
|
||||
/*
|
||||
* This is Linux; we require PF_PACKET support.
|
||||
* If this is a *live* capture, we can look at
|
||||
@ -8407,11 +8675,11 @@ gen_inbound(compiler_state_t *cstate, int dir)
|
||||
/* to filter on inbound traffic, invert the match */
|
||||
gen_not(b0);
|
||||
}
|
||||
#else /* defined(linux) */
|
||||
#else /* defined(__linux__) */
|
||||
bpf_error(cstate, "inbound/outbound not supported on %s",
|
||||
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
|
||||
/*NOTREACHED*/
|
||||
#endif /* defined(linux) */
|
||||
#endif /* defined(__linux__) */
|
||||
}
|
||||
return (b0);
|
||||
}
|
||||
@ -8837,7 +9105,7 @@ gen_vlan_patch_vid_test(compiler_state_t *cstate, struct block *b_vid)
|
||||
|
||||
/* Jump to the test in b_vid. We need to jump one instruction before
|
||||
* the end of the b_vid block so that we only skip loading the TCI
|
||||
* from packet data and not the 'and' instruction extractging VID.
|
||||
* from packet data and not the 'and' instruction extracting VID.
|
||||
*/
|
||||
cnt = 0;
|
||||
for (s2 = b_vid->stmts; s2; s2 = s2->next)
|
||||
@ -8977,7 +9245,7 @@ gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag)
|
||||
#endif
|
||||
b0 = gen_vlan_no_bpf_extensions(cstate, vlan_num,
|
||||
has_vlan_tag);
|
||||
break;
|
||||
break;
|
||||
|
||||
case DLT_IEEE802_11:
|
||||
case DLT_PRISM_HEADER:
|
||||
@ -8992,7 +9260,7 @@ gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag)
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
cstate->vlan_stack_depth++;
|
||||
cstate->vlan_stack_depth++;
|
||||
|
||||
return (b0);
|
||||
}
|
||||
@ -9018,38 +9286,38 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
|
||||
if (setjmp(cstate->top_ctx))
|
||||
return (NULL);
|
||||
|
||||
if (cstate->label_stack_depth > 0) {
|
||||
/* just match the bottom-of-stack bit clear */
|
||||
b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01);
|
||||
} else {
|
||||
/*
|
||||
* We're not in an MPLS stack yet, so check the link-layer
|
||||
* type against MPLS.
|
||||
*/
|
||||
switch (cstate->linktype) {
|
||||
if (cstate->label_stack_depth > 0) {
|
||||
/* just match the bottom-of-stack bit clear */
|
||||
b0 = gen_mcmp(cstate, OR_PREVMPLSHDR, 2, BPF_B, 0, 0x01);
|
||||
} else {
|
||||
/*
|
||||
* We're not in an MPLS stack yet, so check the link-layer
|
||||
* type against MPLS.
|
||||
*/
|
||||
switch (cstate->linktype) {
|
||||
|
||||
case DLT_C_HDLC: /* fall through */
|
||||
case DLT_HDLC:
|
||||
case DLT_EN10MB:
|
||||
case DLT_NETANALYZER:
|
||||
case DLT_NETANALYZER_TRANSPARENT:
|
||||
b0 = gen_linktype(cstate, ETHERTYPE_MPLS);
|
||||
break;
|
||||
case DLT_C_HDLC: /* fall through */
|
||||
case DLT_HDLC:
|
||||
case DLT_EN10MB:
|
||||
case DLT_NETANALYZER:
|
||||
case DLT_NETANALYZER_TRANSPARENT:
|
||||
b0 = gen_linktype(cstate, ETHERTYPE_MPLS);
|
||||
break;
|
||||
|
||||
case DLT_PPP:
|
||||
b0 = gen_linktype(cstate, PPP_MPLS_UCAST);
|
||||
break;
|
||||
case DLT_PPP:
|
||||
b0 = gen_linktype(cstate, PPP_MPLS_UCAST);
|
||||
break;
|
||||
|
||||
/* FIXME add other DLT_s ...
|
||||
* for Frame-Relay/and ATM this may get messy due to SNAP headers
|
||||
* leave it for now */
|
||||
/* FIXME add other DLT_s ...
|
||||
* for Frame-Relay/and ATM this may get messy due to SNAP headers
|
||||
* leave it for now */
|
||||
|
||||
default:
|
||||
bpf_error(cstate, "no MPLS support for %s",
|
||||
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
default:
|
||||
bpf_error(cstate, "no MPLS support for %s",
|
||||
pcap_datalink_val_to_description_or_dlt(cstate->linktype));
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
|
||||
/* If a specific MPLS label is requested, check it */
|
||||
if (has_label_num) {
|
||||
@ -9064,23 +9332,23 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
|
||||
b0 = b1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Change the offsets to point to the type and data fields within
|
||||
* the MPLS packet. Just increment the offsets, so that we
|
||||
* can support a hierarchy, e.g. "mpls 100000 && mpls 1024" to
|
||||
* capture packets with an outer label of 100000 and an inner
|
||||
* label of 1024.
|
||||
*
|
||||
* Increment the MPLS stack depth as well; this indicates that
|
||||
* we're checking MPLS-encapsulated headers, to make sure higher
|
||||
* level code generators don't try to match against IP-related
|
||||
* protocols such as Q_ARP, Q_RARP etc.
|
||||
*
|
||||
* XXX - this is a bit of a kludge. See comments in gen_vlan().
|
||||
*/
|
||||
cstate->off_nl_nosnap += 4;
|
||||
cstate->off_nl += 4;
|
||||
cstate->label_stack_depth++;
|
||||
/*
|
||||
* Change the offsets to point to the type and data fields within
|
||||
* the MPLS packet. Just increment the offsets, so that we
|
||||
* can support a hierarchy, e.g. "mpls 100000 && mpls 1024" to
|
||||
* capture packets with an outer label of 100000 and an inner
|
||||
* label of 1024.
|
||||
*
|
||||
* Increment the MPLS stack depth as well; this indicates that
|
||||
* we're checking MPLS-encapsulated headers, to make sure higher
|
||||
* level code generators don't try to match against IP-related
|
||||
* protocols such as Q_ARP, Q_RARP etc.
|
||||
*
|
||||
* XXX - this is a bit of a kludge. See comments in gen_vlan().
|
||||
*/
|
||||
cstate->off_nl_nosnap += 4;
|
||||
cstate->off_nl += 4;
|
||||
cstate->label_stack_depth++;
|
||||
return (b0);
|
||||
}
|
||||
|
||||
@ -9795,8 +10063,8 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
|
||||
bpf_error(cstate, "'sio' supported only on SS7");
|
||||
/* sio coded on 1 byte so max value 255 */
|
||||
if(jvalue > 255)
|
||||
bpf_error(cstate, "sio value %u too big; max value = 255",
|
||||
jvalue);
|
||||
bpf_error(cstate, "sio value %u too big; max value = 255",
|
||||
jvalue);
|
||||
b0 = gen_ncmp(cstate, OR_PACKET, newoff_sio, BPF_B, 0xffffffffU,
|
||||
jtype, reverse, jvalue);
|
||||
break;
|
||||
@ -9805,13 +10073,13 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
|
||||
newoff_opc += 3;
|
||||
|
||||
/* FALLTHROUGH */
|
||||
case M_OPC:
|
||||
if (cstate->off_opc == OFFSET_NOT_SET)
|
||||
case M_OPC:
|
||||
if (cstate->off_opc == OFFSET_NOT_SET)
|
||||
bpf_error(cstate, "'opc' supported only on SS7");
|
||||
/* opc coded on 14 bits so max value 16383 */
|
||||
if (jvalue > 16383)
|
||||
bpf_error(cstate, "opc value %u too big; max value = 16383",
|
||||
jvalue);
|
||||
bpf_error(cstate, "opc value %u too big; max value = 16383",
|
||||
jvalue);
|
||||
/* the following instructions are made to convert jvalue
|
||||
* to the form used to write opc in an ss7 message*/
|
||||
val1 = jvalue & 0x00003c00;
|
||||
@ -9830,12 +10098,12 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case M_DPC:
|
||||
if (cstate->off_dpc == OFFSET_NOT_SET)
|
||||
if (cstate->off_dpc == OFFSET_NOT_SET)
|
||||
bpf_error(cstate, "'dpc' supported only on SS7");
|
||||
/* dpc coded on 14 bits so max value 16383 */
|
||||
if (jvalue > 16383)
|
||||
bpf_error(cstate, "dpc value %u too big; max value = 16383",
|
||||
jvalue);
|
||||
bpf_error(cstate, "dpc value %u too big; max value = 16383",
|
||||
jvalue);
|
||||
/* the following instructions are made to convert jvalue
|
||||
* to the forme used to write dpc in an ss7 message*/
|
||||
val1 = jvalue & 0x000000ff;
|
||||
@ -9852,12 +10120,12 @@ gen_mtp3field_code(compiler_state_t *cstate, int mtp3field,
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case M_SLS:
|
||||
if (cstate->off_sls == OFFSET_NOT_SET)
|
||||
if (cstate->off_sls == OFFSET_NOT_SET)
|
||||
bpf_error(cstate, "'sls' supported only on SS7");
|
||||
/* sls coded on 4 bits so max value 15 */
|
||||
if (jvalue > 15)
|
||||
bpf_error(cstate, "sls value %u too big; max value = 15",
|
||||
jvalue);
|
||||
bpf_error(cstate, "sls value %u too big; max value = 15",
|
||||
jvalue);
|
||||
/* the following instruction is made to convert jvalue
|
||||
* to the forme used to write sls in an ss7 message*/
|
||||
jvalue = jvalue << 4;
|
||||
|
@ -327,8 +327,8 @@ struct block *gen_acode(compiler_state_t *, const char *, struct qual);
|
||||
struct block *gen_mcode(compiler_state_t *, const char *, const char *,
|
||||
bpf_u_int32, struct qual);
|
||||
#ifdef INET6
|
||||
struct block *gen_mcode6(compiler_state_t *, const char *, const char *,
|
||||
bpf_u_int32, struct qual);
|
||||
struct block *gen_mcode6(compiler_state_t *, const char *, bpf_u_int32,
|
||||
struct qual);
|
||||
#endif
|
||||
struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32,
|
||||
struct qual);
|
||||
|
@ -67,9 +67,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* grammar.h requires gencode.h and sometimes breaks in a polluted namespace
|
||||
@ -110,21 +108,31 @@ struct rtentry;
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifdef YYBYACC
|
||||
/*
|
||||
* Work around some bugs in Berkeley YACC prior to the 2017-07-09
|
||||
* release.
|
||||
*
|
||||
* The 2005-05-05 release was the first one to define YYPATCH, so
|
||||
* we treat any release that either 1) doesn't define YYPATCH or
|
||||
* 2) defines it to a value < 20170709 as being buggy.
|
||||
*/
|
||||
#if defined(YYBYACC) && (!defined(YYPATCH) || YYPATCH < 20170709)
|
||||
/*
|
||||
* Both Berkeley YACC and Bison define yydebug (under whatever name
|
||||
* it has) as a global, but Bison does so only if YYDEBUG is defined.
|
||||
* Berkeley YACC define it even if YYDEBUG isn't defined; declare it
|
||||
* here to suppress a warning.
|
||||
* Berkeley YACC, prior to the 2017-07-09 release, defines it even if
|
||||
* YYDEBUG isn't defined; declare it here to suppress a warning. The
|
||||
* 2017-07-09 release fixes that.
|
||||
*/
|
||||
#if !defined(YYDEBUG)
|
||||
extern int yydebug;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* In Berkeley YACC, yynerrs (under whatever name it has) is global,
|
||||
* even if it's building a reentrant parser. In Bison, it's local
|
||||
* in reentrant parsers.
|
||||
* In Berkeley YACC, prior to the 2017-07-09 release, yynerrs (under
|
||||
* whatever name it has) is global, even if it's building a reentrant
|
||||
* parser. In Bison, and in the Berkeley YACC 2017-07-09 release and
|
||||
* later, it's local in reentrant parsers.
|
||||
*
|
||||
* Declare it to squelch a warning.
|
||||
*/
|
||||
@ -232,7 +240,7 @@ str2tok(const char *str, const struct tok *toks)
|
||||
int i;
|
||||
|
||||
for (i = 0; toks[i].s != NULL; i++) {
|
||||
if (pcap_strcasecmp(toks[i].s, str) == 0) {
|
||||
if (pcapint_strcasecmp(toks[i].s, str) == 0) {
|
||||
/*
|
||||
* Just in case somebody is using this to
|
||||
* generate values of -1/0xFFFFFFFF.
|
||||
@ -422,6 +430,14 @@ DIAG_OFF_BISON_BYACC
|
||||
%%
|
||||
prog: null expr
|
||||
{
|
||||
/*
|
||||
* I'm not sure we have a reason to use yynerrs, but it's
|
||||
* declared, and incremented, whether we need it or not,
|
||||
* which means that Clang 15 will give a "used but not
|
||||
* set" warning. This should suppress the warning for
|
||||
* yynerrs without suppressing it for other variables.
|
||||
*/
|
||||
(void) yynerrs;
|
||||
CHECK_INT_VAL(finish_parse(cstate, $2.b));
|
||||
}
|
||||
| null
|
||||
@ -444,25 +460,59 @@ id: nid
|
||||
| paren pid ')' { $$ = $2; }
|
||||
;
|
||||
nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.q = $<blk>0.q))); }
|
||||
| HID '/' NUM { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3,
|
||||
$$.q = $<blk>0.q))); }
|
||||
| HID NETMASK HID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0,
|
||||
$$.q = $<blk>0.q))); }
|
||||
| HID {
|
||||
| HID '/' NUM {
|
||||
CHECK_PTR_VAL($1);
|
||||
/* Decide how to parse HID based on proto */
|
||||
/* Check whether HID/NUM is being used when appropriate */
|
||||
$$.q = $<blk>0.q;
|
||||
if ($$.q.addr == Q_PORT) {
|
||||
bpf_set_error(cstate, "'port' modifier applied to ip host");
|
||||
bpf_set_error(cstate, "'port' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PORTRANGE) {
|
||||
bpf_set_error(cstate, "'portrange' modifier applied to ip host");
|
||||
bpf_set_error(cstate, "'portrange' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTO) {
|
||||
bpf_set_error(cstate, "'proto' modifier applied to ip host");
|
||||
bpf_set_error(cstate, "'proto' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTOCHAIN) {
|
||||
bpf_set_error(cstate, "'protochain' modifier applied to ip host");
|
||||
bpf_set_error(cstate, "'protochain' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
}
|
||||
CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, NULL, $3, $$.q)));
|
||||
}
|
||||
| HID NETMASK HID {
|
||||
CHECK_PTR_VAL($1);
|
||||
/* Check whether HID mask HID is being used when appropriate */
|
||||
$$.q = $<blk>0.q;
|
||||
if ($$.q.addr == Q_PORT) {
|
||||
bpf_set_error(cstate, "'port' modifier applied to IP address and netmask");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PORTRANGE) {
|
||||
bpf_set_error(cstate, "'portrange' modifier applied to IP address and netmask");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTO) {
|
||||
bpf_set_error(cstate, "'proto' modifier applied to IP address and netmask");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTOCHAIN) {
|
||||
bpf_set_error(cstate, "'protochain' modifier applied to IP address and netmask");
|
||||
YYABORT;
|
||||
}
|
||||
CHECK_PTR_VAL(($$.b = gen_mcode(cstate, $1, $3, 0, $$.q)));
|
||||
}
|
||||
| HID {
|
||||
CHECK_PTR_VAL($1);
|
||||
/* Check whether HID is being used when appropriate */
|
||||
$$.q = $<blk>0.q;
|
||||
if ($$.q.addr == Q_PORT) {
|
||||
bpf_set_error(cstate, "'port' modifier applied to IP address");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PORTRANGE) {
|
||||
bpf_set_error(cstate, "'portrange' modifier applied to IP address");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTO) {
|
||||
bpf_set_error(cstate, "'proto' modifier applied to IP address");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTOCHAIN) {
|
||||
bpf_set_error(cstate, "'protochain' modifier applied to IP address");
|
||||
YYABORT;
|
||||
}
|
||||
CHECK_PTR_VAL(($$.b = gen_ncode(cstate, $1, 0, $$.q)));
|
||||
@ -470,10 +520,24 @@ nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.
|
||||
| HID6 '/' NUM {
|
||||
CHECK_PTR_VAL($1);
|
||||
#ifdef INET6
|
||||
CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, NULL, $3,
|
||||
$$.q = $<blk>0.q)));
|
||||
/* Check whether HID6/NUM is being used when appropriate */
|
||||
$$.q = $<blk>0.q;
|
||||
if ($$.q.addr == Q_PORT) {
|
||||
bpf_set_error(cstate, "'port' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PORTRANGE) {
|
||||
bpf_set_error(cstate, "'portrange' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTO) {
|
||||
bpf_set_error(cstate, "'proto' modifier applied to IP address and prefix length ");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTOCHAIN) {
|
||||
bpf_set_error(cstate, "'protochain' modifier applied to IP address and prefix length");
|
||||
YYABORT;
|
||||
}
|
||||
CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, $3, $$.q)));
|
||||
#else
|
||||
bpf_set_error(cstate, "'ip6addr/prefixlen' not supported "
|
||||
bpf_set_error(cstate, "IPv6 addresses not supported "
|
||||
"in this configuration");
|
||||
YYABORT;
|
||||
#endif /*INET6*/
|
||||
@ -481,10 +545,24 @@ nid: ID { CHECK_PTR_VAL($1); CHECK_PTR_VAL(($$.b = gen_scode(cstate, $1, $$.
|
||||
| HID6 {
|
||||
CHECK_PTR_VAL($1);
|
||||
#ifdef INET6
|
||||
CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 0, 128,
|
||||
$$.q = $<blk>0.q)));
|
||||
/* Check whether HID6 is being used when appropriate */
|
||||
$$.q = $<blk>0.q;
|
||||
if ($$.q.addr == Q_PORT) {
|
||||
bpf_set_error(cstate, "'port' modifier applied to IP address");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PORTRANGE) {
|
||||
bpf_set_error(cstate, "'portrange' modifier applied to IP address");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTO) {
|
||||
bpf_set_error(cstate, "'proto' modifier applied to 'ip6addr/prefixlen");
|
||||
YYABORT;
|
||||
} else if ($$.q.addr == Q_PROTOCHAIN) {
|
||||
bpf_set_error(cstate, "'protochain' modifier applied to IP address");
|
||||
YYABORT;
|
||||
}
|
||||
CHECK_PTR_VAL(($$.b = gen_mcode6(cstate, $1, 128, $$.q)));
|
||||
#else
|
||||
bpf_set_error(cstate, "'ip6addr' not supported "
|
||||
bpf_set_error(cstate, "IPv6 addresses not supported "
|
||||
"in this configuration");
|
||||
YYABORT;
|
||||
#endif /*INET6*/
|
||||
@ -711,11 +789,11 @@ type_subtype: ID { int i;
|
||||
|
||||
pllc: LLC { CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
|
||||
| LLC ID { CHECK_PTR_VAL($2);
|
||||
if (pcap_strcasecmp($2, "i") == 0) {
|
||||
if (pcapint_strcasecmp($2, "i") == 0) {
|
||||
CHECK_PTR_VAL(($$ = gen_llc_i(cstate)));
|
||||
} else if (pcap_strcasecmp($2, "s") == 0) {
|
||||
} else if (pcapint_strcasecmp($2, "s") == 0) {
|
||||
CHECK_PTR_VAL(($$ = gen_llc_s(cstate)));
|
||||
} else if (pcap_strcasecmp($2, "u") == 0) {
|
||||
} else if (pcapint_strcasecmp($2, "u") == 0) {
|
||||
CHECK_PTR_VAL(($$ = gen_llc_u(cstate)));
|
||||
} else {
|
||||
int subtype;
|
||||
@ -739,13 +817,13 @@ pllc: LLC { CHECK_PTR_VAL(($$ = gen_llc(cstate))); }
|
||||
|
||||
dir: NUM { $$ = (int)$1; }
|
||||
| ID { CHECK_PTR_VAL($1);
|
||||
if (pcap_strcasecmp($1, "nods") == 0)
|
||||
if (pcapint_strcasecmp($1, "nods") == 0)
|
||||
$$ = IEEE80211_FC1_DIR_NODS;
|
||||
else if (pcap_strcasecmp($1, "tods") == 0)
|
||||
else if (pcapint_strcasecmp($1, "tods") == 0)
|
||||
$$ = IEEE80211_FC1_DIR_TODS;
|
||||
else if (pcap_strcasecmp($1, "fromds") == 0)
|
||||
else if (pcapint_strcasecmp($1, "fromds") == 0)
|
||||
$$ = IEEE80211_FC1_DIR_FROMDS;
|
||||
else if (pcap_strcasecmp($1, "dstods") == 0)
|
||||
else if (pcapint_strcasecmp($1, "dstods") == 0)
|
||||
$$ = IEEE80211_FC1_DIR_DSTODS;
|
||||
else {
|
||||
bpf_set_error(cstate, "unknown 802.11 direction");
|
||||
|
@ -1,250 +1,541 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
#!/bin/sh
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5 (mit/util/scripts/install.sh).
|
||||
|
||||
scriptversion=2020-11-14.01; # UTC
|
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
# following copyright and license.
|
||||
#
|
||||
# Copyright 1991 by the Massachusetts Institute of Technology
|
||||
# Copyright (C) 1994 X Consortium
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of M.I.T. not be used in advertising or
|
||||
# publicity pertaining to distribution of the software without specific,
|
||||
# written prior permission. M.I.T. makes no representations about the
|
||||
# suitability of this software for any purpose. It is provided "as is"
|
||||
# without express or implied warranty.
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
# Except as contained in this notice, the name of the X Consortium shall not
|
||||
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||
# ings in this Software without prior written authorization from the X Consor-
|
||||
# tium.
|
||||
#
|
||||
#
|
||||
# FSF changes to this file are in the public domain.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# 'make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. It can only install one file at a time, a restriction
|
||||
# shared with many OS's install programs.
|
||||
# from scratch.
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
tab=' '
|
||||
nl='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
IFS=" $tab$nl"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
# Set DOITPROG to "echo" to test this script.
|
||||
|
||||
pathcomp=''
|
||||
doit=${DOITPROG-}
|
||||
doit_exec=${doit:-exec}
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
# Put in absolute file names if you don't have them in your path;
|
||||
# or use environment vars.
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
chgrpprog=${CHGRPPROG-chgrp}
|
||||
chmodprog=${CHMODPROG-chmod}
|
||||
chownprog=${CHOWNPROG-chown}
|
||||
cmpprog=${CMPPROG-cmp}
|
||||
cpprog=${CPPROG-cp}
|
||||
mkdirprog=${MKDIRPROG-mkdir}
|
||||
mvprog=${MVPROG-mv}
|
||||
rmprog=${RMPROG-rm}
|
||||
stripprog=${STRIPPROG-strip}
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
posix_mkdir=
|
||||
|
||||
# Desired mode of installed file.
|
||||
mode=0755
|
||||
|
||||
# Create dirs (including intermediate dirs) using mode 755.
|
||||
# This is like GNU 'install' as of coreutils 8.32 (2020).
|
||||
mkdir_umask=22
|
||||
|
||||
backupsuffix=
|
||||
chgrpcmd=
|
||||
chmodcmd=$chmodprog
|
||||
chowncmd=
|
||||
mvcmd=$mvprog
|
||||
rmcmd="$rmprog -f"
|
||||
stripcmd=
|
||||
|
||||
src=
|
||||
dst=
|
||||
dir_arg=
|
||||
dst_arg=
|
||||
|
||||
copy_on_change=false
|
||||
is_target_a_directory=possibly
|
||||
|
||||
usage="\
|
||||
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||
or: $0 [OPTION]... -d DIRECTORIES...
|
||||
|
||||
In the 1st form, copy SRCFILE to DSTFILE.
|
||||
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||
In the 4th, create DIRECTORIES.
|
||||
|
||||
Options:
|
||||
--help display this help and exit.
|
||||
--version display version info and exit.
|
||||
|
||||
-c (ignored)
|
||||
-C install only if different (preserve data modification time)
|
||||
-d create directories instead of installing files.
|
||||
-g GROUP $chgrpprog installed files to GROUP.
|
||||
-m MODE $chmodprog installed files to MODE.
|
||||
-o USER $chownprog installed files to USER.
|
||||
-p pass -p to $cpprog.
|
||||
-s $stripprog installed files.
|
||||
-S SUFFIX attempt to back up existing files, with suffix SUFFIX.
|
||||
-t DIRECTORY install into DIRECTORY.
|
||||
-T report an error if DSTFILE is a directory.
|
||||
|
||||
Environment variables override the default commands:
|
||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||
RMPROG STRIPPROG
|
||||
|
||||
By default, rm is invoked with -f; when overridden with RMPROG,
|
||||
it's up to you to specify -f if you want it.
|
||||
|
||||
If -S is not specified, no backups are attempted.
|
||||
|
||||
Email bug reports to bug-automake@gnu.org.
|
||||
Automake home page: https://www.gnu.org/software/automake/
|
||||
"
|
||||
|
||||
while test $# -ne 0; do
|
||||
case $1 in
|
||||
-c) ;;
|
||||
|
||||
-C) copy_on_change=true;;
|
||||
|
||||
-d) dir_arg=true;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift;;
|
||||
|
||||
--help) echo "$usage"; exit $?;;
|
||||
|
||||
-m) mode=$2
|
||||
case $mode in
|
||||
*' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
|
||||
echo "$0: invalid mode: $mode" >&2
|
||||
exit 1;;
|
||||
esac
|
||||
shift;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift;;
|
||||
|
||||
-p) cpprog="$cpprog -p";;
|
||||
|
||||
-s) stripcmd=$stripprog;;
|
||||
|
||||
-S) backupsuffix="$2"
|
||||
shift;;
|
||||
|
||||
-t)
|
||||
is_target_a_directory=always
|
||||
dst_arg=$2
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $dst_arg in
|
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||
esac
|
||||
shift;;
|
||||
|
||||
-T) is_target_a_directory=never;;
|
||||
|
||||
--version) echo "$0 $scriptversion"; exit $?;;
|
||||
|
||||
--) shift
|
||||
break;;
|
||||
|
||||
-*) echo "$0: invalid option: $1" >&2
|
||||
exit 1;;
|
||||
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# We allow the use of options -d and -T together, by making -d
|
||||
# take the precedence; this is for compatibility with GNU install.
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
if test -n "$dst_arg"; then
|
||||
echo "$0: target directory not allowed when installing a directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||
# When -d is used, all remaining arguments are directories to create.
|
||||
# When -t is used, the destination is already specified.
|
||||
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||
for arg
|
||||
do
|
||||
if test -n "$dst_arg"; then
|
||||
# $@ is not empty: it contains at least $arg.
|
||||
set fnord "$@" "$dst_arg"
|
||||
shift # fnord
|
||||
fi
|
||||
shift # arg
|
||||
dst_arg=$arg
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $dst_arg in
|
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
if test $# -eq 0; then
|
||||
if test -z "$dir_arg"; then
|
||||
echo "$0: no input file specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
# It's OK to call 'install-sh -d' without argument.
|
||||
# This can happen when creating conditional directories.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
if test -z "$dir_arg"; then
|
||||
if test $# -gt 1 || test "$is_target_a_directory" = always; then
|
||||
if test ! -d "$dst_arg"; then
|
||||
echo "$0: $dst_arg: Is not a directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
if test -z "$dir_arg"; then
|
||||
do_exit='(exit $ret); exit $ret'
|
||||
trap "ret=129; $do_exit" 1
|
||||
trap "ret=130; $do_exit" 2
|
||||
trap "ret=141; $do_exit" 13
|
||||
trap "ret=143; $do_exit" 15
|
||||
|
||||
# Set umask so as not to create temps with too-generous modes.
|
||||
# However, 'strip' requires both read and write access to temps.
|
||||
case $mode in
|
||||
# Optimize common cases.
|
||||
*644) cp_umask=133;;
|
||||
*755) cp_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw='% 200'
|
||||
fi
|
||||
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||
*)
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw=,u+rw
|
||||
fi
|
||||
cp_umask=$mode$u_plus_rw;;
|
||||
esac
|
||||
fi
|
||||
|
||||
for src
|
||||
do
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $src in
|
||||
-* | [=\(\)!]) src=./$src;;
|
||||
esac
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
dst=$src
|
||||
dstdir=$dst
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
# Don't chown directories that already exist.
|
||||
if test $dstdir_status = 0; then
|
||||
chowncmd=""
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
if test ! -f "$src" && test ! -d "$src"; then
|
||||
echo "$0: $src does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$dst_arg"; then
|
||||
echo "$0: no destination specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
dst=$dst_arg
|
||||
|
||||
# If destination is a directory, append the input filename.
|
||||
if test -d "$dst"; then
|
||||
if test "$is_target_a_directory" = never; then
|
||||
echo "$0: $dst_arg: Is a directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
dstdir=$dst
|
||||
dstbase=`basename "$src"`
|
||||
case $dst in
|
||||
*/) dst=$dst$dstbase;;
|
||||
*) dst=$dst/$dstbase;;
|
||||
esac
|
||||
dstdir_status=0
|
||||
else
|
||||
dstdir=`dirname "$dst"`
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
case $dstdir in
|
||||
*/) dstdirslash=$dstdir;;
|
||||
*) dstdirslash=$dstdir/;;
|
||||
esac
|
||||
|
||||
obsolete_mkdir_used=false
|
||||
|
||||
if test $dstdir_status != 0; then
|
||||
case $posix_mkdir in
|
||||
'')
|
||||
# With -d, create the new directory with the user-specified mode.
|
||||
# Otherwise, rely on $mkdir_umask.
|
||||
if test -n "$dir_arg"; then
|
||||
mkdir_mode=-m$mode
|
||||
else
|
||||
mkdir_mode=
|
||||
fi
|
||||
|
||||
posix_mkdir=false
|
||||
# The $RANDOM variable is not portable (e.g., dash). Use it
|
||||
# here however when possible just to lower collision chance.
|
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||
|
||||
trap '
|
||||
ret=$?
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
|
||||
exit $ret
|
||||
' 0
|
||||
|
||||
# Because "mkdir -p" follows existing symlinks and we likely work
|
||||
# directly in world-writeable /tmp, make sure that the '$tmpdir'
|
||||
# directory is successfully created first before we actually test
|
||||
# 'mkdir -p'.
|
||||
if (umask $mkdir_umask &&
|
||||
$mkdirprog $mkdir_mode "$tmpdir" &&
|
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
test_tmpdir="$tmpdir/a"
|
||||
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
d????-?r-*) different_mode=700;;
|
||||
d????-?--*) different_mode=755;;
|
||||
*) false;;
|
||||
esac &&
|
||||
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
|
||||
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
|
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||
}
|
||||
}
|
||||
then posix_mkdir=:
|
||||
fi
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
# Remove any dirs left behind by ancient mkdir implementations.
|
||||
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
|
||||
fi
|
||||
trap '' 0;;
|
||||
esac
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
if
|
||||
$posix_mkdir && (
|
||||
umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||
)
|
||||
then :
|
||||
else
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
# mkdir does not conform to POSIX,
|
||||
# or it failed possibly due to a race condition. Create the
|
||||
# directory the slow way, step by step, checking for races as we go.
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
case $dstdir in
|
||||
/*) prefix='/';;
|
||||
[-=\(\)!]*) prefix='./';;
|
||||
*) prefix='';;
|
||||
esac
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
oIFS=$IFS
|
||||
IFS=/
|
||||
set -f
|
||||
set fnord $dstdir
|
||||
shift
|
||||
set +f
|
||||
IFS=$oIFS
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
prefixes=
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
for d
|
||||
do
|
||||
test X"$d" = X && continue
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
prefix=$prefix$d
|
||||
if test -d "$prefix"; then
|
||||
prefixes=
|
||||
else
|
||||
if $posix_mkdir; then
|
||||
(umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||
# Don't fail if two instances are running concurrently.
|
||||
test -d "$prefix" || exit 1
|
||||
else
|
||||
case $prefix in
|
||||
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||
*) qprefix=$prefix;;
|
||||
esac
|
||||
prefixes="$prefixes '$qprefix'"
|
||||
fi
|
||||
fi
|
||||
prefix=$prefix/
|
||||
done
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
if test -n "$prefixes"; then
|
||||
# Don't fail if two instances are running concurrently.
|
||||
(umask $mkdir_umask &&
|
||||
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||
test -d "$dstdir" || exit 1
|
||||
obsolete_mkdir_used=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
if test -n "$dir_arg"; then
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||
else
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
# Make a couple of temp file names in the proper directory.
|
||||
dsttmp=${dstdirslash}_inst.$$_
|
||||
rmtmp=${dstdirslash}_rm.$$_
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
# Trap to clean up those temp files at exit.
|
||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
# Copy the file name to the temp name.
|
||||
(umask $cp_umask &&
|
||||
{ test -z "$stripcmd" || {
|
||||
# Create $dsttmp read-write so that cp doesn't create it read-only,
|
||||
# which would cause strip to fail.
|
||||
if test -z "$doit"; then
|
||||
: >"$dsttmp" # No need to fork-exec 'touch'.
|
||||
else
|
||||
$doit touch "$dsttmp"
|
||||
fi
|
||||
}
|
||||
} &&
|
||||
$doit_exec $cpprog "$src" "$dsttmp") &&
|
||||
|
||||
fi &&
|
||||
# and set any options; do chmod last to preserve setuid bits.
|
||||
#
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||
#
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
||||
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
||||
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||
|
||||
# If -C, don't bother to copy if it wouldn't change the file.
|
||||
if $copy_on_change &&
|
||||
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
||||
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
||||
set -f &&
|
||||
set X $old && old=:$2:$4:$5:$6 &&
|
||||
set X $new && new=:$2:$4:$5:$6 &&
|
||||
set +f &&
|
||||
test "$old" = "$new" &&
|
||||
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
||||
then
|
||||
rm -f "$dsttmp"
|
||||
else
|
||||
# If $backupsuffix is set, and the file being installed
|
||||
# already exists, attempt a backup. Don't worry if it fails,
|
||||
# e.g., if mv doesn't support -f.
|
||||
if test -n "$backupsuffix" && test -f "$dst"; then
|
||||
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
|
||||
fi
|
||||
|
||||
exit 0
|
||||
# Rename the file to the real destination.
|
||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||
|
||||
# The rename failed, perhaps because mv can't rename something else
|
||||
# to itself, or perhaps because mv is so ancient that it does not
|
||||
# support -f.
|
||||
{
|
||||
# Now remove or move aside any old file at destination location.
|
||||
# We try this two ways since rm can't unlink itself on some
|
||||
# systems and the destination file might be busy for other
|
||||
# reasons. In this case, the final cleanup might fail but the new
|
||||
# file should still install successfully.
|
||||
{
|
||||
test ! -f "$dst" ||
|
||||
$doit $rmcmd "$dst" 2>/dev/null ||
|
||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
|
||||
} ||
|
||||
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||
(exit 1); exit 1
|
||||
}
|
||||
} &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
$doit $mvcmd "$dsttmp" "$dst"
|
||||
}
|
||||
fi || exit 1
|
||||
|
||||
trap '' 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
|
@ -11,7 +11,7 @@
|
||||
* it been given an infinite-sized buffer.
|
||||
*/
|
||||
int
|
||||
pcap_vasprintf(char **strp, const char *format, va_list args)
|
||||
pcapint_vasprintf(char **strp, const char *format, va_list args)
|
||||
{
|
||||
char buf;
|
||||
int len;
|
||||
@ -21,7 +21,7 @@ pcap_vasprintf(char **strp, const char *format, va_list args)
|
||||
|
||||
/*
|
||||
* XXX - the C99 standard says, in section 7.19.6.5 "The
|
||||
* nprintf function":
|
||||
* snprintf function":
|
||||
*
|
||||
* The snprintf function is equivalent to fprintf, except that
|
||||
* the output is written into an array (specified by argument s)
|
||||
@ -88,13 +88,13 @@ pcap_vasprintf(char **strp, const char *format, va_list args)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_asprintf(char **strp, const char *format, ...)
|
||||
pcapint_asprintf(char **strp, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
va_start(args, format);
|
||||
ret = pcap_vasprintf(strp, format, args);
|
||||
ret = pcapint_vasprintf(strp, format, args);
|
||||
va_end(args);
|
||||
return (ret);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: pcap_strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */
|
||||
/* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
@ -16,9 +16,7 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@ -33,7 +31,7 @@
|
||||
* If retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
pcap_strlcat(char * restrict dst, const char * restrict src, size_t dsize)
|
||||
pcapint_strlcat(char * restrict dst, const char * restrict src, size_t dsize)
|
||||
{
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: pcap_strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
|
||||
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
@ -16,9 +16,7 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@ -31,7 +29,7 @@
|
||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
pcap_strlcpy(char * restrict dst, const char * restrict src, size_t dsize)
|
||||
pcapint_strlcpy(char * restrict dst, const char * restrict src, size_t dsize)
|
||||
{
|
||||
const char *osrc = src;
|
||||
size_t nleft = dsize;
|
||||
|
@ -34,14 +34,12 @@
|
||||
* From: @(#)strtok.c 8.1 (Berkeley) 6/4/93
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "portability.h"
|
||||
|
||||
char *
|
||||
pcap_strtok_r(char *s, const char *delim, char **last)
|
||||
pcapint_strtok_r(char *s, const char *delim, char **last)
|
||||
{
|
||||
char *spanp, *tok;
|
||||
int c, sc;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "portability.h"
|
||||
|
||||
int
|
||||
pcap_vasprintf(char **strp, const char *format, va_list args)
|
||||
pcapint_vasprintf(char **strp, const char *format, va_list args)
|
||||
{
|
||||
int len;
|
||||
size_t str_size;
|
||||
@ -39,13 +39,13 @@ pcap_vasprintf(char **strp, const char *format, va_list args)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_asprintf(char **strp, const char *format, ...)
|
||||
pcapint_asprintf(char **strp, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
va_start(args, format);
|
||||
ret = pcap_vasprintf(strp, format, args);
|
||||
ret = pcapint_vasprintf(strp, format, args);
|
||||
va_end(args);
|
||||
return (ret);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh -
|
||||
#!/bin/sh -e
|
||||
#
|
||||
# Copyright (c) 1994, 1996
|
||||
# The Regents of the University of California. All rights reserved.
|
||||
@ -68,20 +68,20 @@ if [ $# = 0 ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -w $MAKE ]; then
|
||||
if [ ! -w "$MAKE" ]; then
|
||||
echo "mkdep: no writeable file \"$MAKE\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TMP=/tmp/mkdep$$
|
||||
TMP=${TMPDIR:-/tmp}/mkdep$$
|
||||
|
||||
trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
|
||||
trap 'rm -f "$TMP" ; exit 1' HUP INT QUIT PIPE TERM
|
||||
|
||||
cp $MAKE ${MAKE}.bak
|
||||
cp "$MAKE" "${MAKE}.bak"
|
||||
|
||||
sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
|
||||
sed -e '/DO NOT DELETE THIS LINE/,$d' < "$MAKE" > "$TMP"
|
||||
|
||||
cat << _EOF_ >> $TMP
|
||||
cat << _EOF_ >> "$TMP"
|
||||
# DO NOT DELETE THIS LINE -- mkdep uses it.
|
||||
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
|
||||
|
||||
@ -99,23 +99,25 @@ _EOF_
|
||||
# Construct a list of source files with paths relative to the source directory.
|
||||
#
|
||||
sources=""
|
||||
for srcfile in $*
|
||||
for srcfile in "$@"
|
||||
do
|
||||
sources="$sources $SOURCE_DIRECTORY/$srcfile"
|
||||
done
|
||||
|
||||
# XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
|
||||
$CC $DEPENDENCY_CFLAG $flags $sources |
|
||||
# $flags and $sources are meant to expand
|
||||
# shellcheck disable=SC2086
|
||||
"$CC" "$DEPENDENCY_CFLAG" $flags $sources |
|
||||
sed "
|
||||
s; \./; ;g
|
||||
$SED" >> $TMP
|
||||
$SED" >> "$TMP"
|
||||
|
||||
cat << _EOF_ >> $TMP
|
||||
cat << _EOF_ >> "$TMP"
|
||||
|
||||
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
|
||||
_EOF_
|
||||
|
||||
# copy to preserve permissions
|
||||
cp $TMP $MAKE
|
||||
rm -f ${MAKE}.bak $TMP
|
||||
cp "$TMP" "$MAKE"
|
||||
rm -f "${MAKE}.bak" "$TMP"
|
||||
exit 0
|
||||
|
@ -84,7 +84,7 @@ hc386.arg: msdos\Makefile
|
||||
-Hnocopyr
|
||||
-Hpragma=Offwarn(491,553,572)
|
||||
-Hon=Recognize_library # make memcpy/strlen etc. inline
|
||||
-Hoff=Behaved # turn off some optimiser warnings
|
||||
-Hoff=Behaved # turn off some optimizer warnings
|
||||
| $<
|
||||
|
||||
clean:
|
||||
|
@ -9,7 +9,7 @@
|
||||
# Note: you should do a "set LFN=y" before running this makefile.
|
||||
#
|
||||
|
||||
VPATH = missing msdos bpf/net
|
||||
VPATH = missing msdos
|
||||
|
||||
PREREQUISITES = scanner.c grammar.c tokdefs.h version.h msdos/pkt_stub.inc
|
||||
|
||||
@ -22,7 +22,7 @@ CFLAGS += -DDEBUG -DNDIS_DEBUG -DHAVE_LIMITS_H -DHAVE_STRERROR -DHAVE_SNPRINTF -
|
||||
|
||||
CFLAGS += -Dyylval=pcap_lval # -DBDEBUG -DNDEBUG
|
||||
|
||||
SOURCES = grammar.c scanner.c bpf/net/bpf_filter.c bpf_image.c bpf_dump.c \
|
||||
SOURCES = grammar.c scanner.c bpf_filter.c bpf_image.c bpf_dump.c \
|
||||
etherent.c gencode.c nametoaddr.c pcap-common.c pcap-dos.c optimize.c \
|
||||
savefile.c pcap.c sf-pcap.c sf-pcapng.c \
|
||||
msdos/pktdrvr.c msdos/ndis2.c # missing/snprintf.c
|
||||
|
@ -52,8 +52,8 @@ $(OBJDIR)\pktdrvr.obj: msdos\pkt_stub.inc msdos\pktdrvr.c &
|
||||
pcap-dos.h pcap-int.h pcap.h msdos\pktdrvr.h
|
||||
*$(CC) $(CFLAGS) msdos\pktdrvr.c -fo=$@
|
||||
|
||||
$(OBJDIR)\bpf_filter.obj: bpf\net\bpf_filter.c
|
||||
*$(CC) $(CFLAGS) bpf\net\bpf_filter.c -fo=$@
|
||||
$(OBJDIR)\bpf_filter.obj: bpf_filter.c
|
||||
*$(CC) $(CFLAGS) bpf_filter.c -fo=$@
|
||||
|
||||
$(OBJDIR)\ndis2.obj: msdos\ndis2.c
|
||||
*$(CC) $(CFLAGS) msdos\ndis2.c -fo=$@
|
||||
@ -94,7 +94,7 @@ clean realclean vclean: .SYMBOLIC
|
||||
#
|
||||
# dependencies
|
||||
#
|
||||
$(OBJDIR)\bpf_filter.obj: bpf\net\bpf_filter.c pcap-int.h pcap.h pcap-bpf.h
|
||||
$(OBJDIR)\bpf_filter.obj: bpf_filter.c pcap-int.h pcap.h pcap-bpf.h
|
||||
|
||||
$(OBJDIR)\bpf_imag.obj: bpf_imag.c pcap-int.h pcap.h pcap-bpf.h
|
||||
|
||||
|
@ -294,7 +294,7 @@ PUBLIC char const *PktRXmodeStr (PKT_RX_MODE mode)
|
||||
"Receive direct & broadcast packets",
|
||||
"Receive direct,broadcast and limited multicast packets",
|
||||
"Receive direct,broadcast and all multicast packets",
|
||||
"Receive all packets (promiscuouos mode)"
|
||||
"Receive all packets (promiscuous mode)"
|
||||
};
|
||||
|
||||
if (mode > DIM(modeStr))
|
||||
|
@ -47,7 +47,7 @@ typedef struct {
|
||||
|
||||
|
||||
typedef struct {
|
||||
BYTE class; /* = 1 for DEC/Interl/Xerox Ethernet */
|
||||
BYTE class; /* = 1 for DEC/Intel/Xerox Ethernet */
|
||||
BYTE number; /* = 0 for single LAN adapter */
|
||||
WORD type; /* = 13 for 3C523 */
|
||||
BYTE funcs; /* Basic/Extended/HiPerf functions */
|
||||
|
@ -13,7 +13,7 @@ supported:
|
||||
Note: the files in the libpcap.zip contains short truncated filenames.
|
||||
So for djgpp to work with these, disable the use of long file names by
|
||||
setting "LFN=n" in the environment. On the other hand, if you get libpcap
|
||||
from Github or the official libpcap.tar.gz, some filenames are beyond 8+3.
|
||||
from GitHub or the official libpcap.tar.gz, some filenames are beyond 8+3.
|
||||
In this case set "LFN=y".
|
||||
|
||||
Files specific to DOS are pcap-dos.[ch] and the assembly and C files in
|
||||
@ -53,7 +53,7 @@ The following packages and tools must be present for all targets.
|
||||
|
||||
https://www.watt-32.net
|
||||
|
||||
2. Exception handler and disassember library (libexc.a) is needed if
|
||||
2. Exception handler and disassembler library (libexc.a) is needed if
|
||||
"USE_EXCEPT = 1" in common.dj. Available at:
|
||||
|
||||
https://www.watt-32.net/misc/exc_dx07.zip
|
||||
|
@ -22,9 +22,7 @@
|
||||
* These functions are not time critical.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef DECNETLIB
|
||||
#include <sys/types.h>
|
||||
@ -140,6 +138,8 @@
|
||||
#include <pcap/namedb.h>
|
||||
#include "nametoaddr.h"
|
||||
|
||||
#include "thread-local.h"
|
||||
|
||||
#ifdef HAVE_OS_PROTO_H
|
||||
#include "os-proto.h"
|
||||
#endif
|
||||
@ -470,41 +470,34 @@ pcap_nametoport(const char *name, int *port, int *proto)
|
||||
int
|
||||
pcap_nametoportrange(const char *name, int *port1, int *port2, int *proto)
|
||||
{
|
||||
u_int p1, p2;
|
||||
char *off, *cpy;
|
||||
int save_proto;
|
||||
|
||||
if (sscanf(name, "%d-%d", &p1, &p2) != 2) {
|
||||
if ((cpy = strdup(name)) == NULL)
|
||||
return 0;
|
||||
if ((cpy = strdup(name)) == NULL)
|
||||
return 0;
|
||||
|
||||
if ((off = strchr(cpy, '-')) == NULL) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*off = '\0';
|
||||
|
||||
if (pcap_nametoport(cpy, port1, proto) == 0) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
save_proto = *proto;
|
||||
|
||||
if (pcap_nametoport(off + 1, port2, proto) == 0) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
if ((off = strchr(cpy, '-')) == NULL) {
|
||||
free(cpy);
|
||||
|
||||
if (*proto != save_proto)
|
||||
*proto = PROTO_UNDEF;
|
||||
} else {
|
||||
*port1 = p1;
|
||||
*port2 = p2;
|
||||
*proto = PROTO_UNDEF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*off = '\0';
|
||||
|
||||
if (pcap_nametoport(cpy, port1, proto) == 0) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
save_proto = *proto;
|
||||
|
||||
if (pcap_nametoport(off + 1, port2, proto) == 0) {
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
free(cpy);
|
||||
|
||||
if (*proto != save_proto)
|
||||
*proto = PROTO_UNDEF;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -742,16 +735,18 @@ pcap_ether_aton(const char *s)
|
||||
#ifndef HAVE_ETHER_HOSTTON
|
||||
/*
|
||||
* Roll our own.
|
||||
* XXX - not thread-safe, because pcap_next_etherent() isn't thread-
|
||||
* safe! Needs a mutex or a thread-safe pcap_next_etherent().
|
||||
*
|
||||
* This should be thread-safe, as we define the static variables
|
||||
* we use to be thread-local, and as pcap_next_etherent() does so
|
||||
* as well.
|
||||
*/
|
||||
u_char *
|
||||
pcap_ether_hostton(const char *name)
|
||||
{
|
||||
register struct pcap_etherent *ep;
|
||||
register u_char *ap;
|
||||
static FILE *fp = NULL;
|
||||
static int init = 0;
|
||||
static thread_local FILE *fp = NULL;
|
||||
static thread_local int init = 0;
|
||||
|
||||
if (!init) {
|
||||
fp = fopen(PCAP_ETHERS_FILE, "r");
|
||||
@ -790,7 +785,7 @@ pcap_ether_hostton(const char *name)
|
||||
/*
|
||||
* In AIX 7.1 and 7.2: int ether_hostton(char *, struct ether_addr *);
|
||||
*/
|
||||
pcap_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
pcapint_strlcpy(namebuf, name, sizeof(namebuf));
|
||||
ap = NULL;
|
||||
if (ether_hostton(namebuf, (struct ether_addr *)a) == 0) {
|
||||
ap = (u_char *)malloc(6);
|
||||
|
@ -19,7 +19,7 @@
|
||||
/* Types missing from some systems */
|
||||
|
||||
/*
|
||||
* Network layer prototocol identifiers
|
||||
* Network layer protocol identifiers
|
||||
*/
|
||||
#ifndef ISO8473_CLNP
|
||||
#define ISO8473_CLNP 0x81
|
||||
|
@ -21,9 +21,7 @@
|
||||
* Optimization module for BPF code intermediate representation.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap-types.h>
|
||||
|
||||
@ -207,7 +205,7 @@ lowest_set_bit(int mask)
|
||||
#define AX_ATOM N_ATOMS
|
||||
|
||||
/*
|
||||
* These data structures are used in a Cocke and Shwarz style
|
||||
* These data structures are used in a Cocke and Schwartz style
|
||||
* value numbering scheme. Since the flowgraph is acyclic,
|
||||
* exit values can be propagated from a node's predecessors
|
||||
* provided it is uniquely defined.
|
||||
@ -1467,6 +1465,12 @@ opt_deadstores(opt_state_t *opt_state, register struct block *b)
|
||||
for (atom = 0; atom < N_ATOMS; ++atom)
|
||||
if (last[atom] && !ATOMELEM(b->out_use, atom)) {
|
||||
last[atom]->code = NOP;
|
||||
/*
|
||||
* The store was removed as it's dead,
|
||||
* so the value stored into now has
|
||||
* an unknown value.
|
||||
*/
|
||||
vstore(0, &b->val[atom], VAL_UNKNOWN, 0);
|
||||
/*
|
||||
* XXX - optimizer loop detection.
|
||||
*/
|
||||
@ -1815,7 +1819,7 @@ opt_j(opt_state_t *opt_state, struct edge *ep)
|
||||
*
|
||||
*/
|
||||
static void
|
||||
or_pullup(opt_state_t *opt_state, struct block *b)
|
||||
or_pullup(opt_state_t *opt_state, struct block *b, struct block *root)
|
||||
{
|
||||
bpf_u_int32 val;
|
||||
int at_top;
|
||||
@ -1976,10 +1980,15 @@ or_pullup(opt_state_t *opt_state, struct block *b)
|
||||
* optimizer gets into one of those infinite loops.
|
||||
*/
|
||||
opt_state->done = 0;
|
||||
|
||||
/*
|
||||
* Recompute dominator sets as control flow graph has changed.
|
||||
*/
|
||||
find_dom(opt_state, root);
|
||||
}
|
||||
|
||||
static void
|
||||
and_pullup(opt_state_t *opt_state, struct block *b)
|
||||
and_pullup(opt_state_t *opt_state, struct block *b, struct block *root)
|
||||
{
|
||||
bpf_u_int32 val;
|
||||
int at_top;
|
||||
@ -2072,6 +2081,11 @@ and_pullup(opt_state_t *opt_state, struct block *b)
|
||||
* optimizer gets into one of those infinite loops.
|
||||
*/
|
||||
opt_state->done = 0;
|
||||
|
||||
/*
|
||||
* Recompute dominator sets as control flow graph has changed.
|
||||
*/
|
||||
find_dom(opt_state, root);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2118,8 +2132,8 @@ opt_blks(opt_state_t *opt_state, struct icode *ic, int do_stmts)
|
||||
find_inedges(opt_state, ic->root);
|
||||
for (i = 1; i <= maxlevel; ++i) {
|
||||
for (p = opt_state->levels[i]; p; p = p->link) {
|
||||
or_pullup(opt_state, p);
|
||||
and_pullup(opt_state, p);
|
||||
or_pullup(opt_state, p, ic->root);
|
||||
and_pullup(opt_state, p, ic->root);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2942,14 +2956,14 @@ conv_error(conv_state_t *conv_state, const char *fmt, ...)
|
||||
* otherwise, return 0.
|
||||
*/
|
||||
int
|
||||
install_bpf_program(pcap_t *p, struct bpf_program *fp)
|
||||
pcapint_install_bpf_program(pcap_t *p, struct bpf_program *fp)
|
||||
{
|
||||
size_t prog_size;
|
||||
|
||||
/*
|
||||
* Validate the program.
|
||||
*/
|
||||
if (!pcap_validate_filter(fp->bf_insns, fp->bf_len)) {
|
||||
if (!pcapint_validate_filter(fp->bf_insns, fp->bf_len)) {
|
||||
snprintf(p->errbuf, sizeof(p->errbuf),
|
||||
"BPF program is not valid");
|
||||
return (-1);
|
||||
@ -2964,7 +2978,7 @@ install_bpf_program(pcap_t *p, struct bpf_program *fp)
|
||||
p->fcode.bf_len = fp->bf_len;
|
||||
p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
|
||||
if (p->fcode.bf_insns == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "malloc");
|
||||
return (-1);
|
||||
}
|
||||
|
@ -31,9 +31,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
@ -169,27 +167,27 @@ load_airpcap_functions(void)
|
||||
*/
|
||||
current_status = AIRPCAP_API_CANNOT_LOAD;
|
||||
|
||||
airpcap_lib = pcap_load_code("airpcap.dll");
|
||||
airpcap_lib = pcapint_load_code("airpcap.dll");
|
||||
if (airpcap_lib != NULL) {
|
||||
/*
|
||||
* OK, we've loaded the library; now try to find the
|
||||
* functions we need in it.
|
||||
*/
|
||||
p_AirpcapGetLastError = (AirpcapGetLastErrorHandler) pcap_find_function(airpcap_lib, "AirpcapGetLastError");
|
||||
p_AirpcapGetDeviceList = (AirpcapGetDeviceListHandler) pcap_find_function(airpcap_lib, "AirpcapGetDeviceList");
|
||||
p_AirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) pcap_find_function(airpcap_lib, "AirpcapFreeDeviceList");
|
||||
p_AirpcapOpen = (AirpcapOpenHandler) pcap_find_function(airpcap_lib, "AirpcapOpen");
|
||||
p_AirpcapClose = (AirpcapCloseHandler) pcap_find_function(airpcap_lib, "AirpcapClose");
|
||||
p_AirpcapSetDeviceMacFlags = (AirpcapSetDeviceMacFlagsHandler) pcap_find_function(airpcap_lib, "AirpcapSetDeviceMacFlags");
|
||||
p_AirpcapSetLinkType = (AirpcapSetLinkTypeHandler) pcap_find_function(airpcap_lib, "AirpcapSetLinkType");
|
||||
p_AirpcapGetLinkType = (AirpcapGetLinkTypeHandler) pcap_find_function(airpcap_lib, "AirpcapGetLinkType");
|
||||
p_AirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) pcap_find_function(airpcap_lib, "AirpcapSetKernelBuffer");
|
||||
p_AirpcapSetFilter = (AirpcapSetFilterHandler) pcap_find_function(airpcap_lib, "AirpcapSetFilter");
|
||||
p_AirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) pcap_find_function(airpcap_lib, "AirpcapSetMinToCopy");
|
||||
p_AirpcapGetReadEvent = (AirpcapGetReadEventHandler) pcap_find_function(airpcap_lib, "AirpcapGetReadEvent");
|
||||
p_AirpcapRead = (AirpcapReadHandler) pcap_find_function(airpcap_lib, "AirpcapRead");
|
||||
p_AirpcapWrite = (AirpcapWriteHandler) pcap_find_function(airpcap_lib, "AirpcapWrite");
|
||||
p_AirpcapGetStats = (AirpcapGetStatsHandler) pcap_find_function(airpcap_lib, "AirpcapGetStats");
|
||||
p_AirpcapGetLastError = (AirpcapGetLastErrorHandler) pcapint_find_function(airpcap_lib, "AirpcapGetLastError");
|
||||
p_AirpcapGetDeviceList = (AirpcapGetDeviceListHandler) pcapint_find_function(airpcap_lib, "AirpcapGetDeviceList");
|
||||
p_AirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) pcapint_find_function(airpcap_lib, "AirpcapFreeDeviceList");
|
||||
p_AirpcapOpen = (AirpcapOpenHandler) pcapint_find_function(airpcap_lib, "AirpcapOpen");
|
||||
p_AirpcapClose = (AirpcapCloseHandler) pcapint_find_function(airpcap_lib, "AirpcapClose");
|
||||
p_AirpcapSetDeviceMacFlags = (AirpcapSetDeviceMacFlagsHandler) pcapint_find_function(airpcap_lib, "AirpcapSetDeviceMacFlags");
|
||||
p_AirpcapSetLinkType = (AirpcapSetLinkTypeHandler) pcapint_find_function(airpcap_lib, "AirpcapSetLinkType");
|
||||
p_AirpcapGetLinkType = (AirpcapGetLinkTypeHandler) pcapint_find_function(airpcap_lib, "AirpcapGetLinkType");
|
||||
p_AirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) pcapint_find_function(airpcap_lib, "AirpcapSetKernelBuffer");
|
||||
p_AirpcapSetFilter = (AirpcapSetFilterHandler) pcapint_find_function(airpcap_lib, "AirpcapSetFilter");
|
||||
p_AirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) pcapint_find_function(airpcap_lib, "AirpcapSetMinToCopy");
|
||||
p_AirpcapGetReadEvent = (AirpcapGetReadEventHandler) pcapint_find_function(airpcap_lib, "AirpcapGetReadEvent");
|
||||
p_AirpcapRead = (AirpcapReadHandler) pcapint_find_function(airpcap_lib, "AirpcapRead");
|
||||
p_AirpcapWrite = (AirpcapWriteHandler) pcapint_find_function(airpcap_lib, "AirpcapWrite");
|
||||
p_AirpcapGetStats = (AirpcapGetStatsHandler) pcapint_find_function(airpcap_lib, "AirpcapGetStats");
|
||||
|
||||
//
|
||||
// Make sure that we found everything
|
||||
@ -275,11 +273,11 @@ airpcap_setfilter(pcap_t *p, struct bpf_program *fp)
|
||||
*/
|
||||
|
||||
/*
|
||||
* install_bpf_program() validates the program.
|
||||
* pcapint_install_bpf_program() validates the program.
|
||||
*
|
||||
* XXX - what if we already have a filter in the kernel?
|
||||
*/
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
if (pcapint_install_bpf_program(p, fp) < 0)
|
||||
return (-1);
|
||||
pa->filtering_in_kernel = 0; /* filtering in userland */
|
||||
return (0);
|
||||
@ -670,7 +668,7 @@ airpcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
*/
|
||||
if (pa->filtering_in_kernel ||
|
||||
p->fcode.bf_insns == NULL ||
|
||||
pcap_filter(p->fcode.bf_insns, datap, bhp->Originallen, caplen)) {
|
||||
pcapint_filter(p->fcode.bf_insns, datap, bhp->Originallen, caplen)) {
|
||||
struct pcap_pkthdr pkthdr;
|
||||
|
||||
pkthdr.ts.tv_sec = bhp->TsSec;
|
||||
@ -732,7 +730,7 @@ airpcap_cleanup(pcap_t *p)
|
||||
p_AirpcapClose(pa->adapter);
|
||||
pa->adapter = NULL;
|
||||
}
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -740,7 +738,7 @@ airpcap_breakloop(pcap_t *p)
|
||||
{
|
||||
HANDLE read_event;
|
||||
|
||||
pcap_breakloop_common(p);
|
||||
pcapint_breakloop_common(p);
|
||||
struct pcap_airpcap *pa = p->priv;
|
||||
|
||||
/* XXX - what if either of these fail? */
|
||||
@ -822,7 +820,7 @@ airpcap_activate(pcap_t *p)
|
||||
p->bufsize = AIRPCAP_DEFAULT_USER_BUFFER_SIZE;
|
||||
p->buffer = malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
@ -896,8 +894,11 @@ airpcap_activate(pcap_t *p)
|
||||
* followed by PPI, followed by "no radio metadata".
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 3);
|
||||
if (p->dlt_list == NULL)
|
||||
if (p->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
p->dlt_list[0] = DLT_IEEE802_11_RADIO;
|
||||
p->dlt_list[1] = DLT_PPI;
|
||||
p->dlt_list[2] = DLT_IEEE802_11;
|
||||
@ -1040,7 +1041,7 @@ airpcap_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
|
||||
for (airpcap_device = airpcap_devices; airpcap_device != NULL;
|
||||
airpcap_device = airpcap_device->next) {
|
||||
if (add_dev(devlistp, airpcap_device->Name, 0,
|
||||
if (pcapint_add_dev(devlistp, airpcap_device->Name, 0,
|
||||
airpcap_device->Description, errbuf) == NULL) {
|
||||
/*
|
||||
* Failure.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -32,13 +32,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
#include "pcap-bt-linux.h"
|
||||
#include "pcap/bluetooth.h"
|
||||
#include "diag-control.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@ -84,9 +83,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
/* if bluetooth is not supported this is not fatal*/
|
||||
if (errno == EAFNOSUPPORT)
|
||||
return 0;
|
||||
pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't open raw Bluetooth socket");
|
||||
return -1;
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
dev_list = malloc(HCI_MAX_DEV * sizeof(*dev_req) + sizeof(*dev_list));
|
||||
@ -94,7 +93,7 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
{
|
||||
snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't allocate %zu bytes for Bluetooth device list",
|
||||
HCI_MAX_DEV * sizeof(*dev_req) + sizeof(*dev_list));
|
||||
ret = -1;
|
||||
ret = PCAP_ERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -110,9 +109,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
|
||||
if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't get Bluetooth device list via ioctl");
|
||||
ret = -1;
|
||||
ret = PCAP_ERROR;
|
||||
goto free;
|
||||
}
|
||||
|
||||
@ -131,9 +130,9 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
* the status to PCAP_IF_CONNECTION_STATUS_CONNECTED
|
||||
* or PCAP_IF_CONNECTION_STATUS_DISCONNECTED.
|
||||
*/
|
||||
if (add_dev(devlistp, dev_name, PCAP_IF_WIRELESS, dev_descr, err_str) == NULL)
|
||||
if (pcapint_add_dev(devlistp, dev_name, PCAP_IF_WIRELESS, dev_descr, err_str) == NULL)
|
||||
{
|
||||
ret = -1;
|
||||
ret = PCAP_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -225,39 +224,39 @@ bt_activate(pcap_t* handle)
|
||||
|
||||
handle->read_op = bt_read_linux;
|
||||
handle->inject_op = bt_inject_linux;
|
||||
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
handle->setdirection_op = bt_setdirection_linux;
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
handle->stats_op = bt_stats_linux;
|
||||
handlep->dev_id = dev_id;
|
||||
|
||||
/* Create HCI socket */
|
||||
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
||||
if (handle->fd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't create raw socket");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
handle->buffer = malloc(handle->bufsize);
|
||||
if (!handle->buffer) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't allocate dump buffer");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(handle->fd, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't enable data direction info");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(handle->fd, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't enable time stamp");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -268,7 +267,7 @@ bt_activate(pcap_t* handle)
|
||||
memset((void *) &flt.type_mask, 0xff, sizeof(flt.type_mask));
|
||||
memset((void *) &flt.event_mask, 0xff, sizeof(flt.event_mask));
|
||||
if (setsockopt(handle->fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't set filter");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -281,7 +280,7 @@ bt_activate(pcap_t* handle)
|
||||
addr.hci_channel = HCI_CHANNEL_RAW;
|
||||
#endif
|
||||
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't attach to device %d", handlep->dev_id);
|
||||
goto close_fail;
|
||||
}
|
||||
@ -301,7 +300,7 @@ bt_activate(pcap_t* handle)
|
||||
if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
|
||||
&handle->opt.buffer_size,
|
||||
sizeof(handle->opt.buffer_size)) == -1) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
errno, PCAP_ERRBUF_SIZE, "SO_RCVBUF");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -311,7 +310,7 @@ bt_activate(pcap_t* handle)
|
||||
return 0;
|
||||
|
||||
close_fail:
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -340,12 +339,12 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
|
||||
|
||||
/* ignore interrupt system call error */
|
||||
do {
|
||||
ret = recvmsg(handle->fd, &msg, 0);
|
||||
if (handle->break_loop)
|
||||
{
|
||||
handle->break_loop = 0;
|
||||
return -2;
|
||||
return PCAP_ERROR_BREAK;
|
||||
}
|
||||
ret = recvmsg(handle->fd, &msg, 0);
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
if (ret < 0) {
|
||||
@ -353,9 +352,9 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
|
||||
/* Nonblocking mode, no data */
|
||||
return 0;
|
||||
}
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't receive packet");
|
||||
return -1;
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
pkth.caplen = (bpf_u_int32)ret;
|
||||
@ -372,7 +371,10 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
|
||||
sizeof pkth.ts);
|
||||
break;
|
||||
}
|
||||
// for musl libc CMSG_NXTHDR()
|
||||
DIAG_OFF_SIGN_COMPARE
|
||||
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
||||
DIAG_ON_SIGN_COMPARE
|
||||
}
|
||||
switch (handle->direction) {
|
||||
|
||||
@ -394,7 +396,7 @@ bt_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char
|
||||
pkth.caplen+=sizeof(pcap_bluetooth_h4_header);
|
||||
pkth.len = pkth.caplen;
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
pcapint_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
callback(user, &pkth, pktd);
|
||||
return 1;
|
||||
}
|
||||
@ -425,13 +427,13 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
if (ret < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't get stats via ioctl");
|
||||
return (-1);
|
||||
|
||||
}
|
||||
|
||||
/* we receive both rx and tx frames, so comulate all stats */
|
||||
/* we receive both rx and tx frames, so cumulate all stats */
|
||||
stats->ps_recv = s->evt_rx + s->acl_rx + s->sco_rx + s->cmd_tx +
|
||||
s->acl_tx +s->sco_tx;
|
||||
stats->ps_drop = s->err_rx + s->err_tx;
|
||||
|
@ -29,9 +29,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
@ -43,6 +41,7 @@
|
||||
|
||||
#include "pcap/bluetooth.h"
|
||||
#include "pcap-int.h"
|
||||
#include "diag-control.h"
|
||||
|
||||
#include "pcap-bt-monitor-linux.h"
|
||||
|
||||
@ -80,11 +79,11 @@ bt_monitor_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
* more than there's a notion of "connected" or "disconnected"
|
||||
* for the "any" device.
|
||||
*/
|
||||
if (add_dev(devlistp, INTERFACE_NAME,
|
||||
if (pcapint_add_dev(devlistp, INTERFACE_NAME,
|
||||
PCAP_IF_WIRELESS|PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
|
||||
"Bluetooth Linux Monitor", err_str) == NULL)
|
||||
{
|
||||
ret = -1;
|
||||
ret = PCAP_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -118,12 +117,12 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
msg.msg_controllen = BT_CONTROL_SIZE;
|
||||
|
||||
do {
|
||||
ret = recvmsg(handle->fd, &msg, 0);
|
||||
if (handle->break_loop)
|
||||
{
|
||||
handle->break_loop = 0;
|
||||
return -2;
|
||||
return PCAP_ERROR_BREAK;
|
||||
}
|
||||
ret = recvmsg(handle->fd, &msg, 0);
|
||||
} while ((ret == -1) && (errno == EINTR));
|
||||
|
||||
if (ret < 0) {
|
||||
@ -131,15 +130,18 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
/* Nonblocking mode, no data */
|
||||
return 0;
|
||||
}
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't receive packet");
|
||||
return -1;
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
pkth.caplen = (bpf_u_int32)(ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header));
|
||||
pkth.len = pkth.caplen;
|
||||
|
||||
// for musl libc CMSG_NXTHDR()
|
||||
DIAG_OFF_SIGN_COMPARE
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
DIAG_ON_SIGN_COMPARE
|
||||
if (cmsg->cmsg_level != SOL_SOCKET) continue;
|
||||
|
||||
if (cmsg->cmsg_type == SCM_TIMESTAMP) {
|
||||
@ -151,7 +153,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
|
||||
bthdr->opcode = htons(hdr.opcode);
|
||||
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
pcapint_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
callback(user, &pkth, pktd);
|
||||
return 1;
|
||||
}
|
||||
@ -163,7 +165,7 @@ bt_monitor_inject(pcap_t *handle, const void *buf _U_, int size _U_)
|
||||
{
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Packet injection is not supported yet on Bluetooth monitor devices");
|
||||
return -1;
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -204,23 +206,23 @@ bt_monitor_activate(pcap_t* handle)
|
||||
|
||||
handle->read_op = bt_monitor_read;
|
||||
handle->inject_op = bt_monitor_inject;
|
||||
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
handle->setdirection_op = NULL; /* Not implemented */
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
handle->stats_op = bt_monitor_stats;
|
||||
|
||||
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
||||
if (handle->fd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't create raw socket");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
handle->buffer = malloc(handle->bufsize);
|
||||
if (!handle->buffer) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't allocate dump buffer");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -231,14 +233,14 @@ bt_monitor_activate(pcap_t* handle)
|
||||
addr.hci_channel = HCI_CHANNEL_MONITOR;
|
||||
|
||||
if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't attach to interface");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(handle->fd, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't enable time stamp");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -248,7 +250,7 @@ bt_monitor_activate(pcap_t* handle)
|
||||
return 0;
|
||||
|
||||
close_fail:
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,7 @@
|
||||
* pcap-common.c - common code for pcap and pcapng files
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap-types.h>
|
||||
|
||||
@ -99,6 +97,17 @@
|
||||
* defining DLT_* values that collide with those
|
||||
* LINKTYPE_* values, either).
|
||||
*/
|
||||
|
||||
/*
|
||||
* These values the DLT_ values for which are the same on all platforms,
|
||||
* and that have been defined by <net/bpf.h> for ages.
|
||||
*
|
||||
* For those, the LINKTYPE_ values are equal to the DLT_ values.
|
||||
*
|
||||
* LINKTYPE_LOW_MATCHING_MIN is the lowest such value;
|
||||
* LINKTYPE_LOW_MATCHING_MAX is the highest such value.
|
||||
*/
|
||||
#define LINKTYPE_LOW_MATCHING_MIN 0 /* lowest value in this "matching" range */
|
||||
#define LINKTYPE_NULL DLT_NULL
|
||||
#define LINKTYPE_ETHERNET DLT_EN10MB /* also for 100Mb and up */
|
||||
#define LINKTYPE_EXP_ETHERNET DLT_EN3MB /* 3Mb experimental Ethernet */
|
||||
@ -111,6 +120,8 @@
|
||||
#define LINKTYPE_PPP DLT_PPP
|
||||
#define LINKTYPE_FDDI DLT_FDDI
|
||||
|
||||
#define LINKTYPE_LOW_MATCHING_MAX LINKTYPE_FDDI /* highest value in this "matching" range */
|
||||
|
||||
/*
|
||||
* LINKTYPE_PPP is for use when there might, or might not, be an RFC 1662
|
||||
* PPP in HDLC-like framing header (with 0xff 0x03 before the PPP protocol
|
||||
@ -150,10 +161,10 @@
|
||||
* and the LINKTYPE_ value that appears in capture files, are the
|
||||
* same.
|
||||
*
|
||||
* LINKTYPE_MATCHING_MIN is the lowest such value; LINKTYPE_MATCHING_MAX
|
||||
* is the highest such value.
|
||||
* LINKTYPE_HIGH_MATCHING_MIN is the lowest such value;
|
||||
* LINKTYPE_HIGH_MATCHING_MAX is the highest such value.
|
||||
*/
|
||||
#define LINKTYPE_MATCHING_MIN 104 /* lowest value in the "matching" range */
|
||||
#define LINKTYPE_HIGH_MATCHING_MIN 104 /* lowest value in the "matching" range */
|
||||
|
||||
#define LINKTYPE_C_HDLC 104 /* Cisco HDLC */
|
||||
#define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 (wireless) */
|
||||
@ -693,9 +704,9 @@
|
||||
#define LINKTYPE_AOS 222
|
||||
|
||||
/*
|
||||
* Wireless HART (Highway Addressable Remote Transducer)
|
||||
* WirelessHART (Highway Addressable Remote Transducer)
|
||||
* From the HART Communication Foundation
|
||||
* IES/PAS 62591
|
||||
* IEC/PAS 62591
|
||||
*
|
||||
* Requested by Sam Roberts <vieuxtech@gmail.com>.
|
||||
*/
|
||||
@ -917,7 +928,6 @@
|
||||
* shiny new link-layer header type value that doesn't collide with
|
||||
* anything, in the hopes that future pfsync savefiles, if any,
|
||||
* won't require special hacks to distinguish from other savefiles.
|
||||
*
|
||||
*/
|
||||
#define LINKTYPE_PFSYNC 246
|
||||
|
||||
@ -1197,168 +1207,335 @@
|
||||
*/
|
||||
#define LINKTYPE_ATSC_ALP 289
|
||||
|
||||
#define LINKTYPE_MATCHING_MAX 289 /* highest value in the "matching" range */
|
||||
#define LINKTYPE_HIGH_MATCHING_MAX 289 /* highest value in the "matching" range */
|
||||
|
||||
/*
|
||||
* The DLT_ and LINKTYPE_ values in the "matching" range should be the
|
||||
* same, so DLT_MATCHING_MAX and LINKTYPE_MATCHING_MAX should be the
|
||||
* same, so DLT_HIGH_MATCHING_MAX and LINKTYPE_HIGH_MATCHING_MAX should be the
|
||||
* same.
|
||||
*/
|
||||
#if LINKTYPE_MATCHING_MAX != DLT_MATCHING_MAX
|
||||
#error The LINKTYPE_ matching range does not match the DLT_ matching range
|
||||
#if LINKTYPE_HIGH_MATCHING_MAX != DLT_HIGH_MATCHING_MAX
|
||||
#error The LINKTYPE_ high matching range does not match the DLT_ matching range
|
||||
#endif
|
||||
|
||||
static struct linktype_map {
|
||||
int dlt;
|
||||
int linktype;
|
||||
} map[] = {
|
||||
/*
|
||||
* Map a DLT_* code to the corresponding LINKTYPE_* code.
|
||||
* Used to generate link-layer types written to savefiles.
|
||||
*/
|
||||
int
|
||||
dlt_to_linktype(int dlt)
|
||||
{
|
||||
/*
|
||||
* These DLT_* codes have LINKTYPE_* codes with values identical
|
||||
* to the values of the corresponding DLT_* code.
|
||||
* All values in the low matching range were handed out before
|
||||
* assigning DLT_* codes became a free-for-all, so they're the
|
||||
* same on all platforms, and thus are given LINKTYPE_* codes
|
||||
* with the same numerical values as the corresponding DLT_*
|
||||
* code.
|
||||
*/
|
||||
{ DLT_NULL, LINKTYPE_NULL },
|
||||
{ DLT_EN10MB, LINKTYPE_ETHERNET },
|
||||
{ DLT_EN3MB, LINKTYPE_EXP_ETHERNET },
|
||||
{ DLT_AX25, LINKTYPE_AX25 },
|
||||
{ DLT_PRONET, LINKTYPE_PRONET },
|
||||
{ DLT_CHAOS, LINKTYPE_CHAOS },
|
||||
{ DLT_IEEE802, LINKTYPE_IEEE802_5 },
|
||||
{ DLT_ARCNET, LINKTYPE_ARCNET_BSD },
|
||||
{ DLT_SLIP, LINKTYPE_SLIP },
|
||||
{ DLT_PPP, LINKTYPE_PPP },
|
||||
{ DLT_FDDI, LINKTYPE_FDDI },
|
||||
{ DLT_SYMANTEC_FIREWALL, LINKTYPE_SYMANTEC_FIREWALL },
|
||||
if (dlt >= DLT_LOW_MATCHING_MIN && dlt <= DLT_LOW_MATCHING_MAX)
|
||||
return (dlt);
|
||||
|
||||
#if DLT_PFSYNC != LINKTYPE_PFSYNC
|
||||
/*
|
||||
* DLT_PFSYNC has a code on several platforms that's in the
|
||||
* non-matching range, a code on FreeBSD that's in the high
|
||||
* matching range and that's *not* equal to LINKTYPE_PFSYNC,
|
||||
* and has a code on the rmaining platforms that's equal
|
||||
* to LINKTYPE_PFSYNC, which is in the high matching range.
|
||||
*
|
||||
* Map it to LINKTYPE_PFSYNC if it's not equal to LINKTYPE_PFSYNC.
|
||||
*/
|
||||
if (dlt == DLT_PFSYNC)
|
||||
return (LINKTYPE_PFSYNC);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* DLT_PKTAP is defined as DLT_USER2 - which is in the high
|
||||
* matching range - on Darwin because Apple used DLT_USER2
|
||||
* on systems that users ran, not just as an internal thing.
|
||||
*
|
||||
* We map it to LINKTYPE_PKTAP if it's not equal to LINKTYPE_PKTAP
|
||||
* so that DLT_PKTAP captures from Apple machines can be read by
|
||||
* software that either doesn't handle DLT_USER2 or that handles it
|
||||
* as something other than Apple PKTAP.
|
||||
*/
|
||||
#if DLT_PKTAP != LINKTYPE_PKTAP
|
||||
if (dlt == DLT_PKTAP)
|
||||
return (LINKTYPE_PKTAP);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For all other DLT_* codes in the high matching range, the DLT
|
||||
* code value is the same as the LINKTYPE_* code value.
|
||||
*/
|
||||
if (dlt >= DLT_HIGH_MATCHING_MIN && dlt <= DLT_HIGH_MATCHING_MAX)
|
||||
return (dlt);
|
||||
|
||||
/*
|
||||
* These DLT_* codes have different values on different
|
||||
* platforms; we map them to LINKTYPE_* codes that
|
||||
* have values that should never be equal to any DLT_*
|
||||
* code.
|
||||
* platforms, so we assigned them LINKTYPE_* codes just
|
||||
* below the lower bound of the high matchig range;
|
||||
* those values should never be equal to any DLT_*
|
||||
* code, so that should avoid collisions.
|
||||
*
|
||||
* That way, for example, "raw IP" packets will have
|
||||
* LINKTYPE_RAW as the code in all savefiles for
|
||||
* which the code that writes them maps to that
|
||||
* value, regardless of the platform on which they
|
||||
* were written, so they should be readable on all
|
||||
* platforms without having to determine on which
|
||||
* platform they were written.
|
||||
*
|
||||
* We map the DLT_* codes on this platform, whatever
|
||||
* it might be, to the corresponding LINKTYPE_* codes.
|
||||
*/
|
||||
if (dlt == DLT_ATM_RFC1483)
|
||||
return (LINKTYPE_ATM_RFC1483);
|
||||
if (dlt == DLT_RAW)
|
||||
return (LINKTYPE_RAW);
|
||||
if (dlt == DLT_SLIP_BSDOS)
|
||||
return (LINKTYPE_SLIP_BSDOS);
|
||||
if (dlt == DLT_PPP_BSDOS)
|
||||
return (LINKTYPE_PPP_BSDOS);
|
||||
|
||||
/*
|
||||
* These DLT_* codes were originally defined on some platform,
|
||||
* and weren't defined on other platforms.
|
||||
*
|
||||
* At least some of them have values, on at least one platform,
|
||||
* that collide with other DLT_* codes on other platforms, e.g.
|
||||
* DLT_LOOP, so we don't just define them, on all platforms,
|
||||
* as having the same value as on the original platform.
|
||||
*
|
||||
* Therefore, we assigned new LINKTYPE_* codes to them, and,
|
||||
* on the platforms where they weren't originally defined,
|
||||
* define the DLT_* codes to have the same value as the
|
||||
* corresponding LINKTYPE_* codes.
|
||||
*
|
||||
* This means that, for capture files with the original
|
||||
* platform's DLT_* code rather than the LINKTYPE_* code
|
||||
* as a link-layer type, we will recognize those types
|
||||
* on that platform, but not on other platforms.
|
||||
*/
|
||||
#ifdef DLT_FR
|
||||
/* BSD/OS Frame Relay */
|
||||
{ DLT_FR, LINKTYPE_FRELAY },
|
||||
if (dlt == DLT_FR)
|
||||
return (LINKTYPE_FRELAY);
|
||||
#endif
|
||||
#if DLT_HDLC != LINKTYPE_NETBSD_HDLC
|
||||
/* NetBSD HDLC */
|
||||
if (dlt == DLT_HDLC)
|
||||
return (LINKTYPE_NETBSD_HDLC);
|
||||
#endif
|
||||
#if DLT_C_HDLC != LINKTYPE_C_HDLC
|
||||
/* BSD/OS Cisco HDLC */
|
||||
if (dlt == DLT_C_HDLC)
|
||||
return (LINKTYPE_C_HDLC);
|
||||
#endif
|
||||
#if DLT_LOOP != LINKTYPE_LOOP
|
||||
/* OpenBSD DLT_LOOP */
|
||||
if (dlt == DLT_LOOP)
|
||||
return (LINKTYPE_LOOP);
|
||||
#endif
|
||||
#if DLT_ENC != LINKTYPE_ENC
|
||||
/* OpenBSD DLT_ENC */
|
||||
if (dlt == DLT_ENC)
|
||||
return (LINKTYPE_ENC);
|
||||
#endif
|
||||
|
||||
{ DLT_ATM_RFC1483, LINKTYPE_ATM_RFC1483 },
|
||||
{ DLT_RAW, LINKTYPE_RAW },
|
||||
{ DLT_SLIP_BSDOS, LINKTYPE_SLIP_BSDOS },
|
||||
{ DLT_PPP_BSDOS, LINKTYPE_PPP_BSDOS },
|
||||
{ DLT_HDLC, LINKTYPE_NETBSD_HDLC },
|
||||
/*
|
||||
* These DLT_* codes are not on all platforms, but, so far,
|
||||
* there don't appear to be any platforms that define
|
||||
* other codes with those values; we map them to
|
||||
* different LINKTYPE_* codes anyway, just in case.
|
||||
*/
|
||||
/* Linux ATM Classical IP */
|
||||
if (dlt == DLT_ATM_CLIP)
|
||||
return (LINKTYPE_ATM_CLIP);
|
||||
|
||||
/*
|
||||
* A few other values, defined on some platforms, not in
|
||||
* either matching range, but not colliding with anything
|
||||
* else, so they're given the same LINKTYPE_* code as
|
||||
* their DLT_* code.
|
||||
*/
|
||||
if (dlt == DLT_REDBACK_SMARTEDGE || dlt == DLT_PPP_SERIAL ||
|
||||
dlt == DLT_PPP_ETHER || dlt == DLT_SYMANTEC_FIREWALL)
|
||||
return (dlt);
|
||||
|
||||
/*
|
||||
* If we don't have a mapping for this DLT_* code, return an
|
||||
* error; that means that this is a DLT_* value with no
|
||||
* corresponding LINKTYPE_ value, and we need to assign one.
|
||||
*/
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Map a LINKTYPE_* code to the corresponding DLT_* code.
|
||||
* Used to translate link-layer types in savefiles to the
|
||||
* DLT_* codes to provide to callers of libpcap.
|
||||
*/
|
||||
int
|
||||
linktype_to_dlt(int linktype)
|
||||
{
|
||||
/*
|
||||
* All values in the low matching range were handed out before
|
||||
* assigning DLT_* codes became a free-for-all, so they're the
|
||||
* same on all platforms, and are thus used as the LINKTYPE_*
|
||||
* codes in capture files.
|
||||
*/
|
||||
if (linktype >= LINKTYPE_LOW_MATCHING_MIN &&
|
||||
linktype <= LINKTYPE_LOW_MATCHING_MAX)
|
||||
return (linktype);
|
||||
|
||||
#if LINKTYPE_PFSYNC != DLT_PFSYNC
|
||||
/*
|
||||
* DLT_PFSYNC has a code on several platforms that's in the
|
||||
* non-matching range, a code on FreeBSD that's in the high
|
||||
* matching range and that's *not* equal to LINKTYPE_PFSYNC,
|
||||
* and has a code on the rmaining platforms that's equal
|
||||
* to LINKTYPE_PFSYNC, which is in the high matching range.
|
||||
*
|
||||
* Map LINKTYPE_PFSYNC to whatever DLT_PFSYNC is on this
|
||||
* platform, if the two aren't equal.
|
||||
*/
|
||||
if (linktype == LINKTYPE_PFSYNC)
|
||||
return (DLT_PFSYNC);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* DLT_PKTAP is defined as DLT_USER2 - which is in the high
|
||||
* matching range - on Darwin because Apple used DLT_USER2
|
||||
* on systems that users ran, not just as an internal thing.
|
||||
*
|
||||
* We map LINKTYPE_PKTAP to the platform's DLT_PKTAP for
|
||||
* the benefit of software that's expecting DLT_PKTAP
|
||||
* (even if that's DLT_USER2) for an Apple PKTAP capture.
|
||||
*
|
||||
* (Yes, this is an annoyance if you want to read a
|
||||
* LINKTYPE_USER2 packet as something other than DLT_PKTAP
|
||||
* on a Darwin-based OS, as, on that OS, DLT_PKTAP and DLT_USER2
|
||||
* are the same. Feel free to complain to Apple about this.)
|
||||
*/
|
||||
#if LINKTYPE_PKTAP != DLT_PKTAP
|
||||
if (linktype == LINKTYPE_PKTAP)
|
||||
return (DLT_PKTAP);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These DLT_* codes have different values on different
|
||||
* platforms, so we assigned them LINKTYPE_* codes just
|
||||
* below the lower bound of the high matchig range;
|
||||
* those values should never be equal to any DLT_*
|
||||
* code, so that should avoid collisions.
|
||||
*
|
||||
* That way, for example, "raw IP" packets will have
|
||||
* LINKTYPE_RAW as the code in all savefiles for
|
||||
* which the code that writes them maps to that
|
||||
* value, regardless of the platform on which they
|
||||
* were written, so they should be readable on all
|
||||
* platforms without having to determine on which
|
||||
* platform they were written.
|
||||
*
|
||||
* We map the LINKTYPE_* codes to the corresponding
|
||||
* DLT_* code on this platform.
|
||||
*/
|
||||
if (linktype == LINKTYPE_ATM_RFC1483)
|
||||
return (DLT_ATM_RFC1483);
|
||||
if (linktype == LINKTYPE_RAW)
|
||||
return (DLT_RAW);
|
||||
if (linktype == LINKTYPE_SLIP_BSDOS)
|
||||
return (DLT_SLIP_BSDOS);
|
||||
if (linktype == LINKTYPE_PPP_BSDOS)
|
||||
return (DLT_PPP_BSDOS);
|
||||
|
||||
/*
|
||||
* These DLT_* codes were originally defined on some platform,
|
||||
* and weren't defined on other platforms.
|
||||
*
|
||||
* At least some of them have values, on at least one platform,
|
||||
* that collide with other DLT_* codes on other platforms, e.g.
|
||||
* DLT_LOOP, so we don't just define them, on all platforms,
|
||||
* as having the same value as on the original platform.
|
||||
*
|
||||
* Therefore, we assigned new LINKTYPE_* codes to them, and,
|
||||
* on the platforms where they weren't originally defined,
|
||||
* define the DLT_* codes to have the same value as the
|
||||
* corresponding LINKTYPE_* codes.
|
||||
*
|
||||
* This means that, for capture files with the original
|
||||
* platform's DLT_* code rather than the LINKTYPE_* code
|
||||
* as a link-layer type, we will recognize those types
|
||||
* on that platform, but not on other platforms.
|
||||
*
|
||||
* We map the LINKTYPE_* codes to the corresponding
|
||||
* DLT_* code on platforms where the two codes differ..
|
||||
*/
|
||||
#ifdef DLT_FR
|
||||
/* BSD/OS Frame Relay */
|
||||
if (linktype == LINKTYPE_FRELAY)
|
||||
return (DLT_FR);
|
||||
#endif
|
||||
#if LINKTYPE_NETBSD_HDLC != DLT_HDLC
|
||||
/* NetBSD HDLC */
|
||||
if (linktype == LINKTYPE_NETBSD_HDLC)
|
||||
return (DLT_HDLC);
|
||||
#endif
|
||||
#if LINKTYPE_C_HDLC != DLT_C_HDLC
|
||||
/* BSD/OS Cisco HDLC */
|
||||
{ DLT_C_HDLC, LINKTYPE_C_HDLC },
|
||||
if (linktype == LINKTYPE_C_HDLC)
|
||||
return (DLT_C_HDLC);
|
||||
#endif
|
||||
#if LINKTYPE_LOOP != DLT_LOOP
|
||||
/* OpenBSD DLT_LOOP */
|
||||
if (linktype == LINKTYPE_LOOP)
|
||||
return (DLT_LOOP);
|
||||
#endif
|
||||
#if LINKTYPE_ENC != DLT_ENC
|
||||
/* OpenBSD DLT_ENC */
|
||||
if (linktype == LINKTYPE_ENC)
|
||||
return (DLT_ENC);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These DLT_* codes are not on all platforms, but, so far,
|
||||
* there don't appear to be any platforms that define
|
||||
* other codes with those values; we map them to
|
||||
* different LINKTYPE_* values anyway, just in case.
|
||||
*/
|
||||
|
||||
/* Linux ATM Classical IP */
|
||||
{ DLT_ATM_CLIP, LINKTYPE_ATM_CLIP },
|
||||
|
||||
/* NetBSD sync/async serial PPP (or Cisco HDLC) */
|
||||
{ DLT_PPP_SERIAL, LINKTYPE_PPP_HDLC },
|
||||
|
||||
/* NetBSD PPP over Ethernet */
|
||||
{ DLT_PPP_ETHER, LINKTYPE_PPP_ETHER },
|
||||
|
||||
/*
|
||||
* All LINKTYPE_ values between LINKTYPE_MATCHING_MIN
|
||||
* and LINKTYPE_MATCHING_MAX are mapped to identical
|
||||
* DLT_ values.
|
||||
*/
|
||||
|
||||
{ -1, -1 }
|
||||
};
|
||||
|
||||
int
|
||||
dlt_to_linktype(int dlt)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* DLTs that, on some platforms, have values in the matching range
|
||||
* but that *don't* have the same value as the corresponding
|
||||
* LINKTYPE because, for some reason, not all OSes have the
|
||||
* same value for that DLT (note that the DLT's value might be
|
||||
* outside the matching range on some of those OSes).
|
||||
*/
|
||||
if (dlt == DLT_PFSYNC)
|
||||
return (LINKTYPE_PFSYNC);
|
||||
if (dlt == DLT_PKTAP)
|
||||
return (LINKTYPE_PKTAP);
|
||||
|
||||
/*
|
||||
* For all other values in the matching range, the DLT
|
||||
* value is the same as the LINKTYPE value.
|
||||
*/
|
||||
if (dlt >= DLT_MATCHING_MIN && dlt <= DLT_MATCHING_MAX)
|
||||
return (dlt);
|
||||
|
||||
/*
|
||||
* Map the values outside that range.
|
||||
*/
|
||||
for (i = 0; map[i].dlt != -1; i++) {
|
||||
if (map[i].dlt == dlt)
|
||||
return (map[i].linktype);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we don't have a mapping for this DLT, return an
|
||||
* error; that means that this is a value with no corresponding
|
||||
* LINKTYPE, and we need to assign one.
|
||||
*/
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
linktype_to_dlt(int linktype)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* LINKTYPEs in the matching range that *don't*
|
||||
* have the same value as the corresponding DLTs
|
||||
* because, for some reason, not all OSes have the
|
||||
* same value for that DLT.
|
||||
*/
|
||||
if (linktype == LINKTYPE_PFSYNC)
|
||||
return (DLT_PFSYNC);
|
||||
if (linktype == LINKTYPE_PKTAP)
|
||||
return (DLT_PKTAP);
|
||||
|
||||
/*
|
||||
* For all other values in the matching range, except for
|
||||
* LINKTYPE_ATM_CLIP, the LINKTYPE value is the same as
|
||||
* the DLT value.
|
||||
*
|
||||
* LINKTYPE_ATM_CLIP is a special case. DLT_ATM_CLIP is
|
||||
* not on all platforms, but, so far, there don't appear
|
||||
* to be any platforms that define it as anything other
|
||||
* than 19; we define LINKTYPE_ATM_CLIP as something
|
||||
* other than 19, just in case. That value is in the
|
||||
* matching range, so we have to check for it.
|
||||
* high matching range, so we have to check for it.
|
||||
*/
|
||||
if (linktype >= LINKTYPE_MATCHING_MIN &&
|
||||
linktype <= LINKTYPE_MATCHING_MAX &&
|
||||
linktype != LINKTYPE_ATM_CLIP)
|
||||
return (linktype);
|
||||
/* Linux ATM Classical IP */
|
||||
if (linktype == LINKTYPE_ATM_CLIP)
|
||||
return (DLT_ATM_CLIP);
|
||||
|
||||
/*
|
||||
* Map the values outside that range.
|
||||
*/
|
||||
for (i = 0; map[i].linktype != -1; i++) {
|
||||
if (map[i].linktype == linktype)
|
||||
return (map[i].dlt);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we don't have an entry for this LINKTYPE, return
|
||||
* the link type value; it may be a DLT from an newer
|
||||
* version of libpcap.
|
||||
* For all other values, return the linktype code as the
|
||||
* DLT_* code.
|
||||
*
|
||||
* If the code is in the high matching range, the
|
||||
* DLT_* code is the same as the LINKTYPE_* code.
|
||||
*
|
||||
* If the code is greater than the maximum value in
|
||||
* the high matching range, it may be a value from
|
||||
* a newer version of libpcap; we provide it in case
|
||||
* the program' capable of handling it.
|
||||
*
|
||||
* If the code is less than the minimum value in the
|
||||
* high matching range, it might be from a capture
|
||||
* written by code that doesn't map non-matching range
|
||||
* DLT_* codes to the appropriate LINKTYPE_* code, so
|
||||
* we'll just pass it through, so that *if it was written
|
||||
* on this platform* it will be interpreted correctly.
|
||||
* (We don't know whether it was written on this platform,
|
||||
* but at least this way there's *some* chance that it
|
||||
* can be read.)
|
||||
*/
|
||||
return linktype;
|
||||
}
|
||||
|
@ -18,55 +18,115 @@
|
||||
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.\"
|
||||
.TH PCAP-CONFIG 1 "15 February 2015"
|
||||
.TH PCAP\-CONFIG 1 "17 April 2023"
|
||||
.SH NAME
|
||||
pcap-config \- write libpcap compiler and linker flags to standard output
|
||||
.SH SYNOPSIS
|
||||
.na
|
||||
.B pcap-config
|
||||
[
|
||||
.B \-\-static
|
||||
.B \-\-help
|
||||
]
|
||||
[
|
||||
.B \-\-cflags | \-\-libs | \-\-additional-libs
|
||||
.B \-\-version
|
||||
]
|
||||
[
|
||||
.B \-\-cflags
|
||||
]
|
||||
.ti +12
|
||||
[
|
||||
.B \-\-libs
|
||||
|
|
||||
.B \-\-additional\-libs
|
||||
]
|
||||
.ti +12
|
||||
[
|
||||
.B \-\-static
|
||||
|
|
||||
.B \-\-static\-pcap\-only
|
||||
]
|
||||
.ad
|
||||
|
||||
.SH DESCRIPTION
|
||||
.LP
|
||||
When run with the
|
||||
.I pcap\-config
|
||||
writes to the standard output various compiler and linker flags required to
|
||||
build a user program with libpcap. By default, it writes flags appropriate
|
||||
for building with a dynamically\-linked version of libpcap; see below
|
||||
for static linking. Depending on the manner of libpcap installation, some
|
||||
options or their combinations may produce empty output \- this is by design.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-\-help
|
||||
Produce a help message and exit.
|
||||
|
||||
.TP
|
||||
.B \-\-version
|
||||
Produce libpcap version and exit. The version is the contents of
|
||||
.I VERSION
|
||||
file in libpcap source tree rather than the result of
|
||||
.BR \%pcap_lib_version (3PCAP).
|
||||
|
||||
.TP
|
||||
.B \-\-cflags
|
||||
option,
|
||||
.I pcap-config
|
||||
writes to the standard output the
|
||||
Produce the
|
||||
.B \-I
|
||||
compiler flags required to include libpcap's header files.
|
||||
When run with the
|
||||
compiler flag required to include libpcap's header files.
|
||||
|
||||
.TP
|
||||
.B \-\-libs
|
||||
option,
|
||||
.I pcap-config
|
||||
writes to the standard output the
|
||||
Produce the
|
||||
.B \-L
|
||||
and
|
||||
.B \-l
|
||||
linker flags required to link with libpcap, including
|
||||
.B \-l
|
||||
flags for libraries required by libpcap.
|
||||
When run with the
|
||||
.B \-\-additional-libs
|
||||
option,
|
||||
.I pcap-config
|
||||
writes to the standard output the
|
||||
|
||||
.TP
|
||||
.B \-\-additional\-libs
|
||||
Produce the
|
||||
.B \-L
|
||||
and
|
||||
.B \-l
|
||||
flags for libraries required by libpcap, but not the
|
||||
.B \-lpcap
|
||||
linker flags for libraries required by libpcap, but not the
|
||||
.B \-l
|
||||
flag to link with libpcap itself.
|
||||
.LP
|
||||
By default, it writes flags appropriate for compiling with a
|
||||
dynamically-linked version of libpcap; the
|
||||
|
||||
.TP
|
||||
.B \-\-static
|
||||
flag causes it to write flags appropriate for compiling with a
|
||||
statically-linked version of libpcap.
|
||||
This option causes
|
||||
.B \-\-libs
|
||||
and
|
||||
.B \-\-additional\-libs
|
||||
to produce linker flags appropriate for static linking with libpcap.
|
||||
|
||||
.TP
|
||||
.B \-\-static\-pcap\-only
|
||||
This option causes
|
||||
.B \-\-libs
|
||||
and
|
||||
.B \-\-additional\-libs
|
||||
to produce linker flags appropriate for static linking with libpcap and
|
||||
dynamic linking with all other libraries, including libraries required by
|
||||
libpcap.
|
||||
|
||||
.SH EXIT STATUS
|
||||
.I pcap\-config
|
||||
exits with a non-zero status when invoked with an invalid command\-line
|
||||
option, and with status 0 otherwise.
|
||||
|
||||
.SH BACKWARD COMPATIBILITY
|
||||
.PP
|
||||
Before libpcap release 1.10.2
|
||||
.I pcap\-config
|
||||
did not treat invalid command\-line options as an error. The
|
||||
.B \-\-static\-pcap\-only
|
||||
flag became available in libpcap release 1.10.2. The
|
||||
.B \-\-static
|
||||
flag became available in libpcap release 1.1.0.
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR pkg\-config (1),
|
||||
.BR pcap (3PCAP)
|
||||
|
@ -16,6 +16,13 @@ LIBS="@LIBS@"
|
||||
LIBS_STATIC="@LIBS_STATIC@"
|
||||
VERSION="@PACKAGE_VERSION@"
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "Usage: pcap-config [ --help ] [ --version ] [ --cflags ]"
|
||||
echo " [ --libs | --additional-libs ]"
|
||||
echo " [ --static | --static-pcap-only ]"
|
||||
}
|
||||
|
||||
static=0
|
||||
static_pcap_only=0
|
||||
show_cflags=0
|
||||
@ -46,7 +53,7 @@ do
|
||||
;;
|
||||
|
||||
-h|--help)
|
||||
echo "Usage: pcap-config [ --help ] [--version] [ --static | --static-pcap-only ] [ --libs | --additional-libs ]"
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
|
||||
@ -57,7 +64,7 @@ do
|
||||
|
||||
*)
|
||||
echo "pcap-config: Invalid command-line option $1 specified" 1>&2
|
||||
echo "Usage: pcap-config [ --help ] [ --static | --static-pcap-only ] [ --libs | --additional-libs ]" 1>&2
|
||||
usage 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
@ -7,9 +7,7 @@
|
||||
* Stephen Donnelly <stephen.donnelly@endace.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h> /* optionally get BSD define */
|
||||
|
||||
@ -259,7 +257,7 @@ dag_platform_cleanup(pcap_t *p)
|
||||
pd->dag_ref = NULL;
|
||||
}
|
||||
delete_pcap_dag(p);
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -424,7 +422,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
rlen = ntohs(header->rlen);
|
||||
if (rlen < dag_record_size)
|
||||
{
|
||||
pcap_strlcpy(p->errbuf, "dag_read: record too small",
|
||||
pcapint_strlcpy(p->errbuf, "dag_read: record too small",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return -1;
|
||||
}
|
||||
@ -668,7 +666,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
caplen = p->snapshot;
|
||||
|
||||
/* Run the packet filter if there is one. */
|
||||
if ((p->fcode.bf_insns == NULL) || pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
|
||||
if ((p->fcode.bf_insns == NULL) || pcapint_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
|
||||
|
||||
/* convert between timestamp formats */
|
||||
register unsigned long long ts;
|
||||
@ -724,7 +722,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
static int
|
||||
dag_inject(pcap_t *p, const void *buf _U_, int size _U_)
|
||||
{
|
||||
pcap_strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
|
||||
pcapint_strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
}
|
||||
@ -762,7 +760,7 @@ static int dag_activate(pcap_t* p)
|
||||
newDev = (char *)malloc(strlen(device) + 16);
|
||||
if (newDev == NULL) {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't allocate string for device name");
|
||||
goto fail;
|
||||
}
|
||||
@ -776,7 +774,7 @@ static int dag_activate(pcap_t* p)
|
||||
* cases?
|
||||
*/
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_parse_name");
|
||||
goto fail;
|
||||
}
|
||||
@ -807,7 +805,7 @@ static int dag_activate(pcap_t* p)
|
||||
device, (errno == EPERM) ? "EPERM" : "EACCES");
|
||||
} else {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_config_init %s", device);
|
||||
}
|
||||
goto fail;
|
||||
@ -818,7 +816,7 @@ static int dag_activate(pcap_t* p)
|
||||
* XXX - does this reliably set errno?
|
||||
*/
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_config_get_card_fd %s", device);
|
||||
goto failclose;
|
||||
}
|
||||
@ -826,7 +824,7 @@ static int dag_activate(pcap_t* p)
|
||||
/* Open requested stream. Can fail if already locked or on error */
|
||||
if (dag_attach_stream64(p->fd, pd->dag_stream, 0, 0) < 0) {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_attach_stream");
|
||||
goto failclose;
|
||||
}
|
||||
@ -845,7 +843,7 @@ static int dag_activate(pcap_t* p)
|
||||
if (dag_get_stream_poll64(p->fd, pd->dag_stream,
|
||||
&mindata, &maxwait, &poll) < 0) {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_get_stream_poll");
|
||||
goto faildetach;
|
||||
}
|
||||
@ -890,7 +888,7 @@ static int dag_activate(pcap_t* p)
|
||||
if (dag_set_stream_poll64(p->fd, pd->dag_stream,
|
||||
mindata, &maxwait, &poll) < 0) {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_set_stream_poll");
|
||||
goto faildetach;
|
||||
}
|
||||
@ -913,7 +911,7 @@ static int dag_activate(pcap_t* p)
|
||||
|
||||
if(dag_start_stream(p->fd, pd->dag_stream) < 0) {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_start_stream %s", device);
|
||||
goto faildetach;
|
||||
}
|
||||
@ -980,7 +978,7 @@ static int dag_activate(pcap_t* p)
|
||||
|
||||
if (new_pcap_dag(p) < 0) {
|
||||
ret = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "new_pcap_dag %s", device);
|
||||
goto failstop;
|
||||
}
|
||||
@ -996,10 +994,10 @@ static int dag_activate(pcap_t* p)
|
||||
|
||||
p->read_op = dag_read;
|
||||
p->inject_op = dag_inject;
|
||||
p->setfilter_op = install_bpf_program;
|
||||
p->setfilter_op = pcapint_install_bpf_program;
|
||||
p->setdirection_op = NULL; /* Not implemented.*/
|
||||
p->set_datalink_op = dag_set_datalink;
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = dag_setnonblock;
|
||||
p->stats_op = dag_stats;
|
||||
p->cleanup_op = dag_platform_cleanup;
|
||||
@ -1030,7 +1028,7 @@ failclose:
|
||||
delete_pcap_dag(p);
|
||||
|
||||
fail:
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
if (newDev != NULL) {
|
||||
free((char *)newDev);
|
||||
}
|
||||
@ -1100,7 +1098,7 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
|
||||
*/
|
||||
p->tstamp_precision_list = malloc(2 * sizeof(u_int));
|
||||
if (p->tstamp_precision_list == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
pcap_close(p);
|
||||
return NULL;
|
||||
@ -1179,7 +1177,7 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
*
|
||||
* Also, are there notions of "up" and "running"?
|
||||
*/
|
||||
if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
|
||||
if (pcapint_add_dev(devlistp, name, 0, description, errbuf) == NULL) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
@ -1191,7 +1189,7 @@ dag_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
dag_detach_stream(dagfd, stream);
|
||||
|
||||
snprintf(name, 10, "dag%d:%d", c, stream);
|
||||
if (add_dev(devlistp, name, 0, description, errbuf) == NULL) {
|
||||
if (pcapint_add_dev(devlistp, name, 0, description, errbuf) == NULL) {
|
||||
/*
|
||||
* Failure.
|
||||
*/
|
||||
@ -1233,12 +1231,12 @@ dag_setnonblock(pcap_t *p, int nonblock)
|
||||
* and have a "dag_getnonblock()" function that looks at
|
||||
* "pd->dag_flags".
|
||||
*/
|
||||
if (pcap_setnonblock_fd(p, nonblock) < 0)
|
||||
if (pcapint_setnonblock_fd(p, nonblock) < 0)
|
||||
return (-1);
|
||||
|
||||
if (dag_get_stream_poll64(p->fd, pd->dag_stream,
|
||||
&mindata, &maxwait, &poll) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_get_stream_poll");
|
||||
return -1;
|
||||
}
|
||||
@ -1254,7 +1252,7 @@ dag_setnonblock(pcap_t *p, int nonblock)
|
||||
|
||||
if (dag_set_stream_poll64(p->fd, pd->dag_stream,
|
||||
mindata, &maxwait, &poll) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "dag_set_stream_poll");
|
||||
return -1;
|
||||
}
|
||||
@ -1277,7 +1275,7 @@ dag_get_datalink(pcap_t *p)
|
||||
memset(types, 0, 255);
|
||||
|
||||
if (p->dlt_list == NULL && (p->dlt_list = malloc(255*sizeof(*(p->dlt_list)))) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "malloc");
|
||||
return (-1);
|
||||
}
|
||||
@ -1287,7 +1285,7 @@ dag_get_datalink(pcap_t *p)
|
||||
#ifdef HAVE_DAG_GET_STREAM_ERF_TYPES
|
||||
/* Get list of possible ERF types for this card */
|
||||
if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "dag_get_stream_erf_types");
|
||||
return (-1);
|
||||
}
|
||||
@ -1297,7 +1295,7 @@ dag_get_datalink(pcap_t *p)
|
||||
#elif defined HAVE_DAG_GET_ERF_TYPES
|
||||
/* Get list of possible ERF types for this card */
|
||||
if (dag_get_erf_types(p->fd, types, 255) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "dag_get_erf_types");
|
||||
return (-1);
|
||||
}
|
||||
@ -1315,12 +1313,9 @@ dag_get_datalink(pcap_t *p)
|
||||
case ERF_TYPE_COLOR_HDLC_POS:
|
||||
case ERF_TYPE_DSM_COLOR_HDLC_POS:
|
||||
case ERF_TYPE_COLOR_HASH_POS:
|
||||
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[dlt_index++] = DLT_CHDLC;
|
||||
p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
|
||||
p->dlt_list[dlt_index++] = DLT_FRELAY;
|
||||
}
|
||||
p->dlt_list[dlt_index++] = DLT_CHDLC;
|
||||
p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
|
||||
p->dlt_list[dlt_index++] = DLT_FRELAY;
|
||||
if(!p->linktype)
|
||||
p->linktype = DLT_CHDLC;
|
||||
break;
|
||||
@ -1339,10 +1334,8 @@ dag_get_datalink(pcap_t *p)
|
||||
* DOCSIS frames out on the wire inside the low-level
|
||||
* Ethernet framing).
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[dlt_index++] = DLT_EN10MB;
|
||||
p->dlt_list[dlt_index++] = DLT_DOCSIS;
|
||||
}
|
||||
p->dlt_list[dlt_index++] = DLT_EN10MB;
|
||||
p->dlt_list[dlt_index++] = DLT_DOCSIS;
|
||||
if(!p->linktype)
|
||||
p->linktype = DLT_EN10MB;
|
||||
break;
|
||||
@ -1351,42 +1344,34 @@ dag_get_datalink(pcap_t *p)
|
||||
case ERF_TYPE_AAL5:
|
||||
case ERF_TYPE_MC_ATM:
|
||||
case ERF_TYPE_MC_AAL5:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[dlt_index++] = DLT_ATM_RFC1483;
|
||||
p->dlt_list[dlt_index++] = DLT_SUNATM;
|
||||
}
|
||||
p->dlt_list[dlt_index++] = DLT_ATM_RFC1483;
|
||||
p->dlt_list[dlt_index++] = DLT_SUNATM;
|
||||
if(!p->linktype)
|
||||
p->linktype = DLT_ATM_RFC1483;
|
||||
break;
|
||||
|
||||
case ERF_TYPE_COLOR_MC_HDLC_POS:
|
||||
case ERF_TYPE_MC_HDLC:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[dlt_index++] = DLT_CHDLC;
|
||||
p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
|
||||
p->dlt_list[dlt_index++] = DLT_FRELAY;
|
||||
p->dlt_list[dlt_index++] = DLT_MTP2;
|
||||
p->dlt_list[dlt_index++] = DLT_MTP2_WITH_PHDR;
|
||||
p->dlt_list[dlt_index++] = DLT_LAPD;
|
||||
}
|
||||
p->dlt_list[dlt_index++] = DLT_CHDLC;
|
||||
p->dlt_list[dlt_index++] = DLT_PPP_SERIAL;
|
||||
p->dlt_list[dlt_index++] = DLT_FRELAY;
|
||||
p->dlt_list[dlt_index++] = DLT_MTP2;
|
||||
p->dlt_list[dlt_index++] = DLT_MTP2_WITH_PHDR;
|
||||
p->dlt_list[dlt_index++] = DLT_LAPD;
|
||||
if(!p->linktype)
|
||||
p->linktype = DLT_CHDLC;
|
||||
break;
|
||||
|
||||
case ERF_TYPE_IPV4:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[dlt_index++] = DLT_RAW;
|
||||
p->dlt_list[dlt_index++] = DLT_IPV4;
|
||||
}
|
||||
p->dlt_list[dlt_index++] = DLT_RAW;
|
||||
p->dlt_list[dlt_index++] = DLT_IPV4;
|
||||
if(!p->linktype)
|
||||
p->linktype = DLT_RAW;
|
||||
break;
|
||||
|
||||
case ERF_TYPE_IPV6:
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[dlt_index++] = DLT_RAW;
|
||||
p->dlt_list[dlt_index++] = DLT_IPV6;
|
||||
}
|
||||
p->dlt_list[dlt_index++] = DLT_RAW;
|
||||
p->dlt_list[dlt_index++] = DLT_IPV6;
|
||||
if(!p->linktype)
|
||||
p->linktype = DLT_RAW;
|
||||
break;
|
||||
@ -1429,7 +1414,7 @@ dag_get_datalink(pcap_t *p)
|
||||
* There are no regular interfaces, just DAG interfaces.
|
||||
*/
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@ -1438,7 +1423,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
|
||||
* Attempts to open a regular interface fail.
|
||||
*/
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device, char *errbuf)
|
||||
pcapint_create_interface(const char *device, char *errbuf)
|
||||
{
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"This version of libpcap only supports DAG cards");
|
||||
|
@ -28,9 +28,7 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -91,7 +89,7 @@ dbus_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *us
|
||||
|
||||
gettimeofday(&pkth.ts, NULL);
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, (u_char *)raw_msg, pkth.len, pkth.caplen)) {
|
||||
pcapint_filter(handle->fcode.bf_insns, (u_char *)raw_msg, pkth.len, pkth.caplen)) {
|
||||
handlep->packets_read++;
|
||||
callback(user, &pkth, (u_char *)raw_msg);
|
||||
count++;
|
||||
@ -142,7 +140,7 @@ dbus_cleanup(pcap_t *handle)
|
||||
|
||||
dbus_connection_unref(handlep->conn);
|
||||
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -227,7 +225,7 @@ dbus_activate(pcap_t *handle)
|
||||
handle->linktype = DLT_DBUS;
|
||||
handle->read_op = dbus_read;
|
||||
handle->inject_op = dbus_write;
|
||||
handle->setfilter_op = install_bpf_program; /* XXX, later add support for dbus_bus_add_match() */
|
||||
handle->setfilter_op = pcapint_install_bpf_program; /* XXX, later add support for dbus_bus_add_match() */
|
||||
handle->setdirection_op = NULL;
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = dbus_getnonblock;
|
||||
@ -338,11 +336,11 @@ dbus_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
* The notion of "connected" vs. "disconnected" doesn't apply.
|
||||
* XXX - what about the notions of "up" and "running"?
|
||||
*/
|
||||
if (add_dev(devlistp, "dbus-system",
|
||||
if (pcapint_add_dev(devlistp, "dbus-system",
|
||||
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, "D-Bus system bus",
|
||||
err_str) == NULL)
|
||||
return -1;
|
||||
if (add_dev(devlistp, "dbus-session",
|
||||
if (pcapint_add_dev(devlistp, "dbus-session",
|
||||
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, "D-Bus session bus",
|
||||
err_str) == NULL)
|
||||
return -1;
|
||||
|
@ -68,9 +68,7 @@
|
||||
* DL_HP_RAWDLS?
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@ -232,7 +230,7 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
case EAGAIN:
|
||||
return (0);
|
||||
}
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf,
|
||||
sizeof(p->errbuf), errno, "getmsg");
|
||||
return (-1);
|
||||
}
|
||||
@ -256,7 +254,7 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, int size)
|
||||
#if defined(DLIOCRAW)
|
||||
ret = write(p->fd, buf, size);
|
||||
if (ret == -1) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send");
|
||||
return (-1);
|
||||
}
|
||||
@ -268,7 +266,7 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, int size)
|
||||
}
|
||||
ret = dlrawdatareq(pd->send_fd, buf, size);
|
||||
if (ret == -1) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send");
|
||||
return (-1);
|
||||
}
|
||||
@ -301,7 +299,7 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, int size)
|
||||
* it should check "p->linktype" and reject the send request if
|
||||
* it's anything other than DLT_EN10MB.
|
||||
*/
|
||||
pcap_strlcpy(p->errbuf, "send: Not supported on this version of this OS",
|
||||
pcapint_strlcpy(p->errbuf, "send: Not supported on this version of this OS",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
ret = -1;
|
||||
#endif /* raw mode */
|
||||
@ -335,7 +333,7 @@ pcap_cleanup_dlpi(pcap_t *p)
|
||||
pd->send_fd = -1;
|
||||
}
|
||||
#endif
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -357,9 +355,9 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
|
||||
*/
|
||||
cp = strrchr(name, '/');
|
||||
if (cp == NULL)
|
||||
pcap_strlcpy(dname, name, sizeof(dname));
|
||||
pcapint_strlcpy(dname, name, sizeof(dname));
|
||||
else
|
||||
pcap_strlcpy(dname, cp + 1, sizeof(dname));
|
||||
pcapint_strlcpy(dname, cp + 1, sizeof(dname));
|
||||
|
||||
/*
|
||||
* Split the device name into a device type name and a unit number;
|
||||
@ -394,7 +392,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
|
||||
cp, (errno == EPERM) ? "EPERM" : "EACCES");
|
||||
} else {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Attempt to open %s failed", cp);
|
||||
}
|
||||
return (status);
|
||||
@ -417,7 +415,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
|
||||
* device name.
|
||||
*/
|
||||
if (*name == '/')
|
||||
pcap_strlcpy(dname, name, sizeof(dname));
|
||||
pcapint_strlcpy(dname, name, sizeof(dname));
|
||||
else
|
||||
snprintf(dname, sizeof(dname), "%s/%s", PCAP_DEV_PREFIX,
|
||||
name);
|
||||
@ -438,7 +436,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
|
||||
* Make a copy of the device pathname, and then remove the unit
|
||||
* number from the device pathname.
|
||||
*/
|
||||
pcap_strlcpy(dname2, dname, sizeof(dname));
|
||||
pcapint_strlcpy(dname2, dname, sizeof(dname));
|
||||
*cp = '\0';
|
||||
|
||||
/* Try device without unit number */
|
||||
@ -452,7 +450,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
|
||||
(errno == EPERM) ? "EPERM" : "EACCES");
|
||||
} else {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"Attempt to open %s failed", dname);
|
||||
}
|
||||
@ -498,7 +496,7 @@ open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
|
||||
(errno == EPERM) ? "EPERM" : "EACCES");
|
||||
} else {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"Attempt to open %s failed",
|
||||
dname2);
|
||||
@ -685,7 +683,7 @@ pcap_activate_dlpi(pcap_t *p)
|
||||
*/
|
||||
if (strioctl(p->fd, A_PROMISCON_REQ, 0, NULL) < 0) {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "A_PROMISCON_REQ");
|
||||
goto bad;
|
||||
}
|
||||
@ -803,7 +801,7 @@ pcap_activate_dlpi(pcap_t *p)
|
||||
*/
|
||||
if (strioctl(p->fd, DLIOCRAW, 0, NULL) < 0) {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "DLIOCRAW");
|
||||
goto bad;
|
||||
}
|
||||
@ -844,7 +842,7 @@ pcap_activate_dlpi(pcap_t *p)
|
||||
*/
|
||||
if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "FLUSHR");
|
||||
goto bad;
|
||||
}
|
||||
@ -865,11 +863,11 @@ pcap_activate_dlpi(pcap_t *p)
|
||||
|
||||
p->read_op = pcap_read_dlpi;
|
||||
p->inject_op = pcap_inject_dlpi;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented.*/
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_dlpi;
|
||||
p->cleanup_op = pcap_cleanup_dlpi;
|
||||
|
||||
@ -987,7 +985,7 @@ dl_dohpuxbind(int fd, char *ebuf)
|
||||
*ebuf = '\0';
|
||||
hpsap++;
|
||||
if (hpsap > 100) {
|
||||
pcap_strlcpy(ebuf,
|
||||
pcapint_strlcpy(ebuf,
|
||||
"All SAPs from 22 through 100 are in use",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
@ -1100,7 +1098,7 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
#ifdef HAVE_SOLARIS
|
||||
int fd;
|
||||
@ -1116,7 +1114,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
/*
|
||||
* Get the list of regular interfaces first.
|
||||
*/
|
||||
if (pcap_findalldevs_interfaces(devlistp, errbuf, is_dlpi_interface,
|
||||
if (pcapint_findalldevs_interfaces(devlistp, errbuf, is_dlpi_interface,
|
||||
get_if_flags) == -1)
|
||||
return (-1); /* failure */
|
||||
|
||||
@ -1137,7 +1135,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
}
|
||||
|
||||
if (strioctl(fd, A_GET_UNITS, sizeof(buf), (char *)&buf) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "A_GET_UNITS");
|
||||
return (-1);
|
||||
}
|
||||
@ -1148,7 +1146,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* And is there a way to determine whether the
|
||||
* interface is plugged into a network?
|
||||
*/
|
||||
if (add_dev(devlistp, baname, 0, NULL, errbuf) == NULL)
|
||||
if (pcapint_add_dev(devlistp, baname, 0, NULL, errbuf) == NULL)
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
@ -1168,7 +1166,7 @@ send_request(int fd, char *ptr, int len, char *what, char *ebuf)
|
||||
|
||||
flags = 0;
|
||||
if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send_request: putmsg \"%s\"", what);
|
||||
return (-1);
|
||||
}
|
||||
@ -1197,7 +1195,7 @@ recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf, int *uerror
|
||||
|
||||
flags = 0;
|
||||
if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "recv_ack: %s getmsg", what);
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
@ -1220,7 +1218,7 @@ recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf, int *uerror
|
||||
case DL_SYSERR:
|
||||
if (uerror != NULL)
|
||||
*uerror = dlp->error_ack.dl_unix_errno;
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
dlp->error_ack.dl_unix_errno,
|
||||
"recv_ack: %s: UNIX error", what);
|
||||
if (dlp->error_ack.dl_unix_errno == EPERM ||
|
||||
@ -1577,7 +1575,7 @@ get_release(char *buf, size_t bufsize, bpf_u_int32 *majorp,
|
||||
*minorp = 0;
|
||||
*microp = 0;
|
||||
if (sysinfo(SI_RELEASE, buf, bufsize) < 0) {
|
||||
pcap_strlcpy(buf, "?", bufsize);
|
||||
pcapint_strlcpy(buf, "?", bufsize);
|
||||
return;
|
||||
}
|
||||
cp = buf;
|
||||
@ -1676,7 +1674,7 @@ get_dlpi_ppa(register int fd, register const char *device, register u_int unit,
|
||||
*/
|
||||
/* get the head first */
|
||||
if (getmsg(fd, &ctl, (struct strbuf *)NULL, &flags) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "get_dlpi_ppa: hpppa getmsg");
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
@ -1703,7 +1701,7 @@ get_dlpi_ppa(register int fd, register const char *device, register u_int unit,
|
||||
|
||||
/* allocate buffer */
|
||||
if ((ppa_data_buf = (char *)malloc(dlp->dl_length)) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "get_dlpi_ppa: hpppa malloc");
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
@ -1712,7 +1710,7 @@ get_dlpi_ppa(register int fd, register const char *device, register u_int unit,
|
||||
ctl.buf = (char *)ppa_data_buf;
|
||||
/* get the data */
|
||||
if (getmsg(fd, &ctl, (struct strbuf *)NULL, &flags) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "get_dlpi_ppa: hpppa getmsg");
|
||||
free(ppa_data_buf);
|
||||
return (PCAP_ERROR);
|
||||
@ -1782,7 +1780,7 @@ get_dlpi_ppa(register int fd, register const char *device, register u_int unit,
|
||||
*/
|
||||
snprintf(dname, sizeof(dname), "/dev/%s%u", device, unit);
|
||||
if (stat(dname, &statbuf) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "stat: %s", dname);
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
@ -1855,7 +1853,7 @@ get_dlpi_ppa(register int fd, register const char *ifname, register u_int unit,
|
||||
}
|
||||
kd = open("/dev/kmem", O_RDONLY);
|
||||
if (kd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "kmem open");
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
@ -1890,13 +1888,13 @@ dlpi_kread(register int fd, register off_t addr,
|
||||
register int cc;
|
||||
|
||||
if (lseek(fd, addr, SEEK_SET) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "lseek");
|
||||
return (-1);
|
||||
}
|
||||
cc = read(fd, buf, len);
|
||||
if (cc < 0) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "read");
|
||||
return (-1);
|
||||
} else if (cc != len) {
|
||||
@ -1909,7 +1907,7 @@ dlpi_kread(register int fd, register off_t addr,
|
||||
#endif
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
#ifdef DL_HP_RAWDLS
|
||||
|
@ -92,7 +92,7 @@ static int ref_count = 0;
|
||||
static u_long mac_count = 0;
|
||||
static u_long filter_count = 0;
|
||||
|
||||
static volatile BOOL exc_occured = 0;
|
||||
static volatile BOOL exc_occurred = 0;
|
||||
|
||||
static struct device *handle_to_device [20];
|
||||
|
||||
@ -250,7 +250,7 @@ pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
|
||||
}
|
||||
}
|
||||
|
||||
while (!exc_occured)
|
||||
while (!exc_occurred)
|
||||
{
|
||||
volatile struct device *dev; /* might be reset by sig_handler */
|
||||
|
||||
@ -480,7 +480,7 @@ static void pcap_cleanup_dos (pcap_t *p)
|
||||
{
|
||||
struct pcap_dos *pd;
|
||||
|
||||
if (!exc_occured)
|
||||
if (!exc_occurred)
|
||||
{
|
||||
pd = p->priv;
|
||||
if (pcap_stats(p,NULL) < 0)
|
||||
@ -599,7 +599,7 @@ int pcap_platform_finddevs (pcap_if_list_t *devlistp, char *errbuf)
|
||||
* a wired device, and set PCAP_IF_CONNECTION_STATUS_CONNECTED
|
||||
* or PCAP_IF_CONNECTION_STATUS_DISCONNECTED?
|
||||
*/
|
||||
if ((curdev = add_dev(devlistp, dev->name, 0,
|
||||
if ((curdev = pcap_add_dev(devlistp, dev->name, 0,
|
||||
dev->long_name, errbuf)) == NULL)
|
||||
{
|
||||
ret = -1;
|
||||
@ -618,7 +618,7 @@ int pcap_platform_finddevs (pcap_if_list_t *devlistp, char *errbuf)
|
||||
broadaddr = (struct sockaddr*) &sa_ll_2;
|
||||
memset (&sa_ll_2.sin_addr, 0xFF, sizeof(sa_ll_2.sin_addr));
|
||||
|
||||
if (add_addr_to_dev(curdev, addr, sizeof(*addr),
|
||||
if (pcap_add_addr_to_dev(curdev, addr, sizeof(*addr),
|
||||
netmask, sizeof(*netmask),
|
||||
broadaddr, sizeof(*broadaddr),
|
||||
dstaddr, sizeof(*dstaddr), errbuf) < 0)
|
||||
@ -663,7 +663,7 @@ void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait)
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialise a named network device.
|
||||
* Initialize a named network device.
|
||||
*/
|
||||
static struct device *
|
||||
open_driver (const char *dev_name, char *ebuf, int promisc)
|
||||
@ -741,7 +741,7 @@ not_probed:
|
||||
}
|
||||
|
||||
/*
|
||||
* Deinitialise MAC driver.
|
||||
* Deinitialize MAC driver.
|
||||
* Set receive mode back to default mode.
|
||||
*/
|
||||
static void close_driver (void)
|
||||
@ -803,7 +803,7 @@ static void exc_handler (int sig)
|
||||
default:
|
||||
fprintf (stderr, "Catching signal %d.\n", sig);
|
||||
}
|
||||
exc_occured = 1;
|
||||
exc_occurred = 1;
|
||||
close_driver();
|
||||
}
|
||||
#endif /* __DJGPP__ */
|
||||
@ -850,7 +850,7 @@ static int first_init (const char *name, char *ebuf, int promisc)
|
||||
#ifdef USE_32BIT_DRIVERS
|
||||
/*
|
||||
* If driver is NOT a 16-bit "pkt/ndis" driver (having a 'copy_rx_buf'
|
||||
* set in it's probe handler), initialise near-memory ring-buffer for
|
||||
* set in it's probe handler), initialize near-memory ring-buffer for
|
||||
* the 32-bit device.
|
||||
*/
|
||||
if (dev->copy_rx_buf == NULL)
|
||||
@ -1001,7 +1001,7 @@ static int init_watt32 (struct pcap *pcap, const char *dev_name, char *err_buf)
|
||||
has_ip_addr = (rc != 8); /* IP-address assignment failed */
|
||||
|
||||
/* if pcap is using a 32-bit driver w/o a pktdrvr loaded, we
|
||||
* just pretend Watt-32 is initialised okay.
|
||||
* just pretend Watt-32 is initialized okay.
|
||||
*
|
||||
* !! fix-me: The Watt-32 config isn't done if no pktdrvr
|
||||
* was found. In that case my_ip_addr + sin_mask
|
||||
@ -1295,7 +1295,7 @@ struct device tc90xbc_dev LOCKED_VAR = {
|
||||
|
||||
struct device wd_dev LOCKED_VAR = {
|
||||
"wd",
|
||||
"Westen Digital",
|
||||
"Western Digital",
|
||||
0,
|
||||
0,0,0,0,0,0,
|
||||
&tc90xbc_dev,
|
||||
|
@ -70,14 +70,12 @@ mkdir -p build && cd build && cmake -DDPDK_DIR=$RTE_SDK/$RTE_TARGET ../ && make
|
||||
|
||||
4. Link your own program with libpcap, and use DPDK with the device name as dpdk:{portid}, such as dpdk:0.
|
||||
And you shall set DPDK configure options by environment variable DPDK_CFG
|
||||
For example, the testprogs/capturetest could be lanched by:
|
||||
For example, the testprogs/capturetest could be launched by:
|
||||
|
||||
env DPDK_CFG="--log-level=debug -l0 -dlibrte_pmd_e1000.so -dlibrte_pmd_ixgbe.so -dlibrte_mempool_ring.so" ./capturetest -i dpdk:0
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
@ -407,7 +405,7 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
|
||||
|
||||
}
|
||||
if (bp){
|
||||
if (p->fcode.bf_insns==NULL || pcap_filter(p->fcode.bf_insns, bp, pcap_header.len, pcap_header.caplen)){
|
||||
if (p->fcode.bf_insns==NULL || pcapint_filter(p->fcode.bf_insns, bp, pcap_header.len, pcap_header.caplen)){
|
||||
cb(cb_arg, &pcap_header, bp);
|
||||
}else{
|
||||
pd->bpf_drop++;
|
||||
@ -427,7 +425,7 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
|
||||
static int pcap_dpdk_inject(pcap_t *p, const void *buf _U_, int size _U_)
|
||||
{
|
||||
//not implemented yet
|
||||
pcap_strlcpy(p->errbuf,
|
||||
pcapint_strlcpy(p->errbuf,
|
||||
"dpdk error: Inject function has not been implemented yet",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return PCAP_ERROR;
|
||||
@ -446,7 +444,7 @@ static void pcap_dpdk_close(pcap_t *p)
|
||||
}
|
||||
rte_eth_dev_stop(pd->portid);
|
||||
rte_eth_dev_close(pd->portid);
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
static void nic_stats_display(struct pcap_dpdk *pd)
|
||||
@ -529,8 +527,8 @@ static void eth_addr_str(ETHER_ADDR_TYPE *addrp, char* mac_str, int len)
|
||||
static uint16_t portid_by_device(char * device)
|
||||
{
|
||||
uint16_t ret = DPDK_PORTID_MAX;
|
||||
int len = strlen(device);
|
||||
int prefix_len = strlen(DPDK_PREFIX);
|
||||
size_t len = strlen(device);
|
||||
size_t prefix_len = strlen(DPDK_PREFIX);
|
||||
unsigned long ret_ul = 0L;
|
||||
char *pEnd;
|
||||
if (len<=prefix_len || strncmp(device, DPDK_PREFIX, prefix_len)) // check prefix dpdk:
|
||||
@ -570,7 +568,7 @@ static int parse_dpdk_cfg(char* dpdk_cfg,char** dargv)
|
||||
skip_space=!skip_space; // skip normal char
|
||||
dargv[cnt++] = dpdk_cfg+i;
|
||||
}
|
||||
if (!skip_space && dpdk_cfg[i]==' '){ // fint a space
|
||||
if (!skip_space && dpdk_cfg[i]==' '){ // find a space
|
||||
dpdk_cfg[i]=0x00; // end of this opt
|
||||
skip_space=!skip_space; // skip space char
|
||||
}
|
||||
@ -600,7 +598,7 @@ static int dpdk_pre_init(char * ebuf, int eaccess_not_fatal)
|
||||
char *dargv[DPDK_ARGC_MAX];
|
||||
char *ptr_dpdk_cfg = NULL;
|
||||
int ret;
|
||||
// globale var
|
||||
// global var
|
||||
if (is_dpdk_pre_inited != 0)
|
||||
{
|
||||
// already inited; did that succeed?
|
||||
@ -948,15 +946,15 @@ static int pcap_dpdk_activate(pcap_t *p)
|
||||
p->selectable_fd = p->fd;
|
||||
p->read_op = pcap_dpdk_dispatch;
|
||||
p->inject_op = pcap_dpdk_inject;
|
||||
// using pcap_filter currently, though DPDK provides their own BPF function. Because DPDK BPF needs load a ELF file as a filter.
|
||||
p->setfilter_op = install_bpf_program;
|
||||
// using pcapint_filter currently, though DPDK provides their own BPF function. Because DPDK BPF needs load a ELF file as a filter.
|
||||
p->setfilter_op = pcapint_install_bpf_program;
|
||||
p->setdirection_op = NULL;
|
||||
p->set_datalink_op = NULL;
|
||||
p->getnonblock_op = pcap_dpdk_getnonblock;
|
||||
p->setnonblock_op = pcap_dpdk_setnonblock;
|
||||
p->stats_op = pcap_dpdk_stats;
|
||||
p->cleanup_op = pcap_dpdk_close;
|
||||
p->breakloop_op = pcap_breakloop_common;
|
||||
p->breakloop_op = pcapint_breakloop_common;
|
||||
// set default timeout
|
||||
pd->required_select_timeout.tv_sec = 0;
|
||||
pd->required_select_timeout.tv_usec = DPDK_DEF_MIN_SLEEP_MS*1000;
|
||||
@ -966,7 +964,7 @@ static int pcap_dpdk_activate(pcap_t *p)
|
||||
|
||||
if (ret <= PCAP_ERROR) // all kinds of error code
|
||||
{
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}else{
|
||||
rte_eth_dev_get_name_by_port(portid,pd->pci_addr);
|
||||
RTE_LOG(INFO, USER1,"Port %d device: %s, MAC:%s, PCI:%s\n", portid, p->opt.device, pd->mac_addr, pd->pci_addr);
|
||||
@ -1041,7 +1039,7 @@ int pcap_dpdk_findalldevs(pcap_if_list_t *devlistp, char *ebuf)
|
||||
// PCI addr
|
||||
rte_eth_dev_get_name_by_port(i,pci_addr);
|
||||
snprintf(dpdk_desc,DPDK_DEV_DESC_MAX-1,"%s %s, MAC:%s, PCI:%s", DPDK_DESC, dpdk_name, mac_addr, pci_addr);
|
||||
if (add_dev(devlistp, dpdk_name, 0, dpdk_desc, ebuf)==NULL){
|
||||
if (pcapint_add_dev(devlistp, dpdk_name, 0, dpdk_desc, ebuf)==NULL){
|
||||
ret = PCAP_ERROR;
|
||||
break;
|
||||
}
|
||||
@ -1059,7 +1057,7 @@ int pcap_dpdk_findalldevs(pcap_if_list_t *devlistp, char *ebuf)
|
||||
* There are no regular interfaces, just DPDK interfaces.
|
||||
*/
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@ -1068,7 +1066,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf)
|
||||
* Attempts to open a regular interface fail.
|
||||
*/
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device, char *errbuf)
|
||||
pcapint_create_interface(const char *device, char *errbuf)
|
||||
{
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"This version of libpcap only supports DPDK");
|
||||
|
@ -7,9 +7,7 @@
|
||||
* Rayan Zachariassen, CA*Net
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@ -75,7 +73,7 @@ readloop(int cnt, int if_fd, struct bpf_program *fp, printfunc printit)
|
||||
ph = (struct packet_header *)bp;
|
||||
caplen = ph->tap.th_wirelen > snaplen ? snaplen : ph->tap
|
||||
.th_wirelen ;
|
||||
if (pcap_filter(fcode, (char *)ph->packet,
|
||||
if (pcapint_filter(fcode, (char *)ph->packet,
|
||||
ph->tap.th_wirelen, caplen)) {
|
||||
if (cnt >= 0 && --cnt < 0)
|
||||
goto out;
|
||||
@ -89,7 +87,7 @@ readloop(int cnt, int if_fd, struct bpf_program *fp, printfunc printit)
|
||||
}
|
||||
#else /* !IBMRTPC */
|
||||
caplen = cc > snaplen ? snaplen : cc ;
|
||||
if (pcap_filter(fcode, buf.hdr.packet, cc, caplen)) {
|
||||
if (pcapint_filter(fcode, buf.hdr.packet, cc, caplen)) {
|
||||
if (cnt >= 0 && --cnt < 0)
|
||||
goto out;
|
||||
(*printit)(buf.hdr.packet, &tv, cc, caplen);
|
||||
|
@ -18,7 +18,7 @@
|
||||
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.\"
|
||||
.TH PCAP-FILTER @MAN_MISC_INFO@ "19 November 2022"
|
||||
.TH PCAP-FILTER @MAN_MISC_INFO@ "13 June 2023"
|
||||
.SH NAME
|
||||
pcap-filter \- packet filter syntax
|
||||
.br
|
||||
@ -107,7 +107,7 @@ E.g., `\fBether src\fP foo', `\fBarp net\fP 128.3', `\fBtcp port\fP 21',
|
||||
If there is no
|
||||
.I proto
|
||||
qualifier, all protocols consistent with the type are assumed.
|
||||
E.g., `\fBsrc\fP foo' means `\fB(ip or arp or rarp) src\fP foo',
|
||||
E.g., `\fBsrc\fP foo' means `\fB(ip6 or ip or arp or rarp) src\fP foo',
|
||||
`\fBnet\fP bar' means `\fB(ip or arp or rarp) net\fP bar' and
|
||||
`\fBport\fP 53' means `\fB(tcp or udp or sctp) port\fP 53'
|
||||
(note that these examples use invalid syntax to illustrate the principle).
|
||||
@ -212,7 +212,7 @@ number (e.g., 10); the netmask is 255.255.255.255 for a dotted quad
|
||||
(which means that it's really a host match), 255.255.255.0 for a dotted
|
||||
triple, 255.255.0.0 for a dotted pair, or 255.0.0.0 for a single number.
|
||||
An IPv6 network number must be written out fully; the netmask is
|
||||
ff:ff:ff:ff:ff:ff:ff:ff, so IPv6 "network" matches are really always
|
||||
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff, so IPv6 "network" matches are really always
|
||||
host matches, and a network match requires a netmask length.
|
||||
.IP "\fBsrc net \fInetnameaddr\fR"
|
||||
True if the IPv4/v6 source address of the packet has a network
|
||||
@ -555,6 +555,9 @@ Packet was sent by the host performing the capture rather than being
|
||||
received by that host. This is only supported for certain link-layer types,
|
||||
such as SLIP and the ``cooked'' Linux capture mode
|
||||
used for the ``any'' device and for some other device types.
|
||||
.IP "\fBifindex \fIinterface_index\fR"
|
||||
True if the packet was logged via the specified interface (applies only to
|
||||
packets logged by the Linux "any" cooked v2 interface).
|
||||
.IP "\fBifname \fIinterface\fR"
|
||||
True if the packet was logged as coming from the specified interface (applies
|
||||
only to packets logged by OpenBSD's or FreeBSD's
|
||||
@ -1042,8 +1045,6 @@ Alternation (`\fB||\fP' or `\fBor\fP').
|
||||
Negation has the highest precedence.
|
||||
Alternation and concatenation have equal precedence and associate
|
||||
left to right.
|
||||
Note that explicit \fBand\fR tokens, not juxtaposition,
|
||||
are now required for concatenation.
|
||||
.LP
|
||||
If an identifier is given without a keyword, the most recent keyword
|
||||
is assumed.
|
||||
@ -1174,6 +1175,10 @@ TCP flag names became available in libpcap 1.9.0.
|
||||
The
|
||||
.B geneve
|
||||
keyword became available in libpcap 1.8.0.
|
||||
.PP
|
||||
The
|
||||
.B ifindex
|
||||
keyword became available in libpcap 1.10.0.
|
||||
.SH SEE ALSO
|
||||
.BR pcap (3PCAP)
|
||||
.SH BUGS
|
||||
|
504
contrib/libpcap/pcap-haiku.c
Normal file
504
contrib/libpcap/pcap-haiku.c
Normal file
@ -0,0 +1,504 @@
|
||||
/*
|
||||
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
* James Woodcock
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
#include <net/if_media.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// IFT_TUN was renamed to IFT_TUNNEL in the master branch after R1/beta4 (the
|
||||
// integer value didn't change). Even though IFT_TUN is a no-op in versions
|
||||
// that define it, for the time being it is desirable to support compiling
|
||||
// libpcap on versions with the old macro and using it on later versions that
|
||||
// support tunnel interfaces.
|
||||
#ifndef IFT_TUNNEL
|
||||
#define IFT_TUNNEL IFT_TUN
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Private data for capturing on Haiku sockets.
|
||||
*/
|
||||
struct pcap_haiku {
|
||||
struct pcap_stat stat;
|
||||
int aux_socket;
|
||||
struct ifreq ifreq;
|
||||
// The original state of the promiscuous mode at the activation time,
|
||||
// if the capture should be run in promiscuous mode.
|
||||
int orig_promisc;
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
pcap_read_haiku(pcap_t* handle, int maxPackets _U_, pcap_handler callback,
|
||||
u_char* userdata)
|
||||
{
|
||||
// Receive a single packet
|
||||
|
||||
u_char* buffer = (u_char*)handle->buffer;
|
||||
ssize_t bytesReceived;
|
||||
do {
|
||||
if (handle->break_loop) {
|
||||
handle->break_loop = 0;
|
||||
return PCAP_ERROR_BREAK;
|
||||
}
|
||||
bytesReceived = recvfrom(handle->fd, buffer, handle->bufsize, MSG_TRUNC,
|
||||
NULL, NULL);
|
||||
} while (bytesReceived < 0 && errno == B_INTERRUPTED);
|
||||
|
||||
// The kernel does not implement timestamping of network packets, so
|
||||
// doing it ASAP in userland is the best that can be done.
|
||||
bigtime_t ts = real_time_clock_usecs();
|
||||
|
||||
if (bytesReceived < 0) {
|
||||
if (errno == B_WOULD_BLOCK) {
|
||||
// there is no packet for us
|
||||
return 0;
|
||||
}
|
||||
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "recvfrom");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
struct pcap_haiku* handlep = (struct pcap_haiku*)handle->priv;
|
||||
// BPF is 32-bit, which is more than sufficient for any realistic
|
||||
// packet size.
|
||||
if (bytesReceived > UINT32_MAX)
|
||||
goto drop;
|
||||
// At this point, if the recvfrom() call populated its struct sockaddr
|
||||
// and socklen_t arguments, it would be the right time to drop packets
|
||||
// that have .sa_family not valid for the current DLT. But in the
|
||||
// current master branch (hrev57588) this would erroneously drop some
|
||||
// valid packets: recvfrom(), at least for tap mode tunnels, sets the
|
||||
// address length to 0 for all incoming packets and sets .sa_len and
|
||||
// .sa_family to 0 for packets that are broadcast or multicast. So it
|
||||
// cannot be done yet, if there is a good reason to do it in the first
|
||||
// place.
|
||||
handlep->stat.ps_recv++;
|
||||
|
||||
bpf_u_int32 wireLength = (bpf_u_int32)bytesReceived;
|
||||
// As long as the buffer is large enough, the captured length is equal
|
||||
// to the wire length, but let's get the lengths right anyway in case
|
||||
// packets grow bigger or the buffer grows smaller in future and the
|
||||
// MSG_TRUNC effect kicks in.
|
||||
bpf_u_int32 captureLength =
|
||||
wireLength <= handle->bufsize ? wireLength : handle->bufsize;
|
||||
|
||||
// run the packet filter
|
||||
if (handle->fcode.bf_insns) {
|
||||
// NB: pcapint_filter() takes the wire length and the captured
|
||||
// length, not the snapshot length of the pcap_t handle.
|
||||
if (pcapint_filter(handle->fcode.bf_insns, buffer, wireLength,
|
||||
captureLength) == 0)
|
||||
goto drop;
|
||||
}
|
||||
|
||||
// fill in pcap_header
|
||||
struct pcap_pkthdr header;
|
||||
header.caplen = captureLength <= (bpf_u_int32)handle->snapshot ?
|
||||
captureLength :
|
||||
(bpf_u_int32)handle->snapshot;
|
||||
header.len = wireLength;
|
||||
header.ts.tv_usec = ts % 1000000;
|
||||
header.ts.tv_sec = ts / 1000000;
|
||||
|
||||
/* Call the user supplied callback function */
|
||||
callback(userdata, &header, buffer);
|
||||
return 1;
|
||||
drop:
|
||||
handlep->stat.ps_drop++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
dgram_socket(const int af, char *errbuf)
|
||||
{
|
||||
int ret = socket(af, SOCK_DGRAM, 0);
|
||||
if (ret < 0) {
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno,
|
||||
"socket");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ioctl_ifreq(const int fd, const unsigned long op, const char *name,
|
||||
struct ifreq *ifreq, char *errbuf)
|
||||
{
|
||||
if (ioctl(fd, op, ifreq, sizeof(struct ifreq)) < 0) {
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, errno,
|
||||
"%s", name);
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
get_promisc(pcap_t *handle)
|
||||
{
|
||||
struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv;
|
||||
// SIOCGIFFLAGS would work fine for AF_LINK too.
|
||||
if (ioctl_ifreq(handlep->aux_socket, SIOCGIFFLAGS, "SIOCGIFFLAGS",
|
||||
&handlep->ifreq, handle->errbuf) < 0)
|
||||
return PCAP_ERROR;
|
||||
return (handlep->ifreq.ifr_flags & IFF_PROMISC) != 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
set_promisc(pcap_t *handle, const int enable)
|
||||
{
|
||||
struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv;
|
||||
if (enable)
|
||||
handlep->ifreq.ifr_flags |= IFF_PROMISC;
|
||||
else
|
||||
handlep->ifreq.ifr_flags &= ~IFF_PROMISC;
|
||||
// SIOCSIFFLAGS works for AF_INET, but not for AF_LINK.
|
||||
return ioctl_ifreq(handlep->aux_socket, SIOCSIFFLAGS, "SIOCSIFFLAGS",
|
||||
&handlep->ifreq, handle->errbuf);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pcap_cleanup_haiku(pcap_t *handle)
|
||||
{
|
||||
struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv;
|
||||
if (handlep->aux_socket >= 0) {
|
||||
// Closing the sockets has no effect on IFF_PROMISC, hence the
|
||||
// need to restore the original state on one hand and the
|
||||
// possibility of clash with other processes managing the same
|
||||
// interface flag. Unset promiscuous mode iff the activation
|
||||
// function had set it and it is still set now.
|
||||
if (handle->opt.promisc && ! handlep->orig_promisc &&
|
||||
get_promisc(handle))
|
||||
(void)set_promisc(handle, 0);
|
||||
close(handlep->aux_socket);
|
||||
handlep->aux_socket = -1;
|
||||
}
|
||||
pcapint_cleanup_live_common(handle);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_inject_haiku(pcap_t *handle, const void *buffer _U_, int size _U_)
|
||||
{
|
||||
// Haiku currently (hrev57588) does not support sending raw packets.
|
||||
// https://dev.haiku-os.org/ticket/18810
|
||||
strlcpy(handle->errbuf, "Sending packets isn't supported yet",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_stats_haiku(pcap_t *handle, struct pcap_stat *stats)
|
||||
{
|
||||
struct pcap_haiku* handlep = (struct pcap_haiku*)handle->priv;
|
||||
*stats = handlep->stat;
|
||||
// Now ps_recv and ps_drop are accurate, but ps_ifdrop still equals to
|
||||
// the snapshot value from the activation time.
|
||||
if (ioctl_ifreq(handlep->aux_socket, SIOCGIFSTATS, "SIOCGIFSTATS",
|
||||
&handlep->ifreq, handle->errbuf) < 0)
|
||||
return PCAP_ERROR;
|
||||
// The result is subject to wrapping around the 32-bit integer space,
|
||||
// but that cannot be significantly improved as long as it has to fit
|
||||
// into a 32-bit member of pcap_stats.
|
||||
stats->ps_ifdrop = handlep->ifreq.ifr_stats.receive.dropped - stats->ps_ifdrop;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_activate_haiku(pcap_t *handle)
|
||||
{
|
||||
struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv;
|
||||
int ret = PCAP_ERROR;
|
||||
|
||||
// we need a socket to talk to the networking stack
|
||||
if ((handlep->aux_socket = dgram_socket(AF_INET, handle->errbuf)) < 0)
|
||||
goto error;
|
||||
|
||||
// pcap_stats_haiku() will need a baseline for ps_ifdrop.
|
||||
// At the time of this writing SIOCGIFSTATS returns EINVAL for AF_LINK
|
||||
// sockets.
|
||||
if (ioctl_ifreq(handlep->aux_socket, SIOCGIFSTATS, "SIOCGIFSTATS",
|
||||
&handlep->ifreq, handle->errbuf) < 0) {
|
||||
// Detect a non-existent network interface at least at the
|
||||
// first ioctl() use.
|
||||
if (errno == EINVAL)
|
||||
ret = PCAP_ERROR_NO_SUCH_DEVICE;
|
||||
goto error;
|
||||
}
|
||||
handlep->stat.ps_ifdrop = handlep->ifreq.ifr_stats.receive.dropped;
|
||||
|
||||
// get link level interface for this interface
|
||||
if ((handle->fd = dgram_socket(AF_LINK, handle->errbuf)) < 0)
|
||||
goto error;
|
||||
|
||||
// Derive a DLT from the interface type.
|
||||
// At the time of this writing SIOCGIFTYPE cannot be used for this
|
||||
// purpose: it returns EINVAL for AF_LINK sockets and sets ifr_type to
|
||||
// 0 for AF_INET sockets. Use the same method as Haiku ifconfig does
|
||||
// (SIOCGIFADDR and AF_LINK).
|
||||
if (ioctl_ifreq(handle->fd, SIOCGIFADDR, "SIOCGIFADDR",
|
||||
&handlep->ifreq, handle->errbuf) < 0)
|
||||
goto error;
|
||||
struct sockaddr_dl *sdl = (struct sockaddr_dl *)&handlep->ifreq.ifr_addr;
|
||||
if (sdl->sdl_family != AF_LINK) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Got AF %d instead of AF_LINK for interface \"%s\".",
|
||||
sdl->sdl_family, handle->opt.device);
|
||||
goto error;
|
||||
}
|
||||
switch (sdl->sdl_type) {
|
||||
case IFT_ETHER:
|
||||
// Ethernet on all versions, also tap (L2) mode tunnels on
|
||||
// versions after R1/beta4.
|
||||
handle->linktype = DLT_EN10MB;
|
||||
break;
|
||||
case IFT_TUNNEL:
|
||||
// Unused on R1/beta4 and earlier versions, tun (L3) mode
|
||||
// tunnels on later versions.
|
||||
case IFT_LOOP:
|
||||
// The loopback interface on all versions.
|
||||
// Both IFT_TUNNEL and IFT_LOOP prepended a dummy Ethernet
|
||||
// header until hrev57585: https://dev.haiku-os.org/ticket/18801
|
||||
handle->linktype = DLT_RAW;
|
||||
break;
|
||||
default:
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Unknown interface type 0x%0x for interface \"%s\".",
|
||||
sdl->sdl_type, handle->opt.device);
|
||||
goto error;
|
||||
}
|
||||
|
||||
// start monitoring
|
||||
if (ioctl_ifreq(handle->fd, SIOCSPACKETCAP, "SIOCSPACKETCAP",
|
||||
&handlep->ifreq, handle->errbuf) < 0)
|
||||
goto error;
|
||||
|
||||
handle->selectable_fd = handle->fd;
|
||||
handle->read_op = pcap_read_haiku;
|
||||
handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
handle->inject_op = pcap_inject_haiku;
|
||||
handle->stats_op = pcap_stats_haiku;
|
||||
handle->cleanup_op = pcap_cleanup_haiku;
|
||||
|
||||
// use default hooks where possible
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
|
||||
/*
|
||||
* Turn a negative snapshot value (invalid), a snapshot value of
|
||||
* 0 (unspecified), or a value bigger than the normal maximum
|
||||
* value, into the maximum allowed value.
|
||||
*
|
||||
* If some application really *needs* a bigger snapshot
|
||||
* length, we should just increase MAXIMUM_SNAPLEN.
|
||||
*/
|
||||
if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
|
||||
handle->snapshot = MAXIMUM_SNAPLEN;
|
||||
|
||||
// Although it would be trivial to size the buffer at the kernel end of
|
||||
// the capture socket using setsockopt() and SO_RCVBUF, there seems to
|
||||
// be no point in doing so: setting the size low silently drops some
|
||||
// packets in the kernel, setting it high does not result in a visible
|
||||
// improvement. Let's leave this buffer as it is until it is clear why
|
||||
// it would need resizing. Meanwhile pcap_set_buffer_size() will have
|
||||
// no effect on Haiku.
|
||||
|
||||
// It would be wrong to size the buffer at the libpcap end of the
|
||||
// capture socket to the interface MTU, which limits only outgoing
|
||||
// packets and only at layer 3. For example, an Ethernet interface
|
||||
// with ifconfig/ioctl() MTU set to 1500 ordinarily sends layer 2
|
||||
// packets as large as 1514 bytes and receives layer 2 packets as large
|
||||
// as the NIC and the driver happen to accept (e.g. 9018 bytes for
|
||||
// ipro1000). This way, valid packets larger than the MTU can occur in
|
||||
// a capture and will arrive truncated to pcap_read_haiku() if the
|
||||
// buffer is not large enough. So let's keep it large enough for most
|
||||
// if not all practical use cases, then pcap_read_haiku() can handle
|
||||
// the unlikely truncation as and if necessary.
|
||||
handle->bufsize = 65536;
|
||||
|
||||
// allocate buffer for monitoring the device
|
||||
handle->buffer = (u_char*)malloc(handle->bufsize);
|
||||
if (handle->buffer == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "buffer malloc");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (handle->opt.promisc) {
|
||||
// Set promiscuous mode iff required, in any case remember the
|
||||
// original state.
|
||||
if ((handlep->orig_promisc = get_promisc(handle)) < 0)
|
||||
goto error;
|
||||
if (! handlep->orig_promisc && set_promisc(handle, 1) < 0)
|
||||
return PCAP_WARNING_PROMISC_NOTSUP;
|
||||
}
|
||||
return 0;
|
||||
error:
|
||||
pcap_cleanup_haiku(handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
validate_ifname(const char *device, char *errbuf)
|
||||
{
|
||||
if (strlen(device) >= IF_NAMESIZE) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Interface name \"%s\" is too long.", device);
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - pcap API
|
||||
|
||||
|
||||
static int
|
||||
can_be_bound(const char *name)
|
||||
{
|
||||
if (strcmp(name, "loop") != 0)
|
||||
return 1;
|
||||
|
||||
// In Haiku versions before hrev57010 the loopback interface allows to
|
||||
// start a capture, but the capture never receives any packets.
|
||||
//
|
||||
// Since compiling libpcap on one Haiku version and using the binary on
|
||||
// another seems to be commonplace, comparing B_HAIKU_VERSION at the
|
||||
// compile time would not always work as intended. Let's at least
|
||||
// remove unsuitable well-known 64-bit versions (with or without
|
||||
// updates) from the problem space at run time.
|
||||
const char *badversions[] = {
|
||||
"hrev56578", // R1/beta4
|
||||
"hrev55182", // R1/beta3
|
||||
"hrev54154", // R1/beta2
|
||||
"hrev52295", // R1/beta1
|
||||
"hrev44702", // R1/alpha4
|
||||
NULL
|
||||
};
|
||||
struct utsname uts;
|
||||
(void)uname(&uts);
|
||||
for (const char **s = badversions; *s; s++)
|
||||
if (! strncmp(uts.version, *s, strlen(*s)))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
pcap_t *
|
||||
pcapint_create_interface(const char *device, char *errorBuffer)
|
||||
{
|
||||
if (validate_ifname(device, errorBuffer) < 0)
|
||||
return NULL;
|
||||
if (! can_be_bound(device)) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE,
|
||||
"Interface \"%s\" does not support capturing traffic.", device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pcap_t* handle = PCAP_CREATE_COMMON(errorBuffer, struct pcap_haiku);
|
||||
if (handle == NULL)
|
||||
return NULL;
|
||||
handle->activate_op = pcap_activate_haiku;
|
||||
|
||||
struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv;
|
||||
handlep->aux_socket = -1;
|
||||
strcpy(handlep->ifreq.ifr_name, device);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
|
||||
{
|
||||
if (validate_ifname(name, errbuf) < 0)
|
||||
return PCAP_ERROR;
|
||||
|
||||
if (*flags & PCAP_IF_LOOPBACK ||
|
||||
! strncmp(name, "tun", strlen("tun")) ||
|
||||
! strncmp(name, "tap", strlen("tap"))) {
|
||||
/*
|
||||
* Loopback devices aren't wireless, and "connected"/
|
||||
* "disconnected" doesn't apply to them.
|
||||
*
|
||||
* Neither does it to tunnel interfaces. A tun mode tunnel
|
||||
* can be identified by the IFT_TUNNEL value, but tap mode
|
||||
* tunnels and Ethernet interfaces both use IFT_ETHER, so let's
|
||||
* use the interface name prefix until there is a better
|
||||
* solution.
|
||||
*/
|
||||
*flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int fd = dgram_socket(AF_LINK, errbuf);
|
||||
if (fd < 0)
|
||||
return PCAP_ERROR;
|
||||
struct ifreq ifreq;
|
||||
strcpy(ifreq.ifr_name, name);
|
||||
if (ioctl_ifreq(fd, SIOCGIFFLAGS, "SIOCGIFFLAGS", &ifreq, errbuf) < 0) {
|
||||
close(fd);
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
*flags |= (ifreq.ifr_flags & IFF_LINK) ?
|
||||
PCAP_IF_CONNECTION_STATUS_CONNECTED :
|
||||
PCAP_IF_CONNECTION_STATUS_DISCONNECTED;
|
||||
if (ioctl_ifreq(fd, SIOCGIFMEDIA, "SIOCGIFMEDIA", &ifreq, errbuf) < 0) {
|
||||
close(fd);
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
if (IFM_TYPE(ifreq.ifr_media) == IFM_IEEE80211)
|
||||
*flags |= PCAP_IF_WIRELESS;
|
||||
close(fd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
pcapint_platform_finddevs(pcap_if_list_t* _allDevices, char* errorBuffer)
|
||||
{
|
||||
return pcapint_findalldevs_interfaces(_allDevices, errorBuffer, can_be_bound,
|
||||
get_if_flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* Libpcap version string.
|
||||
*/
|
||||
const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
return (PCAP_VERSION_STRING);
|
||||
}
|
@ -1,305 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
* James Woodcock
|
||||
*/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sockio.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*
|
||||
* Private data for capturing on Haiku sockets.
|
||||
*/
|
||||
struct pcap_haiku {
|
||||
struct pcap_stat stat;
|
||||
char *device; /* device name */
|
||||
};
|
||||
|
||||
|
||||
bool
|
||||
prepare_request(struct ifreq& request, const char* name)
|
||||
{
|
||||
if (strlen(name) >= IF_NAMESIZE)
|
||||
return false;
|
||||
|
||||
strcpy(request.ifr_name, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_read_haiku(pcap_t* handle, int maxPackets _U_, pcap_handler callback,
|
||||
u_char* userdata)
|
||||
{
|
||||
// Receive a single packet
|
||||
|
||||
u_char* buffer = (u_char*)handle->buffer + handle->offset;
|
||||
struct sockaddr_dl from;
|
||||
ssize_t bytesReceived;
|
||||
do {
|
||||
if (handle->break_loop) {
|
||||
// Clear the break loop flag, and return -2 to indicate our
|
||||
// reasoning
|
||||
handle->break_loop = 0;
|
||||
return -2;
|
||||
}
|
||||
|
||||
socklen_t fromLength = sizeof(from);
|
||||
bytesReceived = recvfrom(handle->fd, buffer, handle->bufsize, MSG_TRUNC,
|
||||
(struct sockaddr*)&from, &fromLength);
|
||||
} while (bytesReceived < 0 && errno == B_INTERRUPTED);
|
||||
|
||||
if (bytesReceived < 0) {
|
||||
if (errno == B_WOULD_BLOCK) {
|
||||
// there is no packet for us
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(handle->errbuf, sizeof(handle->errbuf),
|
||||
"recvfrom: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32 captureLength = bytesReceived;
|
||||
if (captureLength > handle->snapshot)
|
||||
captureLength = handle->snapshot;
|
||||
|
||||
// run the packet filter
|
||||
if (handle->fcode.bf_insns) {
|
||||
if (pcap_filter(handle->fcode.bf_insns, buffer, bytesReceived,
|
||||
captureLength) == 0) {
|
||||
// packet got rejected
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// fill in pcap_header
|
||||
pcap_pkthdr header;
|
||||
header.caplen = captureLength;
|
||||
header.len = bytesReceived;
|
||||
header.ts.tv_usec = system_time() % 1000000;
|
||||
header.ts.tv_sec = system_time() / 1000000;
|
||||
// TODO: get timing from packet!!!
|
||||
|
||||
/* Call the user supplied callback function */
|
||||
callback(userdata, &header, buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_inject_haiku(pcap_t *handle, const void *buffer, int size)
|
||||
{
|
||||
// we don't support injecting packets yet
|
||||
// TODO: use the AF_LINK protocol (we need another socket for this) to
|
||||
// inject the packets
|
||||
strlcpy(handle->errbuf, "Sending packets isn't supported yet",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_stats_haiku(pcap_t *handle, struct pcap_stat *stats)
|
||||
{
|
||||
struct pcap_haiku* handlep = (struct pcap_haiku*)handle->priv;
|
||||
ifreq request;
|
||||
int socket = ::socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (socket < 0) {
|
||||
return -1;
|
||||
}
|
||||
prepare_request(request, handlep->device);
|
||||
if (ioctl(socket, SIOCGIFSTATS, &request, sizeof(struct ifreq)) < 0) {
|
||||
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "pcap_stats: %s",
|
||||
strerror(errno));
|
||||
close(socket);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(socket);
|
||||
handlep->stat.ps_recv += request.ifr_stats.receive.packets;
|
||||
handlep->stat.ps_drop += request.ifr_stats.receive.dropped;
|
||||
*stats = handlep->stat;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pcap_activate_haiku(pcap_t *handle)
|
||||
{
|
||||
struct pcap_haiku* handlep = (struct pcap_haiku*)handle->priv;
|
||||
|
||||
const char* device = handle->opt.device;
|
||||
|
||||
handle->read_op = pcap_read_haiku;
|
||||
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
handle->inject_op = pcap_inject_haiku;
|
||||
handle->stats_op = pcap_stats_haiku;
|
||||
|
||||
// use default hooks where possible
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
|
||||
/*
|
||||
* Turn a negative snapshot value (invalid), a snapshot value of
|
||||
* 0 (unspecified), or a value bigger than the normal maximum
|
||||
* value, into the maximum allowed value.
|
||||
*
|
||||
* If some application really *needs* a bigger snapshot
|
||||
* length, we should just increase MAXIMUM_SNAPLEN.
|
||||
*/
|
||||
if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
|
||||
handle->snapshot = MAXIMUM_SNAPLEN;
|
||||
|
||||
handlep->device = strdup(device);
|
||||
if (handlep->device == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "strdup");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
handle->bufsize = 65536;
|
||||
// TODO: should be determined by interface MTU
|
||||
|
||||
// allocate buffer for monitoring the device
|
||||
handle->buffer = (u_char*)malloc(handle->bufsize);
|
||||
if (handle->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "buffer malloc");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
handle->offset = 0;
|
||||
handle->linktype = DLT_EN10MB;
|
||||
// TODO: check interface type!
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - pcap API
|
||||
|
||||
|
||||
extern "C" pcap_t *
|
||||
pcap_create_interface(const char *device, char *errorBuffer)
|
||||
{
|
||||
// TODO: handle promiscuous mode!
|
||||
|
||||
// we need a socket to talk to the networking stack
|
||||
int socket = ::socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (socket < 0) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE,
|
||||
"The networking stack doesn't seem to be available.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ifreq request;
|
||||
if (!prepare_request(request, device)) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE,
|
||||
"Interface name \"%s\" is too long.", device);
|
||||
close(socket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// check if the interface exist
|
||||
if (ioctl(socket, SIOCGIFINDEX, &request, sizeof(request)) < 0) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE,
|
||||
"Interface \"%s\" does not exist.\n", device);
|
||||
close(socket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
close(socket);
|
||||
// no longer needed after this point
|
||||
|
||||
// get link level interface for this interface
|
||||
|
||||
socket = ::socket(AF_LINK, SOCK_DGRAM, 0);
|
||||
if (socket < 0) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE, "No link level: %s\n",
|
||||
strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// start monitoring
|
||||
if (ioctl(socket, SIOCSPACKETCAP, &request, sizeof(struct ifreq)) < 0) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE, "Cannot start monitoring: %s\n",
|
||||
strerror(errno));
|
||||
close(socket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wrapper_struct { pcap_t __common; struct pcap_haiku __private; };
|
||||
pcap_t* handle = pcap_create_common(errorBuffer,
|
||||
sizeof (struct wrapper_struct),
|
||||
offsetof (struct wrapper_struct, __private));
|
||||
|
||||
if (handle == NULL) {
|
||||
snprintf(errorBuffer, PCAP_ERRBUF_SIZE, "malloc: %s", strerror(errno));
|
||||
close(socket);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->selectable_fd = socket;
|
||||
handle->fd = socket;
|
||||
|
||||
handle->activate_op = pcap_activate_haiku;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
static int
|
||||
can_be_bound(const char *name _U_)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
|
||||
{
|
||||
/* TODO */
|
||||
if (*flags & PCAP_IF_LOOPBACK) {
|
||||
/*
|
||||
* Loopback devices aren't wireless, and "connected"/
|
||||
* "disconnected" doesn't apply to them.
|
||||
*/
|
||||
*flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE;
|
||||
return (0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
pcap_platform_finddevs(pcap_if_list_t* _allDevices, char* errorBuffer)
|
||||
{
|
||||
return pcap_findalldevs_interfaces(_allDevices, errorBuffer, can_be_bound,
|
||||
get_if_flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* Libpcap version string.
|
||||
*/
|
||||
extern "C" const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
return (PCAP_VERSION_STRING);
|
||||
}
|
@ -52,6 +52,8 @@
|
||||
|
||||
#include "portability.h"
|
||||
|
||||
#define PCAP_DEBUG {printf(" [%s:%d %s] ", __FILE__, __LINE__, __func__); fflush(stdout);}
|
||||
|
||||
/*
|
||||
* If we're compiling with Visual Studio, make sure we have at least
|
||||
* VS 2015 or later, so we have sufficient C99 support.
|
||||
@ -81,7 +83,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If pcap_new_api is set, we disable pcap_lookupdev(), because:
|
||||
* If pcapint_new_api is set, we disable pcap_lookupdev(), because:
|
||||
*
|
||||
* it's not thread-safe, and is marked as deprecated, on all
|
||||
* platforms;
|
||||
@ -97,15 +99,15 @@ extern "C" {
|
||||
*
|
||||
* We also disable the aforementioned hack in pcap_create().
|
||||
*/
|
||||
extern int pcap_new_api;
|
||||
extern int pcapint_new_api;
|
||||
|
||||
/*
|
||||
* If pcap_utf_8_mode is set, on Windows we treat strings as UTF-8.
|
||||
* If pcapint_utf_8_mode is set, on Windows we treat strings as UTF-8.
|
||||
*
|
||||
* On UN*Xes, we assume all strings are and should be in UTF-8, regardless
|
||||
* of the setting of this flag.
|
||||
*/
|
||||
extern int pcap_utf_8_mode;
|
||||
extern int pcapint_utf_8_mode;
|
||||
|
||||
/*
|
||||
* Swap byte ordering of unsigned long long timestamp on a big endian
|
||||
@ -369,76 +371,6 @@ struct pcap {
|
||||
*/
|
||||
#define BPF_SPECIAL_VLAN_HANDLING 0x00000001 /* special VLAN handling for Linux */
|
||||
|
||||
/*
|
||||
* This is a timeval as stored in a savefile.
|
||||
* It has to use the same types everywhere, independent of the actual
|
||||
* `struct timeval'; `struct timeval' has 32-bit tv_sec values on some
|
||||
* platforms and 64-bit tv_sec values on other platforms, and writing
|
||||
* out native `struct timeval' values would mean files could only be
|
||||
* read on systems with the same tv_sec size as the system on which
|
||||
* the file was written.
|
||||
*/
|
||||
|
||||
struct pcap_timeval {
|
||||
bpf_int32 tv_sec; /* seconds */
|
||||
bpf_int32 tv_usec; /* microseconds */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is a `pcap_pkthdr' as actually stored in a savefile.
|
||||
*
|
||||
* Do not change the format of this structure, in any way (this includes
|
||||
* changes that only affect the length of fields in this structure),
|
||||
* and do not make the time stamp anything other than seconds and
|
||||
* microseconds (e.g., seconds and nanoseconds). Instead:
|
||||
*
|
||||
* introduce a new structure for the new format;
|
||||
*
|
||||
* send mail to "tcpdump-workers@lists.tcpdump.org", requesting
|
||||
* a new magic number for your new capture file format, and, when
|
||||
* you get the new magic number, put it in "savefile.c";
|
||||
*
|
||||
* use that magic number for save files with the changed record
|
||||
* header;
|
||||
*
|
||||
* make the code in "savefile.c" capable of reading files with
|
||||
* the old record header as well as files with the new record header
|
||||
* (using the magic number to determine the header format).
|
||||
*
|
||||
* Then supply the changes by forking the branch at
|
||||
*
|
||||
* https://github.com/the-tcpdump-group/libpcap/tree/master
|
||||
*
|
||||
* and issuing a pull request, so that future versions of libpcap and
|
||||
* programs that use it (such as tcpdump) will be able to read your new
|
||||
* capture file format.
|
||||
*/
|
||||
|
||||
struct pcap_sf_pkthdr {
|
||||
struct pcap_timeval ts; /* time stamp */
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length of this packet (off wire) */
|
||||
};
|
||||
|
||||
/*
|
||||
* How a `pcap_pkthdr' is actually stored in savefiles written
|
||||
* by some patched versions of libpcap (e.g. the ones in Red
|
||||
* Hat Linux 6.1 and 6.2).
|
||||
*
|
||||
* Do not change the format of this structure, in any way (this includes
|
||||
* changes that only affect the length of fields in this structure).
|
||||
* Instead, introduce a new structure, as per the above.
|
||||
*/
|
||||
|
||||
struct pcap_sf_patched_pkthdr {
|
||||
struct pcap_timeval ts; /* time stamp */
|
||||
bpf_u_int32 caplen; /* length of portion present */
|
||||
bpf_u_int32 len; /* length of this packet (off wire) */
|
||||
int index;
|
||||
unsigned short protocol;
|
||||
unsigned char pkt_type;
|
||||
};
|
||||
|
||||
/*
|
||||
* User data structure for the one-shot callback used for pcap_next()
|
||||
* and pcap_next_ex().
|
||||
@ -453,7 +385,7 @@ struct oneshot_userdata {
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
||||
int pcapint_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
||||
|
||||
/*
|
||||
* Does the packet count argument to a module's read routine say
|
||||
@ -465,41 +397,41 @@ int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
|
||||
* Routines that most pcap implementations can use for non-blocking mode.
|
||||
*/
|
||||
#if !defined(_WIN32) && !defined(MSDOS)
|
||||
int pcap_getnonblock_fd(pcap_t *);
|
||||
int pcap_setnonblock_fd(pcap_t *p, int);
|
||||
int pcapint_getnonblock_fd(pcap_t *);
|
||||
int pcapint_setnonblock_fd(pcap_t *p, int);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Internal interfaces for "pcap_create()".
|
||||
*
|
||||
* "pcap_create_interface()" is the routine to do a pcap_create on
|
||||
* "pcapint_create_interface()" is the routine to do a pcap_create on
|
||||
* a regular network interface. There are multiple implementations
|
||||
* of this, one for each platform type (Linux, BPF, DLPI, etc.),
|
||||
* with the one used chosen by the configure script.
|
||||
*
|
||||
* "pcap_create_common()" allocates and fills in a pcap_t, for use
|
||||
* "pcapint_create_common()" allocates and fills in a pcap_t, for use
|
||||
* by pcap_create routines.
|
||||
*/
|
||||
pcap_t *pcap_create_interface(const char *, char *);
|
||||
pcap_t *pcapint_create_interface(const char *, char *);
|
||||
|
||||
/*
|
||||
* This wrapper takes an error buffer pointer and a type to use for the
|
||||
* private data, and calls pcap_create_common(), passing it the error
|
||||
* private data, and calls pcapint_create_common(), passing it the error
|
||||
* buffer pointer, the size for the private data type, in bytes, and the
|
||||
* offset of the private data from the beginning of the structure, in
|
||||
* bytes.
|
||||
*/
|
||||
#define PCAP_CREATE_COMMON(ebuf, type) \
|
||||
pcap_create_common(ebuf, \
|
||||
pcapint_create_common(ebuf, \
|
||||
sizeof (struct { pcap_t __common; type __private; }), \
|
||||
offsetof (struct { pcap_t __common; type __private; }, __private))
|
||||
pcap_t *pcap_create_common(char *, size_t, size_t);
|
||||
int pcap_do_addexit(pcap_t *);
|
||||
void pcap_add_to_pcaps_to_close(pcap_t *);
|
||||
void pcap_remove_from_pcaps_to_close(pcap_t *);
|
||||
void pcap_cleanup_live_common(pcap_t *);
|
||||
int pcap_check_activated(pcap_t *);
|
||||
void pcap_breakloop_common(pcap_t *);
|
||||
pcap_t *pcapint_create_common(char *, size_t, size_t);
|
||||
int pcapint_do_addexit(pcap_t *);
|
||||
void pcapint_add_to_pcaps_to_close(pcap_t *);
|
||||
void pcapint_remove_from_pcaps_to_close(pcap_t *);
|
||||
void pcapint_cleanup_live_common(pcap_t *);
|
||||
int pcapint_check_activated(pcap_t *);
|
||||
void pcapint_breakloop_common(pcap_t *);
|
||||
|
||||
/*
|
||||
* Internal interfaces for "pcap_findalldevs()".
|
||||
@ -509,39 +441,42 @@ void pcap_breakloop_common(pcap_t *);
|
||||
* A get_if_flags_func is a platform-dependent function called to get
|
||||
* additional interface flags.
|
||||
*
|
||||
* "pcap_platform_finddevs()" is the platform-dependent routine to
|
||||
* "pcapint_platform_finddevs()" is the platform-dependent routine to
|
||||
* find local network interfaces.
|
||||
*
|
||||
* "pcap_findalldevs_interfaces()" is a helper to find those interfaces
|
||||
* "pcapint_findalldevs_interfaces()" is a helper to find those interfaces
|
||||
* using the "standard" mechanisms (SIOCGIFCONF, "getifaddrs()", etc.).
|
||||
*
|
||||
* "add_dev()" adds an entry to a pcap_if_list_t.
|
||||
* "pcapint_add_dev()" adds an entry to a pcap_if_list_t.
|
||||
*
|
||||
* "find_dev()" tries to find a device, by name, in a pcap_if_list_t.
|
||||
* "pcap_add_any_dev()" adds an entry for the "any" device to a pcap_if_list_t.
|
||||
*
|
||||
* "find_or_add_dev()" checks whether a device is already in a pcap_if_list_t
|
||||
* and, if not, adds an entry for it.
|
||||
* "pcapint_find_dev()" tries to find a device, by name, in a pcap_if_list_t.
|
||||
*
|
||||
* "pcapint_find_or_add_dev()" checks whether a device is already in a
|
||||
* pcap_if_list_t and, if not, adds an entry for it.
|
||||
*/
|
||||
struct pcap_if_list;
|
||||
typedef struct pcap_if_list pcap_if_list_t;
|
||||
typedef int (*get_if_flags_func)(const char *, bpf_u_int32 *, char *);
|
||||
int pcap_platform_finddevs(pcap_if_list_t *, char *);
|
||||
int pcapint_platform_finddevs(pcap_if_list_t *, char *);
|
||||
#if !defined(_WIN32) && !defined(MSDOS)
|
||||
int pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
|
||||
int pcapint_findalldevs_interfaces(pcap_if_list_t *, char *,
|
||||
int (*)(const char *), get_if_flags_func);
|
||||
#endif
|
||||
pcap_if_t *find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
|
||||
pcap_if_t *pcapint_find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
|
||||
get_if_flags_func, const char *, char *);
|
||||
pcap_if_t *find_dev(pcap_if_list_t *, const char *);
|
||||
pcap_if_t *add_dev(pcap_if_list_t *, const char *, bpf_u_int32, const char *,
|
||||
char *);
|
||||
int add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t,
|
||||
pcap_if_t *pcapint_find_dev(pcap_if_list_t *, const char *);
|
||||
pcap_if_t *pcapint_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
|
||||
const char *, char *);
|
||||
pcap_if_t *pcap_add_any_dev(pcap_if_list_t *, char *);
|
||||
int pcapint_add_addr_to_dev(pcap_if_t *, struct sockaddr *, size_t,
|
||||
struct sockaddr *, size_t, struct sockaddr *, size_t,
|
||||
struct sockaddr *dstaddr, size_t, char *errbuf);
|
||||
#ifndef _WIN32
|
||||
pcap_if_t *find_or_add_if(pcap_if_list_t *, const char *, bpf_u_int32,
|
||||
pcap_if_t *pcapint_find_or_add_if(pcap_if_list_t *, const char *, uint64_t,
|
||||
get_if_flags_func, char *);
|
||||
int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32,
|
||||
int pcapint_add_addr_to_if(pcap_if_list_t *, const char *, uint64_t,
|
||||
get_if_flags_func,
|
||||
struct sockaddr *, size_t, struct sockaddr *, size_t,
|
||||
struct sockaddr *, size_t, struct sockaddr *, size_t, char *);
|
||||
@ -551,43 +486,43 @@ int add_addr_to_if(pcap_if_list_t *, const char *, bpf_u_int32,
|
||||
* Internal interfaces for "pcap_open_offline()" and other savefile
|
||||
* I/O routines.
|
||||
*
|
||||
* "pcap_open_offline_common()" allocates and fills in a pcap_t, for use
|
||||
* "pcapint_open_offline_common()" allocates and fills in a pcap_t, for use
|
||||
* by pcap_open_offline routines.
|
||||
*
|
||||
* "pcap_adjust_snapshot()" adjusts the snapshot to be non-zero and
|
||||
* "pcapint_adjust_snapshot()" adjusts the snapshot to be non-zero and
|
||||
* fit within an int.
|
||||
*
|
||||
* "sf_cleanup()" closes the file handle associated with a pcap_t, if
|
||||
* "pcapint_sf_cleanup()" closes the file handle associated with a pcap_t, if
|
||||
* appropriate, and frees all data common to all modules for handling
|
||||
* savefile types.
|
||||
*
|
||||
* "charset_fopen()", in UTF-8 mode on Windows, does an fopen() that
|
||||
* "pcapint_charset_fopen()", in UTF-8 mode on Windows, does an fopen() that
|
||||
* treats the pathname as being in UTF-8, rather than the local
|
||||
* code page, on Windows.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This wrapper takes an error buffer pointer and a type to use for the
|
||||
* private data, and calls pcap_create_common(), passing it the error
|
||||
* private data, and calls pcapint_create_common(), passing it the error
|
||||
* buffer pointer, the size for the private data type, in bytes, and the
|
||||
* offset of the private data from the beginning of the structure, in
|
||||
* bytes.
|
||||
*/
|
||||
#define PCAP_OPEN_OFFLINE_COMMON(ebuf, type) \
|
||||
pcap_open_offline_common(ebuf, \
|
||||
pcapint_open_offline_common(ebuf, \
|
||||
sizeof (struct { pcap_t __common; type __private; }), \
|
||||
offsetof (struct { pcap_t __common; type __private; }, __private))
|
||||
pcap_t *pcap_open_offline_common(char *ebuf, size_t total_size,
|
||||
pcap_t *pcapint_open_offline_common(char *ebuf, size_t total_size,
|
||||
size_t private_data);
|
||||
bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen);
|
||||
void sf_cleanup(pcap_t *p);
|
||||
bpf_u_int32 pcapint_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen);
|
||||
void pcapint_sf_cleanup(pcap_t *p);
|
||||
#ifdef _WIN32
|
||||
FILE *charset_fopen(const char *path, const char *mode);
|
||||
FILE *pcapint_charset_fopen(const char *path, const char *mode);
|
||||
#else
|
||||
/*
|
||||
* On other OSes, just use Boring Old fopen().
|
||||
*/
|
||||
#define charset_fopen(path, mode) fopen((path), (mode))
|
||||
#define pcapint_charset_fopen(path, mode) fopen((path), (mode))
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -597,8 +532,8 @@ FILE *charset_fopen(const char *path, const char *mode);
|
||||
#define pcap_code_handle_t HMODULE
|
||||
#define pcap_funcptr_t FARPROC
|
||||
|
||||
pcap_code_handle_t pcap_load_code(const char *);
|
||||
pcap_funcptr_t pcap_find_function(pcap_code_handle_t, const char *);
|
||||
pcap_code_handle_t pcapint_load_code(const char *);
|
||||
pcap_funcptr_t pcapint_find_function(pcap_code_handle_t, const char *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -619,40 +554,40 @@ struct pcap_bpf_aux_data {
|
||||
* Filtering routine that takes the auxiliary data as an additional
|
||||
* argument.
|
||||
*/
|
||||
u_int pcap_filter_with_aux_data(const struct bpf_insn *,
|
||||
u_int pcapint_filter_with_aux_data(const struct bpf_insn *,
|
||||
const u_char *, u_int, u_int, const struct pcap_bpf_aux_data *);
|
||||
|
||||
/*
|
||||
* Filtering routine that doesn't.
|
||||
*/
|
||||
u_int pcap_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
|
||||
u_int pcapint_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
|
||||
|
||||
/*
|
||||
* Routine to validate a BPF program.
|
||||
*/
|
||||
int pcap_validate_filter(const struct bpf_insn *, int);
|
||||
int pcapint_validate_filter(const struct bpf_insn *, int);
|
||||
|
||||
/*
|
||||
* Internal interfaces for both "pcap_create()" and routines that
|
||||
* open savefiles.
|
||||
*
|
||||
* "pcap_oneshot()" is the standard one-shot callback for "pcap_next()"
|
||||
* "pcapint_oneshot()" is the standard one-shot callback for "pcap_next()"
|
||||
* and "pcap_next_ex()".
|
||||
*/
|
||||
void pcap_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||
void pcapint_oneshot(u_char *, const struct pcap_pkthdr *, const u_char *);
|
||||
|
||||
int install_bpf_program(pcap_t *, struct bpf_program *);
|
||||
int pcapint_install_bpf_program(pcap_t *, struct bpf_program *);
|
||||
|
||||
int pcap_strcasecmp(const char *, const char *);
|
||||
int pcapint_strcasecmp(const char *, const char *);
|
||||
|
||||
/*
|
||||
* Internal interfaces for pcap_createsrcstr and pcap_parsesrcstr with
|
||||
* the additional bit of information regarding SSL support (rpcap:// vs.
|
||||
* rpcaps://).
|
||||
*/
|
||||
int pcap_createsrcstr_ex(char *, int, const char *, const char *,
|
||||
int pcapint_createsrcstr_ex(char *, int, const char *, const char *,
|
||||
const char *, unsigned char, char *);
|
||||
int pcap_parsesrcstr_ex(const char *, int *, char *, char *,
|
||||
int pcapint_parsesrcstr_ex(const char *, int *, char *, char *,
|
||||
char *, unsigned char *, char *);
|
||||
|
||||
#ifdef YYDEBUG
|
||||
|
@ -24,9 +24,7 @@
|
||||
* Packet capture routines for DLPI using libdlpi under SunOS 5.11.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@ -80,7 +78,7 @@ list_interfaces(const char *linkname, void *arg)
|
||||
lwp->lw_err = ENOMEM;
|
||||
return (B_TRUE);
|
||||
}
|
||||
(void) pcap_strlcpy(entry->linkname, linkname, DLPI_LINKNAME_MAX);
|
||||
(void) pcapint_strlcpy(entry->linkname, linkname, DLPI_LINKNAME_MAX);
|
||||
|
||||
if (lwp->lw_list == NULL) {
|
||||
lwp->lw_list = entry;
|
||||
@ -229,7 +227,7 @@ pcap_activate_libdlpi(pcap_t *p)
|
||||
*/
|
||||
if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
|
||||
status = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "FLUSHR");
|
||||
goto bad;
|
||||
}
|
||||
@ -248,11 +246,11 @@ pcap_activate_libdlpi(pcap_t *p)
|
||||
|
||||
p->read_op = pcap_read_libdlpi;
|
||||
p->inject_op = pcap_inject_libdlpi;
|
||||
p->setfilter_op = install_bpf_program; /* No kernel filtering */
|
||||
p->setfilter_op = pcapint_install_bpf_program; /* No kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented */
|
||||
p->set_datalink_op = NULL; /* Can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_dlpi;
|
||||
p->cleanup_op = pcap_cleanup_libdlpi;
|
||||
|
||||
@ -338,7 +336,7 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
|
||||
* additional network links present in the system.
|
||||
*/
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
int retv = 0;
|
||||
|
||||
@ -349,7 +347,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
/*
|
||||
* Get the list of regular interfaces first.
|
||||
*/
|
||||
if (pcap_findalldevs_interfaces(devlistp, errbuf,
|
||||
if (pcapint_findalldevs_interfaces(devlistp, errbuf,
|
||||
is_dlpi_interface, get_if_flags) == -1)
|
||||
return (-1); /* failure */
|
||||
|
||||
@ -358,14 +356,14 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
/*
|
||||
* Find all DLPI devices in the current zone.
|
||||
*
|
||||
* XXX - will pcap_findalldevs_interfaces() find any devices
|
||||
* XXX - will pcapint_findalldevs_interfaces() find any devices
|
||||
* outside the current zone? If not, the only reason to call
|
||||
* it would be to get the interface addresses.
|
||||
*/
|
||||
dlpi_walk(list_interfaces, &lw, 0);
|
||||
|
||||
if (lw.lw_err != 0) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
lw.lw_err, "dlpi_walk");
|
||||
retv = -1;
|
||||
goto done;
|
||||
@ -377,7 +375,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* If it isn't already in the list of devices, try to
|
||||
* add it.
|
||||
*/
|
||||
if (find_or_add_dev(devlistp, entry->linkname, 0, get_if_flags,
|
||||
if (pcapint_find_or_add_dev(devlistp, entry->linkname, 0, get_if_flags,
|
||||
NULL, errbuf) == NULL)
|
||||
retv = -1;
|
||||
}
|
||||
@ -481,7 +479,7 @@ pcap_cleanup_libdlpi(pcap_t *p)
|
||||
pd->dlpi_hd = NULL;
|
||||
p->fd = -1;
|
||||
}
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -495,7 +493,7 @@ pcap_libdlpi_err(const char *linkname, const char *func, int err, char *errbuf)
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -28,9 +28,7 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
#include "diag-control.h"
|
||||
@ -61,7 +59,7 @@
|
||||
* It took me quite some time to debug ;/
|
||||
*
|
||||
* Sending any data to nfnetlink socket requires CAP_NET_ADMIN privileges,
|
||||
* and in nfqueue we need to send verdict reply after recving packet.
|
||||
* and in nfqueue we need to send verdict reply after receiving packet.
|
||||
*
|
||||
* In tcpdump you can disable dropping privileges with -Z root
|
||||
*/
|
||||
@ -123,12 +121,12 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
|
||||
handle->break_loop = 0;
|
||||
return PCAP_ERROR_BREAK;
|
||||
}
|
||||
if (errno == ENOBUFS)
|
||||
if (len == -1 && errno == ENOBUFS)
|
||||
handlep->packets_nobufs++;
|
||||
} while ((len == -1) && (errno == EINTR || errno == ENOBUFS));
|
||||
|
||||
if (len < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "Can't receive packet");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
@ -259,7 +257,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
|
||||
|
||||
gettimeofday(&pkth.ts, NULL);
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
|
||||
pcapint_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
|
||||
{
|
||||
handlep->packets_read++;
|
||||
callback(user, &pkth, payload);
|
||||
@ -595,17 +593,17 @@ netfilter_activate(pcap_t* handle)
|
||||
handle->offset = 0;
|
||||
handle->read_op = netfilter_read_linux;
|
||||
handle->inject_op = netfilter_inject_linux;
|
||||
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
handle->setdirection_op = NULL;
|
||||
handle->set_datalink_op = netfilter_set_datalink;
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
handle->stats_op = netfilter_stats_linux;
|
||||
|
||||
/* Create netlink socket */
|
||||
handle->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER);
|
||||
if (handle->fd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't create raw socket");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
@ -613,32 +611,35 @@ netfilter_activate(pcap_t* handle)
|
||||
if (type == NFLOG) {
|
||||
handle->linktype = DLT_NFLOG;
|
||||
handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
if (handle->dlt_list != NULL) {
|
||||
handle->dlt_list[0] = DLT_NFLOG;
|
||||
handle->dlt_list[1] = DLT_IPV4;
|
||||
handle->dlt_count = 2;
|
||||
if (handle->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"Can't allocate DLT list");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
handle->dlt_list[0] = DLT_NFLOG;
|
||||
handle->dlt_list[1] = DLT_IPV4;
|
||||
handle->dlt_count = 2;
|
||||
} else
|
||||
handle->linktype = DLT_IPV4;
|
||||
|
||||
handle->buffer = malloc(handle->bufsize);
|
||||
if (!handle->buffer) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't allocate dump buffer");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
if (type == NFLOG) {
|
||||
if (nflog_send_config_cmd(handle, 0, NFULNL_CFG_CMD_PF_UNBIND, AF_INET) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"NFULNL_CFG_CMD_PF_UNBIND");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
if (nflog_send_config_cmd(handle, 0, NFULNL_CFG_CMD_PF_BIND, AF_INET) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "NFULNL_CFG_CMD_PF_BIND");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -646,14 +647,14 @@ netfilter_activate(pcap_t* handle)
|
||||
/* Bind socket to the nflog groups */
|
||||
for (i = 0; i < group_count; i++) {
|
||||
if (nflog_send_config_cmd(handle, groups[i], NFULNL_CFG_CMD_BIND, AF_UNSPEC) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"Can't listen on group index");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
if (nflog_send_config_mode(handle, groups[i], NFULNL_COPY_PACKET, handle->snapshot) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"NFULNL_COPY_PACKET");
|
||||
goto close_fail;
|
||||
@ -662,13 +663,13 @@ netfilter_activate(pcap_t* handle)
|
||||
|
||||
} else {
|
||||
if (nfqueue_send_config_cmd(handle, 0, NFQNL_CFG_CMD_PF_UNBIND, AF_INET) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "NFQNL_CFG_CMD_PF_UNBIND");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
if (nfqueue_send_config_cmd(handle, 0, NFQNL_CFG_CMD_PF_BIND, AF_INET) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "NFQNL_CFG_CMD_PF_BIND");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -676,14 +677,14 @@ netfilter_activate(pcap_t* handle)
|
||||
/* Bind socket to the nfqueue groups */
|
||||
for (i = 0; i < group_count; i++) {
|
||||
if (nfqueue_send_config_cmd(handle, groups[i], NFQNL_CFG_CMD_BIND, AF_UNSPEC) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"Can't listen on group index");
|
||||
goto close_fail;
|
||||
}
|
||||
|
||||
if (nfqueue_send_config_mode(handle, groups[i], NFQNL_COPY_PACKET, handle->snapshot) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"NFQNL_COPY_PACKET");
|
||||
goto close_fail;
|
||||
@ -695,7 +696,7 @@ netfilter_activate(pcap_t* handle)
|
||||
/*
|
||||
* Monitor mode doesn't apply to netfilter devices.
|
||||
*/
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
return PCAP_ERROR_RFMON_NOTSUP;
|
||||
}
|
||||
|
||||
@ -704,7 +705,7 @@ netfilter_activate(pcap_t* handle)
|
||||
* Set the socket buffer size to the specified value.
|
||||
*/
|
||||
if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF, &handle->opt.buffer_size, sizeof(handle->opt.buffer_size)) == -1) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "SO_RCVBUF");
|
||||
goto close_fail;
|
||||
}
|
||||
@ -714,7 +715,7 @@ netfilter_activate(pcap_t* handle)
|
||||
return 0;
|
||||
|
||||
close_fail:
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
|
||||
@ -771,7 +772,7 @@ netfilter_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
/* if netlink is not supported this is not fatal */
|
||||
if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)
|
||||
return 0;
|
||||
pcap_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(err_str, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't open netlink socket");
|
||||
return -1;
|
||||
}
|
||||
@ -781,11 +782,11 @@ netfilter_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
* The notion of "connected" vs. "disconnected" doesn't apply.
|
||||
* XXX - what about "up" and "running"?
|
||||
*/
|
||||
if (add_dev(devlistp, NFLOG_IFACE,
|
||||
if (pcapint_add_dev(devlistp, NFLOG_IFACE,
|
||||
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
|
||||
"Linux netfilter log (NFLOG) interface", err_str) == NULL)
|
||||
return -1;
|
||||
if (add_dev(devlistp, NFQUEUE_IFACE,
|
||||
if (pcapint_add_dev(devlistp, NFQUEUE_IFACE,
|
||||
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
|
||||
"Linux netfilter queue (NFQUEUE) interface", err_str) == NULL)
|
||||
return -1;
|
||||
|
@ -24,9 +24,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
@ -81,7 +79,7 @@ pcap_netmap_filter(u_char *arg, struct pcap_pkthdr *h, const u_char *buf)
|
||||
const struct bpf_insn *pc = p->fcode.bf_insns;
|
||||
|
||||
++pn->rx_pkts;
|
||||
if (pc == NULL || pcap_filter(pc, buf, h->len, h->caplen))
|
||||
if (pc == NULL || pcapint_filter(pc, buf, h->len, h->caplen))
|
||||
pn->cb(pn->cb_arg, h, buf);
|
||||
}
|
||||
|
||||
@ -133,13 +131,13 @@ pcap_netmap_ioctl(pcap_t *p, u_long what, uint32_t *if_flags)
|
||||
struct ifreq ifr;
|
||||
int error, fd = d->fd;
|
||||
|
||||
#ifdef linux
|
||||
#ifdef __linux__
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error: cannot get device control socket.\n");
|
||||
return -1;
|
||||
}
|
||||
#endif /* linux */
|
||||
#endif /* __linux__ */
|
||||
bzero(&ifr, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, d->req.nr_name, sizeof(ifr.ifr_name));
|
||||
switch (what) {
|
||||
@ -194,9 +192,9 @@ pcap_netmap_ioctl(pcap_t *p, u_long what, uint32_t *if_flags)
|
||||
#endif /* __FreeBSD__ */
|
||||
}
|
||||
}
|
||||
#ifdef linux
|
||||
#ifdef __linux__
|
||||
close(fd);
|
||||
#endif /* linux */
|
||||
#endif /* __linux__ */
|
||||
return error ? -1 : 0;
|
||||
}
|
||||
|
||||
@ -216,7 +214,7 @@ pcap_netmap_close(pcap_t *p)
|
||||
}
|
||||
}
|
||||
nm_close(d);
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
|
||||
@ -229,10 +227,10 @@ pcap_netmap_activate(pcap_t *p)
|
||||
|
||||
d = nm_open(p->opt.device, NULL, 0, NULL);
|
||||
if (d == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "netmap open: cannot access %s",
|
||||
p->opt.device);
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
#if 0
|
||||
@ -266,11 +264,11 @@ pcap_netmap_activate(pcap_t *p)
|
||||
p->selectable_fd = p->fd;
|
||||
p->read_op = pcap_netmap_dispatch;
|
||||
p->inject_op = pcap_netmap_inject;
|
||||
p->setfilter_op = install_bpf_program;
|
||||
p->setfilter_op = pcapint_install_bpf_program;
|
||||
p->setdirection_op = NULL;
|
||||
p->set_datalink_op = NULL;
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_netmap_stats;
|
||||
p->cleanup_op = pcap_netmap_close;
|
||||
|
||||
|
@ -31,9 +31,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ftmacros.h"
|
||||
#include "diag-control.h"
|
||||
@ -144,7 +142,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
dev->name = strdup(tmpstring);
|
||||
if (dev->name == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc() failed");
|
||||
pcap_freealldevs(*alldevs);
|
||||
@ -158,11 +156,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
localdesc = dev->name;
|
||||
else
|
||||
localdesc = dev->description;
|
||||
if (pcap_asprintf(&desc, "%s '%s' %s",
|
||||
if (pcapint_asprintf(&desc, "%s '%s' %s",
|
||||
PCAP_TEXT_SOURCE_ADAPTER, localdesc,
|
||||
PCAP_TEXT_SOURCE_ON_LOCAL_HOST) == -1)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc() failed");
|
||||
pcap_freealldevs(*alldevs);
|
||||
@ -232,14 +230,23 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
#else
|
||||
/* opening the folder */
|
||||
unixdir= opendir(path);
|
||||
if (unixdir == NULL) {
|
||||
DIAG_OFF_FORMAT_TRUNCATION
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Error when listing files in '%s': %s", path, pcap_strerror(errno));
|
||||
DIAG_ON_FORMAT_TRUNCATION
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get the first file into it */
|
||||
errno = 0;
|
||||
filedata= readdir(unixdir);
|
||||
|
||||
if (filedata == NULL)
|
||||
{
|
||||
DIAG_OFF_FORMAT_TRUNCATION
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path);
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Error when listing files in '%s': %s", path, pcap_strerror(errno));
|
||||
DIAG_ON_FORMAT_TRUNCATION
|
||||
closedir(unixdir);
|
||||
return -1;
|
||||
@ -270,7 +277,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
dev = (pcap_if_t *)malloc(sizeof(pcap_if_t));
|
||||
if (dev == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc() failed");
|
||||
pcap_freealldevs(*alldevs);
|
||||
@ -319,7 +326,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
dev->name = strdup(tmpstring);
|
||||
if (dev->name == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc() failed");
|
||||
pcap_freealldevs(*alldevs);
|
||||
@ -334,11 +341,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
/*
|
||||
* Create the description.
|
||||
*/
|
||||
if (pcap_asprintf(&dev->description,
|
||||
if (pcapint_asprintf(&dev->description,
|
||||
"%s '%s' %s", PCAP_TEXT_SOURCE_FILE,
|
||||
filename, PCAP_TEXT_SOURCE_ON_LOCAL_HOST) == -1)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc() failed");
|
||||
pcap_freealldevs(*alldevs);
|
||||
@ -374,7 +381,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t
|
||||
return pcap_findalldevs_ex_remote(source, auth, alldevs, errbuf);
|
||||
|
||||
default:
|
||||
pcap_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE);
|
||||
pcapint_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -428,7 +435,7 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout,
|
||||
return pcap_open_rpcap(source, snaplen, flags, read_timeout, auth, errbuf);
|
||||
|
||||
default:
|
||||
pcap_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE);
|
||||
pcapint_strlcpy(errbuf, "Source type not supported", PCAP_ERRBUF_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@ -113,7 +111,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
if (cc < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
return (0);
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "pcap_read");
|
||||
return (-1);
|
||||
}
|
||||
@ -181,7 +179,7 @@ pcap_read_nit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
caplen = nh->nh_wirelen;
|
||||
if (caplen > p->snapshot)
|
||||
caplen = p->snapshot;
|
||||
if (pcap_filter(p->fcode.bf_insns, cp, nh->nh_wirelen, caplen)) {
|
||||
if (pcapint_filter(p->fcode.bf_insns, cp, nh->nh_wirelen, caplen)) {
|
||||
struct pcap_pkthdr h;
|
||||
h.ts = nh->nh_timestamp;
|
||||
h.len = nh->nh_wirelen;
|
||||
@ -208,7 +206,7 @@ pcap_inject_nit(pcap_t *p, const void *buf, int size)
|
||||
strncpy(sa.sa_data, device, sizeof(sa.sa_data));
|
||||
ret = sendto(p->fd, buf, size, 0, &sa, sizeof(sa));
|
||||
if (ret == -1) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send");
|
||||
return (-1);
|
||||
}
|
||||
@ -251,7 +249,7 @@ nit_setflags(pcap_t *p)
|
||||
nioc.nioc_flags |= NF_PROMISC;
|
||||
|
||||
if (ioctl(p->fd, SIOCSNIT, &nioc) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCSNIT");
|
||||
return (-1);
|
||||
}
|
||||
@ -293,7 +291,7 @@ pcap_activate_nit(pcap_t *p)
|
||||
memset(p, 0, sizeof(*p));
|
||||
p->fd = fd = socket(AF_NIT, SOCK_RAW, NITPROTO_RAW);
|
||||
if (fd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "socket");
|
||||
goto bad;
|
||||
}
|
||||
@ -308,7 +306,7 @@ pcap_activate_nit(pcap_t *p)
|
||||
* they might be the same error, if they both end up
|
||||
* meaning "NIT doesn't know about that device".
|
||||
*/
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "bind: %s", snit.snit_ifname);
|
||||
goto bad;
|
||||
}
|
||||
@ -323,7 +321,7 @@ pcap_activate_nit(pcap_t *p)
|
||||
p->bufsize = BUFSPACE;
|
||||
p->buffer = malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
@ -344,32 +342,32 @@ pcap_activate_nit(pcap_t *p)
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
|
||||
p->read_op = pcap_read_nit;
|
||||
p->inject_op = pcap_inject_nit;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_nit;
|
||||
|
||||
return (0);
|
||||
bad:
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
@ -403,9 +401,9 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
return (pcapint_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
get_if_flags));
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h> /* for INT_MAX */
|
||||
@ -143,14 +141,56 @@ PacketGetMonitorMode(PCHAR AdapterName _U_)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sigh. PacketRequest() will have made a DeviceIoControl()
|
||||
* call to the NPF driver to perform the OID request, with a
|
||||
* BIOCQUERYOID ioctl. The kernel code should get back one
|
||||
* of NDIS_STATUS_INVALID_OID, NDIS_STATUS_NOT_SUPPORTED,
|
||||
* or NDIS_STATUS_NOT_RECOGNIZED if the OID request isn't
|
||||
* supported by the OS or the driver, but that doesn't seem
|
||||
* to make it to the caller of PacketRequest() in a
|
||||
* reliable fashion.
|
||||
* If a driver returns an NTSTATUS value:
|
||||
*
|
||||
* https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781
|
||||
*
|
||||
* with the "Customer" bit set, it will not be mapped to a Windows error
|
||||
* value in userland, so it will be returned by GetLastError().
|
||||
*
|
||||
* Note that "driver" here includes the Npcap NPF driver, as various
|
||||
* versions would take NT status values and set the "Customer" bit
|
||||
* before returning the status code. The commit message for the
|
||||
* change that started doing that is
|
||||
*
|
||||
* Returned a customer-defined NTSTATUS in OID requests to avoid
|
||||
* NTSTATUS-to-Win32 Error code translation.
|
||||
*
|
||||
* but I don't know why the goal was to avoid that translation. For
|
||||
* a while, I suspected that the NT status STATUS_NOT_SUPPORTED was
|
||||
* getting mapped to ERROR_GEN_FAILURE, but, in the cases where
|
||||
* attempts to set promiscuous mode on regular Ethernet devices were
|
||||
* failing with ERROR_GEN_FAILURE, it turns out that the drivers for
|
||||
* those devices were NetAdapterCx drivers, and Microsoft's NetAdapterCx
|
||||
* mechanism wasn't providing the correct "bytes processed" value on
|
||||
* attempts to set OIDs, and the Npcap NPF driver was checking for
|
||||
* that and returning STATUS_UNSUCCESSFUL, which gets mapped to
|
||||
* ERROR_GEN_FAILURE, so perhaps there's no need to avoid that
|
||||
* translation.
|
||||
*
|
||||
* Attempting to set the hardware filter on a Microsoft Surface Pro's
|
||||
* Mobile Broadband Adapter returns an error that appears to be
|
||||
* NDIS_STATUS_NOT_SUPPORTED ORed with the "Customer" bit, so it's
|
||||
* probably indicating that it doesn't support that. It was probably
|
||||
* the NPF driver setting that bit.
|
||||
*/
|
||||
#define NT_STATUS_CUSTOMER_DEFINED 0x20000000
|
||||
|
||||
/*
|
||||
* PacketRequest() makes a DeviceIoControl() call to the NPF driver to
|
||||
* perform the OID request, with a BIOCQUERYOID ioctl. The kernel code
|
||||
* should get back one of NDIS_STATUS_INVALID_OID, NDIS_STATUS_NOT_SUPPORTED,
|
||||
* or NDIS_STATUS_NOT_RECOGNIZED if the OID request isn't supported by
|
||||
* the OS or the driver.
|
||||
*
|
||||
* Currently, that code may be returned by the Npcap NPF driver with the
|
||||
* NT_STATUS_CUSTOMER_DEFINED bit. That prevents the return status from
|
||||
* being mapped to a Windows error code; if the NPF driver were to stop
|
||||
* ORing in the NT_STATUS_CUSTOMER_DEFINED bit, it's not obvious how those
|
||||
* the NDIS_STATUS_ values that don't correspond to NTSTATUS values would
|
||||
* be translated to Windows error values (NDIS_STATUS_NOT_SUPPORTED is
|
||||
* the same as STATUS_NOT_SUPPORTED, which is an NTSTATUS value that is
|
||||
* mapped to ERROR_NOT_SUPPORTED).
|
||||
*/
|
||||
#define NDIS_STATUS_INVALID_OID 0xc0010017
|
||||
#define NDIS_STATUS_NOT_SUPPORTED 0xc00000bb /* STATUS_NOT_SUPPORTED */
|
||||
@ -182,7 +222,7 @@ oid_get_request(ADAPTER *adapter, bpf_u_int32 oid, void *data, size_t *lenp,
|
||||
oid_data_arg->Oid = oid;
|
||||
oid_data_arg->Length = (ULONG)(*lenp); /* XXX - check for ridiculously large value? */
|
||||
if (!PacketRequest(adapter, FALSE, oid_data_arg)) {
|
||||
pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Error calling PacketRequest");
|
||||
free(oid_data_arg);
|
||||
return (-1);
|
||||
@ -221,7 +261,7 @@ pcap_stats_npf(pcap_t *p, struct pcap_stat *ps)
|
||||
* to us.
|
||||
*/
|
||||
if (!PacketGetStats(pw->adapter, &bstats)) {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "PacketGetStats error");
|
||||
return (-1);
|
||||
}
|
||||
@ -278,7 +318,7 @@ pcap_stats_ex_npf(pcap_t *p, int *pcap_stat_size)
|
||||
* same layout, but let's not cheat.)
|
||||
*/
|
||||
if (!PacketGetStatsEx(pw->adapter, &bstats)) {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "PacketGetStatsEx error");
|
||||
return (NULL);
|
||||
}
|
||||
@ -380,7 +420,7 @@ pcap_oid_set_request_npf(pcap_t *p, bpf_u_int32 oid, const void *data,
|
||||
oid_data_arg->Length = (ULONG)(*lenp); /* XXX - check for ridiculously large value? */
|
||||
memcpy(oid_data_arg->Data, data, *lenp);
|
||||
if (!PacketRequest(pw->adapter, TRUE, oid_data_arg)) {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Error calling PacketRequest");
|
||||
free(oid_data_arg);
|
||||
return (PCAP_ERROR);
|
||||
@ -410,7 +450,7 @@ pcap_sendqueue_transmit_npf(pcap_t *p, pcap_send_queue *queue, int sync)
|
||||
(BOOLEAN)sync);
|
||||
|
||||
if(res != queue->len){
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Error queueing packets");
|
||||
}
|
||||
|
||||
@ -618,7 +658,7 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
"The interface disappeared (error code %s)",
|
||||
errcode_msg);
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errcode,
|
||||
"PacketReceivePacket error");
|
||||
}
|
||||
@ -676,13 +716,13 @@ pcap_read_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
* in kernel, no need to do it now - we already know
|
||||
* the packet passed the filter.
|
||||
*
|
||||
* XXX - pcap_filter() should always return TRUE if
|
||||
* XXX - pcapint_filter() should always return TRUE if
|
||||
* handed a null pointer for the program, but it might
|
||||
* just try to "run" the filter, so we check here.
|
||||
*/
|
||||
if (pw->filtering_in_kernel ||
|
||||
p->fcode.bf_insns == NULL ||
|
||||
pcap_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
|
||||
pcapint_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) {
|
||||
#ifdef ENABLE_REMOTE
|
||||
switch (p->rmt_samp.method) {
|
||||
|
||||
@ -904,7 +944,7 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
/* No underlying filtering system. We need to filter on our own */
|
||||
if (p->fcode.bf_insns)
|
||||
{
|
||||
if (pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
|
||||
if (pcapint_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
|
||||
{
|
||||
/* Move to next packet */
|
||||
header = (dag_record_t*)((char*)header + erf_record_len);
|
||||
@ -945,7 +985,7 @@ pcap_inject_npf(pcap_t *p, const void *buf, int size)
|
||||
|
||||
PacketInitPacket(&pkt, (PVOID)buf, size);
|
||||
if(PacketSendPacket(pw->adapter,&pkt,TRUE) == FALSE) {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "send error: PacketSendPacket failed");
|
||||
return (-1);
|
||||
}
|
||||
@ -971,51 +1011,19 @@ pcap_cleanup_npf(pcap_t *p)
|
||||
{
|
||||
PacketSetMonitorMode(p->opt.device, 0);
|
||||
}
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
static void
|
||||
pcap_breakloop_npf(pcap_t *p)
|
||||
{
|
||||
pcap_breakloop_common(p);
|
||||
pcapint_breakloop_common(p);
|
||||
struct pcap_win *pw = p->priv;
|
||||
|
||||
/* XXX - what if this fails? */
|
||||
SetEvent(PacketGetReadEvent(pw->adapter));
|
||||
}
|
||||
|
||||
/*
|
||||
* These are NTSTATUS values:
|
||||
*
|
||||
* https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781
|
||||
*
|
||||
* with the "Customer" bit set. If a driver returns them, they are not
|
||||
* mapped to Windows error values in userland; they're returned by
|
||||
* GetLastError().
|
||||
*
|
||||
* Note that "driver" here includes the Npcap NPF driver, as various
|
||||
* versions would take NT status values and set the "Customer" bit
|
||||
* before returning the status code. The commit message for the
|
||||
* change that started doing that is
|
||||
*
|
||||
* Returned a customer-defined NTSTATUS in OID requests to avoid
|
||||
* NTSTATUS-to-Win32 Error code translation.
|
||||
*
|
||||
* but I don't know why the goal was to avoid that translation.
|
||||
*
|
||||
* Attempting to set the hardware filter on a Microsoft Surface Pro's
|
||||
* Mobile Broadband Adapter returns an error that appears to be
|
||||
* NDIS_STATUS_NOT_SUPPORTED ORed with the "Customer" bit, so it's
|
||||
* probably indicating that it doesn't support that.
|
||||
*
|
||||
* It is likely that there are other devices which throw spurious errors,
|
||||
* at which point this will need refactoring to efficiently check against
|
||||
* a list, but for now we can just check this one value. Perhaps the
|
||||
* right way to do this is compare against various NDIS errors with
|
||||
* the "customer" bit ORed in.
|
||||
*/
|
||||
#define NT_STATUS_CUSTOMER_DEFINED 0x20000000
|
||||
|
||||
static int
|
||||
pcap_activate_npf(pcap_t *p)
|
||||
{
|
||||
@ -1095,7 +1103,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
/*
|
||||
* Unknown - report details.
|
||||
*/
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errcode, "Error opening adapter");
|
||||
if (pw->rfmon_selfstart)
|
||||
{
|
||||
@ -1108,7 +1116,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
/*get network type*/
|
||||
if(PacketGetNetType (pw->adapter,&type) == FALSE)
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Cannot determine the network type");
|
||||
goto bad;
|
||||
}
|
||||
@ -1132,14 +1140,15 @@ pcap_activate_npf(pcap_t *p)
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL)
|
||||
{
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
break;
|
||||
|
||||
case NdisMedium802_5:
|
||||
@ -1243,7 +1252,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
*/
|
||||
if (!PacketSetTimestampMode(pw->adapter, TIMESTAMPMODE_SINGLE_SYNCHRONIZATION))
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Cannot set the time stamp mode to TIMESTAMPMODE_SINGLE_SYNCHRONIZATION");
|
||||
goto bad;
|
||||
}
|
||||
@ -1255,7 +1264,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
*/
|
||||
if (!PacketSetTimestampMode(pw->adapter, TIMESTAMPMODE_QUERYSYSTEMTIME))
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Cannot set the time stamp mode to TIMESTAMPMODE_QUERYSYSTEMTIME");
|
||||
goto bad;
|
||||
}
|
||||
@ -1267,7 +1276,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
*/
|
||||
if (!PacketSetTimestampMode(pw->adapter, TIMESTAMPMODE_QUERYSYSTEMTIME_PRECISE))
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "Cannot set the time stamp mode to TIMESTAMPMODE_QUERYSYSTEMTIME_PRECISE");
|
||||
goto bad;
|
||||
}
|
||||
@ -1297,13 +1306,18 @@ pcap_activate_npf(pcap_t *p)
|
||||
/* Set promiscuous mode */
|
||||
if (p->opt.promisc)
|
||||
{
|
||||
|
||||
/*
|
||||
* For future reference, in case we ever want to query
|
||||
* whether an adapter supports promiscuous mode, that
|
||||
* would be done on Windows by querying the value
|
||||
* of the OID_GEN_SUPPORTED_PACKET_FILTERS OID.
|
||||
*/
|
||||
if (PacketSetHwFilter(pw->adapter,NDIS_PACKET_TYPE_PROMISCUOUS) == FALSE)
|
||||
{
|
||||
DWORD errcode = GetLastError();
|
||||
|
||||
/*
|
||||
* Suppress spurious error generated by non-compiant
|
||||
* Suppress spurious error generated by non-compliant
|
||||
* MS Surface mobile adapters that appear to
|
||||
* return NDIS_STATUS_NOT_SUPPORTED for attempts
|
||||
* to set the hardware filter.
|
||||
@ -1341,10 +1355,18 @@ pcap_activate_npf(pcap_t *p)
|
||||
* value, so that old incorrect programs that
|
||||
* assume a non-zero return from pcap_activate()
|
||||
* is an error don't break.)
|
||||
*
|
||||
* We check here for ERROR_NOT_SUPPORTED, which
|
||||
* is what NDIS_STATUS_NOT_SUPPORTED (which is
|
||||
* the same value as the NTSTATUS value
|
||||
* STATUS_NOT_SUPPORTED) gets mapped to, as
|
||||
* well as NDIS_STATUS_NOT_SUPPORTED with the
|
||||
* "Customer" bit set.
|
||||
*/
|
||||
if (errcode != (NDIS_STATUS_NOT_SUPPORTED|NT_STATUS_CUSTOMER_DEFINED))
|
||||
if (errcode != ERROR_NOT_SUPPORTED &&
|
||||
errcode != (NDIS_STATUS_NOT_SUPPORTED|NT_STATUS_CUSTOMER_DEFINED))
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errcode,
|
||||
"failed to set hardware filter to promiscuous mode");
|
||||
goto bad;
|
||||
@ -1370,12 +1392,12 @@ pcap_activate_npf(pcap_t *p)
|
||||
DWORD errcode = GetLastError();
|
||||
|
||||
/*
|
||||
* Suppress spurious error generated by non-compiant
|
||||
* Suppress spurious error generated by non-compliant
|
||||
* MS Surface mobile adapters.
|
||||
*/
|
||||
if (errcode != (NDIS_STATUS_NOT_SUPPORTED|NT_STATUS_CUSTOMER_DEFINED))
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errcode,
|
||||
"failed to set hardware filter to non-promiscuous mode");
|
||||
goto bad;
|
||||
@ -1407,7 +1429,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
p->buffer = malloc(p->bufsize);
|
||||
if (p->buffer == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
@ -1417,7 +1439,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
/* tell the driver to copy the buffer as soon as data arrives */
|
||||
if(PacketSetMinToCopy(pw->adapter,0)==FALSE)
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
PCAP_ERRBUF_SIZE, GetLastError(),
|
||||
"Error calling PacketSetMinToCopy");
|
||||
goto bad;
|
||||
@ -1428,7 +1450,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
/* tell the driver to copy the buffer only if it contains at least 16K */
|
||||
if(PacketSetMinToCopy(pw->adapter,16000)==FALSE)
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf,
|
||||
PCAP_ERRBUF_SIZE, GetLastError(),
|
||||
"Error calling PacketSetMinToCopy");
|
||||
goto bad;
|
||||
@ -1505,7 +1527,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
total_prog.bf_len = 1;
|
||||
total_prog.bf_insns = &total_insn;
|
||||
if (!PacketSetBpf(pw->adapter, &total_prog)) {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "PacketSetBpf");
|
||||
status = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -1569,7 +1591,7 @@ pcap_activate_npf(pcap_t *p)
|
||||
* that the caller can do anything useful with it.
|
||||
*
|
||||
* (Not that we make any general guarantee of that
|
||||
* sort on UN*X, either, any more, given that not
|
||||
* sort on UN*X, either, anymore, given that not
|
||||
* all capture devices are regular OS network
|
||||
* interfaces.)
|
||||
*/
|
||||
@ -1600,6 +1622,11 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
char *device_copy = NULL;
|
||||
ADAPTER *adapter = NULL;
|
||||
ULONG num_ts_modes;
|
||||
/* Npcap 1.00 driver is buggy and will write 16 bytes regardless of
|
||||
* buffer size. Using a sufficient stack buffer avoids overflow and
|
||||
* avoids a heap allocation in most (currently all) cases.
|
||||
*/
|
||||
ULONG ts_modes[4];
|
||||
BOOL ret;
|
||||
DWORD error = ERROR_SUCCESS;
|
||||
ULONG *modes = NULL;
|
||||
@ -1616,7 +1643,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
*/
|
||||
device_copy = strdup(device);
|
||||
if (device_copy == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
@ -1660,7 +1687,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
p->tstamp_type_list = NULL;
|
||||
status = 0;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_win32_err(ebuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(ebuf,
|
||||
PCAP_ERRBUF_SIZE, error,
|
||||
"Error opening adapter");
|
||||
status = -1;
|
||||
@ -1690,8 +1717,8 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
* happen), and that ULONG should be set to the
|
||||
* number of modes.
|
||||
*/
|
||||
num_ts_modes = 1;
|
||||
ret = PacketGetTimestampModes(adapter, &num_ts_modes);
|
||||
ts_modes[0] = sizeof(ts_modes) / sizeof(ULONG);
|
||||
ret = PacketGetTimestampModes(adapter, ts_modes);
|
||||
if (!ret) {
|
||||
/*
|
||||
* OK, it failed. Did it fail with
|
||||
@ -1725,60 +1752,61 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
/*
|
||||
* No, some other error. Fail.
|
||||
*/
|
||||
pcap_fmt_errmsg_for_win32_err(ebuf,
|
||||
pcapint_fmt_errmsg_for_win32_err(ebuf,
|
||||
PCAP_ERRBUF_SIZE, error,
|
||||
"Error calling PacketGetTimestampModes");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Yes, so we now know how many types to fetch.
|
||||
*
|
||||
* The buffer needs to have one ULONG for the
|
||||
* count and num_ts_modes ULONGs for the
|
||||
* num_ts_modes time stamp types.
|
||||
*/
|
||||
num_ts_modes = ts_modes[0];
|
||||
modes = (ULONG *)malloc((1 + num_ts_modes) * sizeof(ULONG));
|
||||
if (modes == NULL) {
|
||||
/* Out of memory. */
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
modes[0] = 1 + num_ts_modes;
|
||||
if (!PacketGetTimestampModes(adapter, modes)) {
|
||||
pcapint_fmt_errmsg_for_win32_err(ebuf,
|
||||
PCAP_ERRBUF_SIZE, GetLastError(),
|
||||
"Error calling PacketGetTimestampModes");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
if (modes[0] != num_ts_modes) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"First PacketGetTimestampModes() call gives %lu modes, second call gives %lu modes",
|
||||
num_ts_modes, modes[0]);
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
modes = ts_modes;
|
||||
num_ts_modes = ts_modes[0];
|
||||
}
|
||||
/* else (ret == TRUE)
|
||||
* Unexpected success. Let's act like we got ERROR_MORE_DATA.
|
||||
* If it doesn't work, we'll hit some other error condition farther on.
|
||||
*/
|
||||
|
||||
/* If the driver reports no modes supported *and*
|
||||
* ERROR_MORE_DATA, something is seriously wrong.
|
||||
* We *could* ignore the error and continue without supporting
|
||||
* settable timestamp modes, but that would hide a bug.
|
||||
*/
|
||||
if (num_ts_modes == 0) {
|
||||
if (modes[0] == 0) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"PacketGetTimestampModes() reports 0 modes supported.");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Yes, so we now know how many types to fetch.
|
||||
*
|
||||
* The buffer needs to have one ULONG for the
|
||||
* count and num_ts_modes ULONGs for the
|
||||
* num_ts_modes time stamp types.
|
||||
*/
|
||||
modes = (ULONG *)malloc((1 + num_ts_modes) * sizeof(ULONG));
|
||||
if (modes == NULL) {
|
||||
/* Out of memory. */
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
modes[0] = 1 + num_ts_modes;
|
||||
if (!PacketGetTimestampModes(adapter, modes)) {
|
||||
pcap_fmt_errmsg_for_win32_err(ebuf,
|
||||
PCAP_ERRBUF_SIZE, GetLastError(),
|
||||
"Error calling PacketGetTimestampModes");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
if (modes[0] != num_ts_modes) {
|
||||
snprintf(ebuf, PCAP_ERRBUF_SIZE,
|
||||
"First PacketGetTimestampModes() call gives %lu modes, second call gives %lu modes",
|
||||
num_ts_modes, modes[0]);
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a buffer big enough for
|
||||
* PCAP_TSTAMP_HOST (default) plus
|
||||
@ -1786,7 +1814,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
*/
|
||||
p->tstamp_type_list = malloc((1 + num_ts_modes) * sizeof(u_int));
|
||||
if (p->tstamp_type_list == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
@ -1843,7 +1871,7 @@ get_ts_types(const char *device, pcap_t *p, char *ebuf)
|
||||
if (device_copy != NULL) {
|
||||
free(device_copy);
|
||||
}
|
||||
if (modes != NULL) {
|
||||
if (modes != NULL && modes != ts_modes) {
|
||||
free(modes);
|
||||
}
|
||||
if (adapter != NULL) {
|
||||
@ -1864,7 +1892,7 @@ get_ts_types(const char *device _U_, pcap_t *p _U_, char *ebuf _U_)
|
||||
#endif /* HAVE_PACKET_GET_TIMESTAMP_MODES */
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
@ -1915,11 +1943,11 @@ pcap_setfilter_npf(pcap_t *p, struct bpf_program *fp)
|
||||
*/
|
||||
|
||||
/*
|
||||
* install_bpf_program() validates the program.
|
||||
* pcapint_install_bpf_program() validates the program.
|
||||
*
|
||||
* XXX - what if we already have a filter in the kernel?
|
||||
*/
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
if (pcapint_install_bpf_program(p, fp) < 0)
|
||||
return (-1);
|
||||
pw->filtering_in_kernel = 0; /* filtering in userland */
|
||||
return (0);
|
||||
@ -1948,12 +1976,12 @@ pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
|
||||
|
||||
if(!fp)
|
||||
{
|
||||
pcap_strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
|
||||
pcapint_strlcpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Install a user level filter */
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
if (pcapint_install_bpf_program(p, fp) < 0)
|
||||
return (-1);
|
||||
|
||||
return (0);
|
||||
@ -1996,7 +2024,7 @@ pcap_setnonblock_npf(pcap_t *p, int nonblock)
|
||||
newtimeout = p->opt.timeout;
|
||||
}
|
||||
if (!PacketSetReadTimeout(pw->adapter, newtimeout)) {
|
||||
pcap_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "PacketSetReadTimeout");
|
||||
return (-1);
|
||||
}
|
||||
@ -2018,7 +2046,7 @@ pcap_add_if_npf(pcap_if_list_t *devlistp, char *name, bpf_u_int32 flags,
|
||||
/*
|
||||
* Add an entry for this interface, with no addresses.
|
||||
*/
|
||||
curdev = add_dev(devlistp, name, flags, description, errbuf);
|
||||
curdev = pcapint_add_dev(devlistp, name, flags, description, errbuf);
|
||||
if (curdev == NULL) {
|
||||
/*
|
||||
* Failure.
|
||||
@ -2050,7 +2078,7 @@ pcap_add_if_npf(pcap_if_list_t *devlistp, char *name, bpf_u_int32 flags,
|
||||
* "curdev" is an entry for this interface; add an entry for
|
||||
* this address to its list of addresses.
|
||||
*/
|
||||
res = add_addr_to_dev(curdev,
|
||||
res = pcapint_add_addr_to_dev(curdev,
|
||||
(struct sockaddr *)&if_addrs[if_addr_size].IPAddress,
|
||||
sizeof (struct sockaddr_storage),
|
||||
(struct sockaddr *)&if_addrs[if_addr_size].SubnetMask,
|
||||
@ -2327,7 +2355,7 @@ DIAG_ON_ENUM_SWITCH
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
int ret = 0;
|
||||
const char *desc;
|
||||
@ -2359,7 +2387,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
|
||||
if (last_error != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
last_error, "PacketGetAdapterNames");
|
||||
return (-1);
|
||||
}
|
||||
@ -2375,7 +2403,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
}
|
||||
|
||||
if (!PacketGetAdapterNames(AdaptersName, &NameLength)) {
|
||||
pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "PacketGetAdapterNames");
|
||||
free(AdaptersName);
|
||||
return (-1);
|
||||
@ -2490,7 +2518,7 @@ pcap_lookupdev(char *errbuf)
|
||||
* In addition, it's not thread-safe, so we've marked it as
|
||||
* deprecated.
|
||||
*/
|
||||
if (pcap_new_api) {
|
||||
if (pcapint_new_api) {
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"pcap_lookupdev() is deprecated and is not supported in programs calling pcap_init()");
|
||||
return (NULL);
|
||||
@ -2536,7 +2564,7 @@ DIAG_ON_DEPRECATION
|
||||
|
||||
if ( !PacketGetAdapterNames((PTSTR)TAdaptersName,&NameLength) )
|
||||
{
|
||||
pcap_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_win32_err(errbuf, PCAP_ERRBUF_SIZE,
|
||||
GetLastError(), "PacketGetAdapterNames");
|
||||
free(TAdaptersName);
|
||||
return NULL;
|
||||
@ -2710,7 +2738,7 @@ pcap_lib_version(void)
|
||||
*/
|
||||
char *full_pcap_version_string;
|
||||
|
||||
if (pcap_asprintf(&full_pcap_version_string,
|
||||
if (pcapint_asprintf(&full_pcap_version_string,
|
||||
WINPCAP_PRODUCT_NAME " version " WINPCAP_VER_STRING " (packet.dll version %s), based on " PCAP_VERSION_STRING,
|
||||
packet_version_string) != -1) {
|
||||
/* Success */
|
||||
@ -2737,7 +2765,7 @@ pcap_lib_version(void)
|
||||
*/
|
||||
char *full_pcap_version_string;
|
||||
|
||||
if (pcap_asprintf(&full_pcap_version_string,
|
||||
if (pcapint_asprintf(&full_pcap_version_string,
|
||||
PCAP_VERSION_STRING " (packet.dll version %s)",
|
||||
PacketGetVersion()) != -1) {
|
||||
/* Success */
|
||||
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -30,14 +28,14 @@
|
||||
static char nosup[] = "live packet capture not supported on this system";
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
(void)pcap_strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
|
||||
(void)pcapint_strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf _U_)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp _U_, char *errbuf _U_)
|
||||
{
|
||||
/*
|
||||
* There are no interfaces on which we can capture.
|
||||
@ -50,7 +48,7 @@ int
|
||||
pcap_lookupnet(const char *device _U_, bpf_u_int32 *netp _U_,
|
||||
bpf_u_int32 *maskp _U_, char *errbuf)
|
||||
{
|
||||
(void)pcap_strlcpy(errbuf, nosup, PCAP_ERRBUF_SIZE);
|
||||
(void)pcapint_strlcpy(errbuf, nosup, PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
@ -22,9 +22,7 @@
|
||||
* Extraction/creation by Jeffrey Mogul, DECWRL
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@ -79,7 +77,7 @@ struct rtentry;
|
||||
*/
|
||||
struct pcap_pf {
|
||||
int filtering_in_kernel; /* using kernel filter */
|
||||
u_long TotPkts; /* can't oflow for 79 hrs on ether */
|
||||
u_long TotPkts; /* can't overflow for 79 hrs on ether */
|
||||
u_long TotAccepted; /* count accepted by filter */
|
||||
u_long TotDrops; /* count of dropped packets */
|
||||
long TotMissed; /* missed by i/f during this run */
|
||||
@ -124,7 +122,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
|
||||
(void)lseek(pc->fd, 0L, SEEK_SET);
|
||||
goto again;
|
||||
}
|
||||
pcap_fmt_errmsg_for_errno(pc->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(pc->errbuf,
|
||||
sizeof(pc->errbuf), errno, "pf read");
|
||||
return (-1);
|
||||
}
|
||||
@ -203,7 +201,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
|
||||
* skipping that padding.
|
||||
*/
|
||||
if (pf->filtering_in_kernel ||
|
||||
pcap_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
|
||||
pcapint_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
|
||||
struct pcap_pkthdr h;
|
||||
pf->TotAccepted++;
|
||||
h.ts = sp->ens_tstamp;
|
||||
@ -230,7 +228,7 @@ pcap_inject_pf(pcap_t *p, const void *buf, int size)
|
||||
|
||||
ret = write(p->fd, buf, size);
|
||||
if (ret == -1) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send");
|
||||
return (-1);
|
||||
}
|
||||
@ -335,7 +333,7 @@ pcap_activate_pf(pcap_t *p)
|
||||
p->opt.device);
|
||||
err = PCAP_ERROR_PERM_DENIED;
|
||||
} else {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "pf open: %s", p->opt.device);
|
||||
err = PCAP_ERROR;
|
||||
}
|
||||
@ -360,7 +358,7 @@ pcap_activate_pf(pcap_t *p)
|
||||
if (p->opt.promisc)
|
||||
enmode |= ENPROMISC;
|
||||
if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "EIOCMBIS");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -372,14 +370,14 @@ pcap_activate_pf(pcap_t *p)
|
||||
#endif
|
||||
/* set the backlog */
|
||||
if (ioctl(p->fd, EIOCSETW, (caddr_t)&backlog) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "EIOCSETW");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
}
|
||||
/* discover interface type */
|
||||
if (ioctl(p->fd, EIOCDEVP, (caddr_t)&devparams) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "EIOCDEVP");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -404,14 +402,15 @@ pcap_activate_pf(pcap_t *p)
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
break;
|
||||
|
||||
case ENDT_FDDI:
|
||||
@ -476,7 +475,7 @@ pcap_activate_pf(pcap_t *p)
|
||||
} else
|
||||
p->fddipad = 0;
|
||||
if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&p->snapshot) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "EIOCTRUNCATE");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -486,7 +485,7 @@ pcap_activate_pf(pcap_t *p)
|
||||
Filter.enf_Priority = 37; /* anything > 2 */
|
||||
Filter.enf_FilterLen = 0; /* means "always true" */
|
||||
if (ioctl(p->fd, EIOCSETF, (caddr_t)&Filter) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "EIOCSETF");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -497,7 +496,7 @@ pcap_activate_pf(pcap_t *p)
|
||||
timeout.tv_sec = p->opt.timeout / 1000;
|
||||
timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
|
||||
if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "EIOCSRTIMEOUT");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -507,7 +506,7 @@ pcap_activate_pf(pcap_t *p)
|
||||
p->bufsize = BUFSPACE;
|
||||
p->buffer = malloc(p->bufsize + p->offset);
|
||||
if (p->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -523,18 +522,18 @@ pcap_activate_pf(pcap_t *p)
|
||||
p->setfilter_op = pcap_setfilter_pf;
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_pf;
|
||||
|
||||
return (0);
|
||||
bad:
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
return (err);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
@ -578,9 +577,9 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
return (pcapint_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
get_if_flags));
|
||||
}
|
||||
|
||||
@ -593,7 +592,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
|
||||
/*
|
||||
* See if BIOCVERSION works. If not, we assume the kernel doesn't
|
||||
* support BPF-style filters (it's not documented in the bpf(7)
|
||||
* or packetfiler(7) man pages, but the code used to fail if
|
||||
* or packetfilter(7) man pages, but the code used to fail if
|
||||
* BIOCSETF worked but BIOCVERSION didn't, and I've seen it do
|
||||
* kernel filtering in DU 4.0, so presumably BIOCVERSION works
|
||||
* there, at least).
|
||||
@ -610,7 +609,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
|
||||
* Yes. Try to install the filter.
|
||||
*/
|
||||
if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf,
|
||||
sizeof(p->errbuf), errno, "BIOCSETF");
|
||||
return (-1);
|
||||
}
|
||||
@ -659,7 +658,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
|
||||
/*
|
||||
* We couldn't do filtering in the kernel; do it in userland.
|
||||
*/
|
||||
if (install_bpf_program(p, fp) < 0)
|
||||
if (pcapint_install_bpf_program(p, fp) < 0)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
|
@ -28,9 +28,7 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <config.h>
|
||||
|
||||
#include "pcap-int.h"
|
||||
#include "pcap-rdmasniff.h"
|
||||
@ -89,7 +87,7 @@ rdmasniff_cleanup(pcap_t *handle)
|
||||
ibv_close_device(priv->context);
|
||||
free(priv->oneshot_buffer);
|
||||
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -172,7 +170,7 @@ rdmasniff_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
|
||||
pktd = (u_char *) handle->buffer + wc.wr_id * RDMASNIFF_RECEIVE_SIZE;
|
||||
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
pcapint_filter(handle->fcode.bf_insns, pktd, pkth.len, pkth.caplen)) {
|
||||
callback(user, &pkth, pktd);
|
||||
++priv->packets_recv;
|
||||
++count;
|
||||
@ -323,11 +321,11 @@ rdmasniff_activate(pcap_t *handle)
|
||||
handle->read_op = rdmasniff_read;
|
||||
handle->stats_op = rdmasniff_stats;
|
||||
handle->cleanup_op = rdmasniff_cleanup;
|
||||
handle->setfilter_op = install_bpf_program;
|
||||
handle->setfilter_op = pcapint_install_bpf_program;
|
||||
handle->setdirection_op = NULL;
|
||||
handle->set_datalink_op = NULL;
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
handle->oneshot_callback = rdmasniff_oneshot;
|
||||
handle->selectable_fd = priv->channel->fd;
|
||||
|
||||
@ -444,7 +442,7 @@ rdmasniff_findalldevs(pcap_if_list_t *devlistp, char *err_str)
|
||||
* XXX - do the notions of "up", "running", or
|
||||
* "connected" apply here?
|
||||
*/
|
||||
if (!add_dev(devlistp, dev_list[i]->name, 0, "RDMA sniffer", err_str)) {
|
||||
if (!pcapint_add_dev(devlistp, dev_list[i]->name, 0, "RDMA sniffer", err_str)) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
|
||||
* Copyright (c) 2005 - 2008 CACE Technologies, Davis (California)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
|
||||
* nor the names of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __PCAP_RPCAP_INT_H__
|
||||
#define __PCAP_RPCAP_INT_H__
|
||||
|
||||
#include "pcap.h"
|
||||
#include "sockutils.h" /* Needed for some structures (like SOCKET, sockaddr_in) which are used here */
|
||||
|
||||
/*
|
||||
* \file pcap-rpcap-int.h
|
||||
*
|
||||
* This file keeps all the definitions used by the RPCAP client and server,
|
||||
* other than the protocol definitions.
|
||||
*
|
||||
* \warning All the RPCAP functions that are allowed to return a buffer containing
|
||||
* the error description can return max PCAP_ERRBUF_SIZE characters.
|
||||
* However there is no guarantees that the string will be zero-terminated.
|
||||
* Best practice is to define the errbuf variable as a char of size 'PCAP_ERRBUF_SIZE+1'
|
||||
* and to insert manually the termination char at the end of the buffer. This will
|
||||
* guarantee that no buffer overflows occur even if we use the printf() to show
|
||||
* the error on the screen.
|
||||
*/
|
||||
|
||||
/*********************************************************
|
||||
* *
|
||||
* General definitions / typedefs for the RPCAP protocol *
|
||||
* *
|
||||
*********************************************************/
|
||||
|
||||
/*
|
||||
* \brief Buffer used by socket functions to send-receive packets.
|
||||
* In case you plan to have messages larger than this value, you have to increase it.
|
||||
*/
|
||||
#define RPCAP_NETBUF_SIZE 64000
|
||||
|
||||
/*********************************************************
|
||||
* *
|
||||
* Exported function prototypes *
|
||||
* *
|
||||
*********************************************************/
|
||||
void rpcap_createhdr(struct rpcap_header *header, uint8 type, uint16 value, uint32 length);
|
||||
int rpcap_senderror(SOCKET sock, char *error, unsigned short errcode, char *errbuf);
|
||||
|
||||
#endif
|
@ -31,9 +31,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ftmacros.h"
|
||||
#include "diag-control.h"
|
||||
@ -93,7 +91,7 @@
|
||||
struct activehosts
|
||||
{
|
||||
struct sockaddr_storage host;
|
||||
SOCKET sockctrl;
|
||||
PCAP_SOCKET sockctrl;
|
||||
SSL *ssl;
|
||||
uint8 protocol_version;
|
||||
int byte_swapped;
|
||||
@ -109,7 +107,7 @@ static struct activehosts *activeHosts;
|
||||
* See the documentation of pcap_remoteact_accept() and
|
||||
* pcap_remoteact_cleanup() for more details.
|
||||
*/
|
||||
static SOCKET sockmain;
|
||||
static PCAP_SOCKET sockmain;
|
||||
static SSL *ssl_main;
|
||||
|
||||
/*
|
||||
@ -123,11 +121,11 @@ struct pcap_rpcap {
|
||||
*/
|
||||
int rmt_clientside;
|
||||
|
||||
SOCKET rmt_sockctrl; /* socket ID of the socket used for the control connection */
|
||||
SOCKET rmt_sockdata; /* socket ID of the socket used for the data connection */
|
||||
PCAP_SOCKET rmt_sockctrl; /* socket ID of the socket used for the control connection */
|
||||
PCAP_SOCKET rmt_sockdata; /* socket ID of the socket used for the data connection */
|
||||
SSL *ctrl_ssl, *data_ssl; /* optional transport of rmt_sockctrl and rmt_sockdata via TLS */
|
||||
int rmt_flags; /* we have to save flags, since they are passed by the pcap_open_live(), but they are used by the pcap_startcapture() */
|
||||
int rmt_capstarted; /* 'true' if the capture is already started (needed to knoe if we have to call the pcap_startcapture() */
|
||||
int rmt_capstarted; /* 'true' if the capture is already started (needed to know if we have to call the pcap_startcapture() */
|
||||
char *currentfilter; /* Pointer to a buffer (allocated at run-time) that stores the current filter. Needed when flag PCAP_OPENFLAG_NOCAPTURE_RPCAP is turned on. */
|
||||
|
||||
uint8 protocol_version; /* negotiated protocol version */
|
||||
@ -172,13 +170,13 @@ static void pcap_save_current_filter_rpcap(pcap_t *fp, const char *filter);
|
||||
static int pcap_setfilter_rpcap(pcap_t *fp, struct bpf_program *prog);
|
||||
static int pcap_setsampling_remote(pcap_t *fp);
|
||||
static int pcap_startcapture_remote(pcap_t *fp);
|
||||
static int rpcap_recv_msg_header(SOCKET sock, SSL *, struct rpcap_header *header, char *errbuf);
|
||||
static int rpcap_check_msg_ver(SOCKET sock, SSL *, uint8 expected_ver, struct rpcap_header *header, char *errbuf);
|
||||
static int rpcap_check_msg_type(SOCKET sock, SSL *, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf);
|
||||
static int rpcap_process_msg_header(SOCKET sock, SSL *, uint8 ver, uint8 request_type, struct rpcap_header *header, char *errbuf);
|
||||
static int rpcap_recv(SOCKET sock, SSL *, void *buffer, size_t toread, uint32 *plen, char *errbuf);
|
||||
static void rpcap_msg_err(SOCKET sockctrl, SSL *, uint32 plen, char *remote_errbuf);
|
||||
static int rpcap_discard(SOCKET sock, SSL *, uint32 len, char *errbuf);
|
||||
static int rpcap_recv_msg_header(PCAP_SOCKET sock, SSL *, struct rpcap_header *header, char *errbuf);
|
||||
static int rpcap_check_msg_ver(PCAP_SOCKET sock, SSL *, uint8 expected_ver, struct rpcap_header *header, char *errbuf);
|
||||
static int rpcap_check_msg_type(PCAP_SOCKET sock, SSL *, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf);
|
||||
static int rpcap_process_msg_header(PCAP_SOCKET sock, SSL *, uint8 ver, uint8 request_type, struct rpcap_header *header, char *errbuf);
|
||||
static int rpcap_recv(PCAP_SOCKET sock, SSL *, void *buffer, size_t toread, uint32 *plen, char *errbuf);
|
||||
static void rpcap_msg_err(PCAP_SOCKET sockctrl, SSL *, uint32 plen, char *remote_errbuf);
|
||||
static int rpcap_discard(PCAP_SOCKET sock, SSL *, uint32 len, char *errbuf);
|
||||
static int rpcap_read_packet_msg(struct pcap_rpcap const *, pcap_t *p, size_t size);
|
||||
|
||||
/****************************************************
|
||||
@ -269,7 +267,10 @@ static int rpcap_read_packet_msg(struct pcap_rpcap const *, pcap_t *p, size_t si
|
||||
|
||||
/*
|
||||
* Possible IPv4 family values other than the designated over-the-wire value,
|
||||
* which is 2 (because everybody uses 2 for AF_INET4).
|
||||
* which is 2 (because everybody, except for Haiku uses 2 for AF_INET,
|
||||
* and Haiku has probably never run the old rpcapd code that put address
|
||||
* structures directly on the wire, rather than the new rpcapd code
|
||||
* that serializes addresses, using 2 for AF_INET).
|
||||
*/
|
||||
#define SOCKADDR_IN_LEN 16 /* length of struct sockaddr_in */
|
||||
#define SOCKADDR_IN6_LEN 28 /* length of struct sockaddr_in6 */
|
||||
@ -295,7 +296,7 @@ static int rpcap_read_packet_msg(struct pcap_rpcap const *, pcap_t *p, size_t si
|
||||
#define SOLARIS_AF_INET6 26
|
||||
|
||||
static int
|
||||
rpcap_deseraddr(struct rpcap_sockaddr *sockaddrin, struct sockaddr_storage **sockaddrout, char *errbuf)
|
||||
rpcap_deseraddr(struct rpcap_sockaddr *sockaddrin, struct sockaddr **sockaddrout, char *errbuf)
|
||||
{
|
||||
/* Warning: we support only AF_INET and AF_INET6 */
|
||||
switch (ntohs(sockaddrin->family))
|
||||
@ -307,10 +308,10 @@ rpcap_deseraddr(struct rpcap_sockaddr *sockaddrin, struct sockaddr_storage **soc
|
||||
struct rpcap_sockaddr_in *sockaddrin_ipv4;
|
||||
struct sockaddr_in *sockaddrout_ipv4;
|
||||
|
||||
(*sockaddrout) = (struct sockaddr_storage *) malloc(sizeof(struct sockaddr_in));
|
||||
(*sockaddrout) = (struct sockaddr *) malloc(sizeof(struct sockaddr_in));
|
||||
if ((*sockaddrout) == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc() failed");
|
||||
return -1;
|
||||
}
|
||||
@ -337,10 +338,10 @@ rpcap_deseraddr(struct rpcap_sockaddr *sockaddrin, struct sockaddr_storage **soc
|
||||
struct rpcap_sockaddr_in6 *sockaddrin_ipv6;
|
||||
struct sockaddr_in6 *sockaddrout_ipv6;
|
||||
|
||||
(*sockaddrout) = (struct sockaddr_storage *) malloc(sizeof(struct sockaddr_in6));
|
||||
(*sockaddrout) = (struct sockaddr *) malloc(sizeof(struct sockaddr_in6));
|
||||
if ((*sockaddrout) == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc() failed");
|
||||
return -1;
|
||||
}
|
||||
@ -693,7 +694,7 @@ static int pcap_read_rpcap(pcap_t *p, int cnt, pcap_handler callback, u_char *us
|
||||
* it to the callback, and count it so we can
|
||||
* return the count.
|
||||
*/
|
||||
pcap_post_process(p->linktype, pr->byte_swapped,
|
||||
pcapint_post_process(p->linktype, pr->byte_swapped,
|
||||
&pkt_header, pkt_data);
|
||||
(*callback)(user, &pkt_header, pkt_data);
|
||||
n++;
|
||||
@ -834,7 +835,7 @@ static void pcap_cleanup_rpcap(pcap_t *fp)
|
||||
pr->currentfilter = NULL;
|
||||
}
|
||||
|
||||
pcap_cleanup_live_common(fp);
|
||||
pcapint_cleanup_live_common(fp);
|
||||
|
||||
/* To avoid inconsistencies in the number of sock_init() */
|
||||
sock_cleanup();
|
||||
@ -1021,7 +1022,6 @@ rpcap_remoteact_getsock(const char *host, int *error, char *errbuf)
|
||||
{
|
||||
struct activehosts *temp; /* temp var needed to scan the host list chain */
|
||||
struct addrinfo hints, *addrinfo, *ai_next; /* temp var needed to translate between hostname to its address */
|
||||
int retval;
|
||||
|
||||
/* retrieve the network address corresponding to 'host' */
|
||||
addrinfo = NULL;
|
||||
@ -1029,9 +1029,9 @@ rpcap_remoteact_getsock(const char *host, int *error, char *errbuf)
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
retval = sock_initaddress(host, NULL, &hints, &addrinfo, errbuf,
|
||||
addrinfo = sock_initaddress(host, NULL, &hints, errbuf,
|
||||
PCAP_ERRBUF_SIZE);
|
||||
if (retval != 0)
|
||||
if (addrinfo == NULL)
|
||||
{
|
||||
*error = 1;
|
||||
return NULL;
|
||||
@ -1094,7 +1094,7 @@ static int pcap_startcapture_remote(pcap_t *fp)
|
||||
/* socket-related variables*/
|
||||
struct addrinfo hints; /* temp, needed to open a socket connection */
|
||||
struct addrinfo *addrinfo; /* temp, needed to open a socket connection */
|
||||
SOCKET sockdata = 0; /* socket descriptor of the data connection */
|
||||
PCAP_SOCKET sockdata = 0; /* socket descriptor of the data connection */
|
||||
struct sockaddr_storage saddr; /* temp, needed to retrieve the network data port chosen on the local machine */
|
||||
socklen_t saddrlen; /* temp, needed to retrieve the network data port chosen on the local machine */
|
||||
int ai_family; /* temp, keeps the address family used by the control connection */
|
||||
@ -1183,7 +1183,9 @@ static int pcap_startcapture_remote(pcap_t *fp)
|
||||
hints.ai_flags = AI_PASSIVE; /* Data connection is opened by the server toward the client */
|
||||
|
||||
/* Let's the server pick up a free network port for us */
|
||||
if (sock_initaddress(NULL, NULL, &hints, &addrinfo, fp->errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
addrinfo = sock_initaddress(NULL, NULL, &hints, fp->errbuf,
|
||||
PCAP_ERRBUF_SIZE);
|
||||
if (addrinfo == NULL)
|
||||
goto error_nodiscard;
|
||||
|
||||
if ((sockdata = sock_open(NULL, addrinfo, SOCKOPEN_SERVER,
|
||||
@ -1308,7 +1310,9 @@ static int pcap_startcapture_remote(pcap_t *fp)
|
||||
snprintf(portstring, PCAP_BUF_SIZE, "%d", ntohs(startcapreply.portdata));
|
||||
|
||||
/* Let's the server pick up a free network port for us */
|
||||
if (sock_initaddress(host, portstring, &hints, &addrinfo, fp->errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
addrinfo = sock_initaddress(host, portstring, &hints,
|
||||
fp->errbuf, PCAP_ERRBUF_SIZE);
|
||||
if (addrinfo == NULL)
|
||||
goto error;
|
||||
|
||||
if ((sockdata = sock_open(host, addrinfo, SOCKOPEN_CLIENT, 0, fp->errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
|
||||
@ -1320,7 +1324,7 @@ static int pcap_startcapture_remote(pcap_t *fp)
|
||||
}
|
||||
else
|
||||
{
|
||||
SOCKET socktemp; /* We need another socket, since we're going to accept() a connection */
|
||||
PCAP_SOCKET socktemp; /* We need another socket, since we're going to accept() a connection */
|
||||
|
||||
/* Connection creation */
|
||||
saddrlen = sizeof(struct sockaddr_storage);
|
||||
@ -1427,7 +1431,7 @@ static int pcap_startcapture_remote(pcap_t *fp)
|
||||
fp->buffer = (u_char *)malloc(fp->bufsize);
|
||||
if (fp->buffer == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(fp->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(fp->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto error;
|
||||
}
|
||||
@ -1545,7 +1549,7 @@ error_nodiscard:
|
||||
*
|
||||
* \param sendbuf: the buffer on which the serialized data has to copied.
|
||||
*
|
||||
* \param sendbufidx: it is used to return the abounf of bytes copied into the buffer.
|
||||
* \param sendbufidx: it is used to return the amount of bytes copied into the buffer.
|
||||
*
|
||||
* \param prog: the bpf program we have to copy.
|
||||
*
|
||||
@ -1701,7 +1705,7 @@ static int pcap_setfilter_rpcap(pcap_t *fp, struct bpf_program *prog)
|
||||
if (!pr->rmt_capstarted)
|
||||
{
|
||||
/* copy filter into the pcap_t structure */
|
||||
if (install_bpf_program(fp, prog) == -1)
|
||||
if (pcapint_install_bpf_program(fp, prog) == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
@ -1797,7 +1801,7 @@ static int pcap_createfilter_norpcappkt(pcap_t *fp, struct bpf_program *prog)
|
||||
* We have a current filter; add items to it to
|
||||
* filter out this rpcap session.
|
||||
*/
|
||||
if (pcap_asprintf(&newfilter,
|
||||
if (pcapint_asprintf(&newfilter,
|
||||
"(%s) and not (host %s and host %s and port %s and port %s) and not (host %s and host %s and port %s)",
|
||||
pr->currentfilter, myaddress, peeraddress,
|
||||
myctrlport, peerctrlport, myaddress, peeraddress,
|
||||
@ -1815,7 +1819,7 @@ static int pcap_createfilter_norpcappkt(pcap_t *fp, struct bpf_program *prog)
|
||||
* We have no current filter; construct a filter to
|
||||
* filter out this rpcap session.
|
||||
*/
|
||||
if (pcap_asprintf(&newfilter,
|
||||
if (pcapint_asprintf(&newfilter,
|
||||
"not (host %s and host %s and port %s and port %s) and not (host %s and host %s and port %s)",
|
||||
myaddress, peeraddress, myctrlport, peerctrlport,
|
||||
myaddress, peeraddress, mydataport) == -1)
|
||||
@ -1867,7 +1871,7 @@ static int pcap_setsampling_remote(pcap_t *fp)
|
||||
struct rpcap_header header; /* To keep the reply message */
|
||||
struct rpcap_sampling *sampling_pars; /* Structure that is needed to send sampling parameters to the remote host */
|
||||
|
||||
/* If no samping is requested, return 'ok' */
|
||||
/* If no sampling is requested, return 'ok' */
|
||||
if (fp->rmt_samp.method == PCAP_SAMP_NOSAMP)
|
||||
return 0;
|
||||
|
||||
@ -1967,7 +1971,7 @@ static int pcap_setsampling_remote(pcap_t *fp)
|
||||
* \return '0' if everything is fine, '-1' for an error. For errors,
|
||||
* an error message string is returned in the 'errbuf' variable.
|
||||
*/
|
||||
static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver,
|
||||
static int rpcap_doauth(PCAP_SOCKET sockctrl, SSL *ssl, uint8 *ver,
|
||||
int *byte_swapped, struct pcap_rmtauth *auth, char *errbuf)
|
||||
{
|
||||
char sendbuf[RPCAP_NETBUF_SIZE]; /* temporary buffer in which data that has to be sent is buffered */
|
||||
@ -2093,7 +2097,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver,
|
||||
{
|
||||
/* No - discard it and fail. */
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Authenticaton reply from server is too short");
|
||||
"Authentication reply from server is too short");
|
||||
(void)rpcap_discard(sockctrl, ssl, plen, NULL);
|
||||
return -1;
|
||||
}
|
||||
@ -2118,7 +2122,7 @@ static int rpcap_doauth(SOCKET sockctrl, SSL *ssl, uint8 *ver,
|
||||
* Discard it and fail.
|
||||
*/
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"Authenticaton reply from server is too short");
|
||||
"Authentication reply from server is too short");
|
||||
(void)rpcap_discard(sockctrl, ssl, plen, NULL);
|
||||
return -1;
|
||||
}
|
||||
@ -2258,7 +2262,7 @@ pcap_setnonblock_rpcap(pcap_t *p, int nonblock _U_)
|
||||
|
||||
static int
|
||||
rpcap_setup_session(const char *source, struct pcap_rmtauth *auth,
|
||||
int *activep, SOCKET *sockctrlp, uint8 *uses_sslp, SSL **sslp,
|
||||
int *activep, PCAP_SOCKET *sockctrlp, uint8 *uses_sslp, SSL **sslp,
|
||||
int rmt_flags, uint8 *protocol_versionp, int *byte_swappedp,
|
||||
char *host, char *port, char *iface, char *errbuf)
|
||||
{
|
||||
@ -2271,7 +2275,7 @@ rpcap_setup_session(const char *source, struct pcap_rmtauth *auth,
|
||||
* You must have a valid source string even if we're in active mode,
|
||||
* because otherwise the call to the following function will fail.
|
||||
*/
|
||||
if (pcap_parsesrcstr_ex(source, &type, host, port, iface, uses_sslp,
|
||||
if (pcapint_parsesrcstr_ex(source, &type, host, port, iface, uses_sslp,
|
||||
errbuf) == -1)
|
||||
return -1;
|
||||
|
||||
@ -2337,16 +2341,16 @@ rpcap_setup_session(const char *source, struct pcap_rmtauth *auth,
|
||||
if (port[0] == 0)
|
||||
{
|
||||
/* the user chose not to specify the port */
|
||||
if (sock_initaddress(host, RPCAP_DEFAULT_NETPORT,
|
||||
&hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
return -1;
|
||||
addrinfo = sock_initaddress(host, RPCAP_DEFAULT_NETPORT,
|
||||
&hints, errbuf, PCAP_ERRBUF_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sock_initaddress(host, port, &hints, &addrinfo,
|
||||
errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
return -1;
|
||||
addrinfo = sock_initaddress(host, port, &hints,
|
||||
errbuf, PCAP_ERRBUF_SIZE);
|
||||
}
|
||||
if (addrinfo == NULL)
|
||||
return -1;
|
||||
|
||||
if ((*sockctrlp = sock_open(host, addrinfo, SOCKOPEN_CLIENT, 0,
|
||||
errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
|
||||
@ -2441,7 +2445,7 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim
|
||||
char *source_str;
|
||||
struct pcap_rpcap *pr; /* structure used when doing a remote live capture */
|
||||
char host[PCAP_BUF_SIZE], ctrlport[PCAP_BUF_SIZE], iface[PCAP_BUF_SIZE];
|
||||
SOCKET sockctrl;
|
||||
PCAP_SOCKET sockctrl;
|
||||
SSL *ssl = NULL;
|
||||
uint8 protocol_version; /* negotiated protocol version */
|
||||
int byte_swapped; /* server is known to be byte-swapped */
|
||||
@ -2461,7 +2465,7 @@ pcap_t *pcap_open_rpcap(const char *source, int snaplen, int flags, int read_tim
|
||||
}
|
||||
source_str = strdup(source);
|
||||
if (source_str == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return NULL;
|
||||
}
|
||||
@ -2613,7 +2617,7 @@ pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_i
|
||||
{
|
||||
uint8 protocol_version; /* protocol version */
|
||||
int byte_swapped; /* Server byte order is swapped from ours */
|
||||
SOCKET sockctrl; /* socket descriptor of the control connection */
|
||||
PCAP_SOCKET sockctrl; /* socket descriptor of the control connection */
|
||||
SSL *ssl = NULL; /* optional SSL handler for sockctrl */
|
||||
uint32 plen;
|
||||
struct rpcap_header header; /* structure that keeps the general header of the rpcap protocol */
|
||||
@ -2681,7 +2685,7 @@ pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_i
|
||||
dev = (pcap_if_t *)malloc(sizeof(pcap_if_t));
|
||||
if (dev == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc() failed");
|
||||
goto error;
|
||||
}
|
||||
@ -2725,14 +2729,14 @@ pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_i
|
||||
tmpstring[findalldevs_if.namelen] = 0;
|
||||
|
||||
/* Create the new device identifier */
|
||||
if (pcap_createsrcstr_ex(tmpstring2, PCAP_SRC_IFREMOTE,
|
||||
if (pcapint_createsrcstr_ex(tmpstring2, PCAP_SRC_IFREMOTE,
|
||||
host, port, tmpstring, uses_ssl, errbuf) == -1)
|
||||
goto error;
|
||||
|
||||
dev->name = strdup(tmpstring2);
|
||||
if (dev->name == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "malloc() failed");
|
||||
goto error;
|
||||
}
|
||||
@ -2753,11 +2757,11 @@ pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_i
|
||||
|
||||
tmpstring[findalldevs_if.desclen] = 0;
|
||||
|
||||
if (pcap_asprintf(&dev->description,
|
||||
if (pcapint_asprintf(&dev->description,
|
||||
"%s '%s' %s %s", PCAP_TEXT_SOURCE_ADAPTER,
|
||||
tmpstring, PCAP_TEXT_SOURCE_ON_REMOTE_HOST, host) == -1)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "malloc() failed");
|
||||
goto error;
|
||||
}
|
||||
@ -2783,7 +2787,7 @@ pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_i
|
||||
addr = (struct pcap_addr *) malloc(sizeof(struct pcap_addr));
|
||||
if (addr == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "malloc() failed");
|
||||
goto error;
|
||||
}
|
||||
@ -2793,26 +2797,26 @@ pcap_findalldevs_ex_remote(const char *source, struct pcap_rmtauth *auth, pcap_i
|
||||
addr->broadaddr = NULL;
|
||||
addr->dstaddr = NULL;
|
||||
|
||||
if (rpcap_deseraddr(&ifaddr.addr,
|
||||
(struct sockaddr_storage **) &addr->addr, errbuf) == -1)
|
||||
if (rpcap_deseraddr(&ifaddr.addr, &addr->addr,
|
||||
errbuf) == -1)
|
||||
{
|
||||
freeaddr(addr);
|
||||
goto error;
|
||||
}
|
||||
if (rpcap_deseraddr(&ifaddr.netmask,
|
||||
(struct sockaddr_storage **) &addr->netmask, errbuf) == -1)
|
||||
if (rpcap_deseraddr(&ifaddr.netmask, &addr->netmask,
|
||||
errbuf) == -1)
|
||||
{
|
||||
freeaddr(addr);
|
||||
goto error;
|
||||
}
|
||||
if (rpcap_deseraddr(&ifaddr.broadaddr,
|
||||
(struct sockaddr_storage **) &addr->broadaddr, errbuf) == -1)
|
||||
if (rpcap_deseraddr(&ifaddr.broadaddr, &addr->broadaddr,
|
||||
errbuf) == -1)
|
||||
{
|
||||
freeaddr(addr);
|
||||
goto error;
|
||||
}
|
||||
if (rpcap_deseraddr(&ifaddr.dstaddr,
|
||||
(struct sockaddr_storage **) &addr->dstaddr, errbuf) == -1)
|
||||
if (rpcap_deseraddr(&ifaddr.dstaddr, &addr->dstaddr,
|
||||
errbuf) == -1)
|
||||
{
|
||||
freeaddr(addr);
|
||||
goto error;
|
||||
@ -2917,14 +2921,14 @@ error_nodiscard:
|
||||
* to implement; we provide some APIs for it that work only with rpcap.
|
||||
*/
|
||||
|
||||
SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, int uses_ssl, char *errbuf)
|
||||
PCAP_SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, int uses_ssl, char *errbuf)
|
||||
{
|
||||
/* socket-related variables */
|
||||
struct addrinfo hints; /* temporary struct to keep settings needed to open the new socket */
|
||||
struct addrinfo *addrinfo; /* keeps the addrinfo chain; required to open a new socket */
|
||||
struct sockaddr_storage from; /* generic sockaddr_storage variable */
|
||||
socklen_t fromlen; /* keeps the length of the sockaddr_storage variable */
|
||||
SOCKET sockctrl; /* keeps the main socket identifier */
|
||||
PCAP_SOCKET sockctrl; /* keeps the main socket identifier */
|
||||
SSL *ssl = NULL; /* Optional SSL handler for sockctrl */
|
||||
uint8 protocol_version; /* negotiated protocol version */
|
||||
int byte_swapped; /* 1 if server byte order is known to be the reverse of ours */
|
||||
@ -2942,29 +2946,29 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
/* Warning: this call can be the first one called by the user. */
|
||||
/* For this reason, we have to initialize the Winsock support. */
|
||||
if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
return (SOCKET)-1;
|
||||
return (PCAP_SOCKET)-1;
|
||||
|
||||
/* Do the work */
|
||||
if ((port == NULL) || (port[0] == 0))
|
||||
{
|
||||
if (sock_initaddress(address, RPCAP_DEFAULT_NETPORT_ACTIVE, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
{
|
||||
return (SOCKET)-2;
|
||||
}
|
||||
addrinfo = sock_initaddress(address,
|
||||
RPCAP_DEFAULT_NETPORT_ACTIVE, &hints, errbuf,
|
||||
PCAP_ERRBUF_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sock_initaddress(address, port, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1)
|
||||
{
|
||||
return (SOCKET)-2;
|
||||
}
|
||||
addrinfo = sock_initaddress(address, port, &hints, errbuf,
|
||||
PCAP_ERRBUF_SIZE);
|
||||
}
|
||||
if (addrinfo == NULL)
|
||||
{
|
||||
return (PCAP_SOCKET)-2;
|
||||
}
|
||||
|
||||
|
||||
if ((sockmain = sock_open(NULL, addrinfo, SOCKOPEN_SERVER, 1, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
|
||||
{
|
||||
freeaddrinfo(addrinfo);
|
||||
return (SOCKET)-2;
|
||||
return (PCAP_SOCKET)-2;
|
||||
}
|
||||
freeaddrinfo(addrinfo);
|
||||
|
||||
@ -2981,7 +2985,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
if (sockctrl == INVALID_SOCKET)
|
||||
{
|
||||
sock_geterrmsg(errbuf, PCAP_ERRBUF_SIZE, "accept() failed");
|
||||
return (SOCKET)-2;
|
||||
return (PCAP_SOCKET)-2;
|
||||
}
|
||||
|
||||
/* Promote to SSL early before any error message may be sent */
|
||||
@ -2992,12 +2996,12 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
if (! ssl)
|
||||
{
|
||||
sock_close(sockctrl, NULL, 0);
|
||||
return (SOCKET)-1;
|
||||
return (PCAP_SOCKET)-1;
|
||||
}
|
||||
#else
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE, "No TLS support");
|
||||
sock_close(sockctrl, NULL, 0);
|
||||
return (SOCKET)-1;
|
||||
return (PCAP_SOCKET)-1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -3016,11 +3020,11 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
}
|
||||
#endif
|
||||
sock_close(sockctrl, NULL, 0);
|
||||
return (SOCKET)-1;
|
||||
return (PCAP_SOCKET)-1;
|
||||
}
|
||||
|
||||
/* checks if the connecting host is among the ones allowed */
|
||||
if (sock_check_hostlist((char *)hostlist, RPCAP_HOSTLIST_SEP, &from, errbuf, PCAP_ERRBUF_SIZE) < 0)
|
||||
if (sock_check_hostlist(hostlist, RPCAP_HOSTLIST_SEP, &from, errbuf, PCAP_ERRBUF_SIZE) < 0)
|
||||
{
|
||||
rpcap_senderror(sockctrl, ssl, 0, PCAP_ERR_REMOTEACCEPT, errbuf, NULL);
|
||||
#ifdef HAVE_OPENSSL
|
||||
@ -3032,7 +3036,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
}
|
||||
#endif
|
||||
sock_close(sockctrl, NULL, 0);
|
||||
return (SOCKET)-1;
|
||||
return (PCAP_SOCKET)-1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3052,7 +3056,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
}
|
||||
#endif
|
||||
sock_close(sockctrl, NULL, 0);
|
||||
return (SOCKET)-3;
|
||||
return (PCAP_SOCKET)-3;
|
||||
}
|
||||
|
||||
/* Checks that this host does not already have a cntrl connection in place */
|
||||
@ -3085,7 +3089,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
|
||||
if (temp == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc() failed");
|
||||
rpcap_senderror(sockctrl, ssl, protocol_version, PCAP_ERR_REMOTEACCEPT, errbuf, NULL);
|
||||
#ifdef HAVE_OPENSSL
|
||||
@ -3097,7 +3101,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
}
|
||||
#endif
|
||||
sock_close(sockctrl, NULL, 0);
|
||||
return (SOCKET)-1;
|
||||
return (PCAP_SOCKET)-1;
|
||||
}
|
||||
|
||||
memcpy(&temp->host, &from, fromlen);
|
||||
@ -3110,7 +3114,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
|
||||
return sockctrl;
|
||||
}
|
||||
|
||||
SOCKET pcap_remoteact_accept(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, char *errbuf)
|
||||
PCAP_SOCKET pcap_remoteact_accept(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, char *errbuf)
|
||||
{
|
||||
return pcap_remoteact_accept_ex(address, port, hostlist, connectinghost, auth, 0, errbuf);
|
||||
}
|
||||
@ -3119,7 +3123,6 @@ int pcap_remoteact_close(const char *host, char *errbuf)
|
||||
{
|
||||
struct activehosts *temp, *prev; /* temp var needed to scan the host list chain */
|
||||
struct addrinfo hints, *addrinfo, *ai_next; /* temp var needed to translate between hostname to its address */
|
||||
int retval;
|
||||
|
||||
temp = activeHosts;
|
||||
prev = NULL;
|
||||
@ -3130,9 +3133,9 @@ int pcap_remoteact_close(const char *host, char *errbuf)
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
retval = sock_initaddress(host, NULL, &hints, &addrinfo, errbuf,
|
||||
addrinfo = sock_initaddress(host, NULL, &hints, errbuf,
|
||||
PCAP_ERRBUF_SIZE);
|
||||
if (retval != 0)
|
||||
if (addrinfo == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -3287,7 +3290,7 @@ int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
pcap_strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE);
|
||||
pcapint_strlcat(hostlist, hoststr, PCAP_ERRBUF_SIZE);
|
||||
hostlist[len - 1] = sep;
|
||||
hostlist[len] = 0;
|
||||
|
||||
@ -3300,7 +3303,7 @@ int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf)
|
||||
/*
|
||||
* Receive the header of a message.
|
||||
*/
|
||||
static int rpcap_recv_msg_header(SOCKET sock, SSL *ssl, struct rpcap_header *header, char *errbuf)
|
||||
static int rpcap_recv_msg_header(PCAP_SOCKET sock, SSL *ssl, struct rpcap_header *header, char *errbuf)
|
||||
{
|
||||
int nrecv;
|
||||
|
||||
@ -3320,7 +3323,7 @@ static int rpcap_recv_msg_header(SOCKET sock, SSL *ssl, struct rpcap_header *hea
|
||||
* Make sure the protocol version of a received message is what we were
|
||||
* expecting.
|
||||
*/
|
||||
static int rpcap_check_msg_ver(SOCKET sock, SSL *ssl, uint8 expected_ver, struct rpcap_header *header, char *errbuf)
|
||||
static int rpcap_check_msg_ver(PCAP_SOCKET sock, SSL *ssl, uint8 expected_ver, struct rpcap_header *header, char *errbuf)
|
||||
{
|
||||
/*
|
||||
* Did the server specify the version we negotiated?
|
||||
@ -3351,7 +3354,7 @@ static int rpcap_check_msg_ver(SOCKET sock, SSL *ssl, uint8 expected_ver, struct
|
||||
* Check the message type of a received message, which should either be
|
||||
* the expected message type or RPCAP_MSG_ERROR.
|
||||
*/
|
||||
static int rpcap_check_msg_type(SOCKET sock, SSL *ssl, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf)
|
||||
static int rpcap_check_msg_type(PCAP_SOCKET sock, SSL *ssl, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf)
|
||||
{
|
||||
const char *request_type_string;
|
||||
const char *msg_type_string;
|
||||
@ -3421,7 +3424,7 @@ static int rpcap_check_msg_type(SOCKET sock, SSL *ssl, uint8 request_type, struc
|
||||
/*
|
||||
* Receive and process the header of a message.
|
||||
*/
|
||||
static int rpcap_process_msg_header(SOCKET sock, SSL *ssl, uint8 expected_ver, uint8 request_type, struct rpcap_header *header, char *errbuf)
|
||||
static int rpcap_process_msg_header(PCAP_SOCKET sock, SSL *ssl, uint8 expected_ver, uint8 request_type, struct rpcap_header *header, char *errbuf)
|
||||
{
|
||||
uint16 errcode;
|
||||
|
||||
@ -3453,7 +3456,7 @@ static int rpcap_process_msg_header(SOCKET sock, SSL *ssl, uint8 expected_ver, u
|
||||
* Returns 0 on success, logs a message and returns -1 on a network
|
||||
* error.
|
||||
*/
|
||||
static int rpcap_recv(SOCKET sock, SSL *ssl, void *buffer, size_t toread, uint32 *plen, char *errbuf)
|
||||
static int rpcap_recv(PCAP_SOCKET sock, SSL *ssl, void *buffer, size_t toread, uint32 *plen, char *errbuf)
|
||||
{
|
||||
int nread;
|
||||
|
||||
@ -3476,7 +3479,7 @@ static int rpcap_recv(SOCKET sock, SSL *ssl, void *buffer, size_t toread, uint32
|
||||
/*
|
||||
* This handles the RPCAP_MSG_ERROR message.
|
||||
*/
|
||||
static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_errbuf)
|
||||
static void rpcap_msg_err(PCAP_SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_errbuf)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
|
||||
@ -3507,7 +3510,7 @@ static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_e
|
||||
* If we're not in UTF-8 mode, convert it to the local
|
||||
* code page.
|
||||
*/
|
||||
if (!pcap_utf_8_mode)
|
||||
if (!pcapint_utf_8_mode)
|
||||
utf_8_to_acp_truncated(remote_errbuf);
|
||||
#endif
|
||||
|
||||
@ -3547,7 +3550,7 @@ static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_e
|
||||
* Returns 0 on success, logs a message and returns -1 on a network
|
||||
* error.
|
||||
*/
|
||||
static int rpcap_discard(SOCKET sock, SSL *ssl, uint32 len, char *errbuf)
|
||||
static int rpcap_discard(PCAP_SOCKET sock, SSL *ssl, uint32 len, char *errbuf)
|
||||
{
|
||||
if (len != 0)
|
||||
{
|
||||
|
@ -17,7 +17,7 @@
|
||||
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
.\"
|
||||
.TH PCAP-SAVEFILE @MAN_FILE_FORMATS@ "24 April 2020"
|
||||
.TH PCAP-SAVEFILE @MAN_FILE_FORMATS@ "16 Aug 2023"
|
||||
.SH NAME
|
||||
pcap-savefile \- libpcap savefile format
|
||||
.SH DESCRIPTION
|
||||
@ -41,13 +41,13 @@ Magic number
|
||||
_
|
||||
Major version Minor version
|
||||
_
|
||||
Time zone offset
|
||||
Reserved1
|
||||
_
|
||||
Time stamp accuracy
|
||||
Reserved2
|
||||
_
|
||||
Snapshot length
|
||||
_
|
||||
Link-layer header type
|
||||
Link-layer header type and additional information
|
||||
.TE
|
||||
.RE
|
||||
.PP
|
||||
@ -80,10 +80,15 @@ A 2-byte file format major version number; the current version number is
|
||||
A 2-byte file format minor version number; the current version number is
|
||||
4.
|
||||
.IP
|
||||
A 4-byte time zone offset; this is always 0.
|
||||
A 4-byte not used - SHOULD be filled with 0 by pcap file writers, and MUST
|
||||
be ignored by pcap file readers. This value was documented by some older
|
||||
implementations as "gmt to local correction" or "time zone offset".
|
||||
Some older pcap file writers stored non-zero values in this field.
|
||||
.IP
|
||||
A 4-byte number giving the accuracy of time stamps in the file; this is
|
||||
always 0.
|
||||
A 4-byte not used - SHOULD be filled with 0 by pcap file writers, and MUST
|
||||
be ignored by pcap file readers. This value was documented by some older
|
||||
implementations as "accuracy of timestamps". Some older pcap file
|
||||
writers stored non-zero values in this field.
|
||||
.IP
|
||||
A 4-byte number giving the "snapshot length" of the capture; packets
|
||||
longer than the snapshot length are truncated to the snapshot length, so
|
||||
@ -95,12 +100,53 @@ bytes of a packet longer than
|
||||
.I N
|
||||
bytes will be saved in the capture.
|
||||
.IP
|
||||
a 4-byte number giving the link-layer header type for packets in the
|
||||
capture; see
|
||||
A 4-byte number giving the link-layer header type for packets in the
|
||||
capture and optional additional information.
|
||||
.IP
|
||||
This format of this field is:
|
||||
.PP
|
||||
.nf
|
||||
1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|FCS len|R|P| Reserved3 | Link-layer type |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
.fi
|
||||
.IP
|
||||
The field is shown as if it were in the byte order of the host reading
|
||||
or writing the file, with bit 0 being the most-significant bit of the
|
||||
field and bit 31 being the least-significant bit of the field.
|
||||
.IP
|
||||
Link-layer type (16 bits):
|
||||
A 16-bit value giving the link-layer header type for packets in the file;
|
||||
see
|
||||
.BR pcap-linktype (@MAN_MISC_INFO@)
|
||||
for the
|
||||
.B LINKTYPE_
|
||||
values that can appear in this field.
|
||||
.IP
|
||||
Reserved3 (10 bits):
|
||||
not used - MUST be set to zero by pcap writers, and MUST NOT be
|
||||
interpreted by pcap readers; a reader SHOULD treat a non-zero value as
|
||||
an error.
|
||||
.IP
|
||||
P (1 bit):
|
||||
A bit that, if set, indicates that the Frame Check Sequence (FCS)
|
||||
length value is present and, if not set, indicates that the FCS value is
|
||||
not present.
|
||||
.IP
|
||||
R (1 bit):
|
||||
not used - MUST be set to zero by pcap writers, and MUST NOT be
|
||||
interpreted by pcap readers; a reader SHOULD treat a non-zero value as
|
||||
an error.
|
||||
.IP
|
||||
FCS len (4 bits):
|
||||
A 4-bit unsigned value giving the number of 16-bit (2-octet) words
|
||||
of FCS that are appended to each packet, if the P bit is set; if the P
|
||||
bit is not set, and the FCS length is not indicated by the link-layer
|
||||
type value, the FCS length is unknown. The valid values of the FCS len
|
||||
field are between 0 and 15; Ethernet, for example, would have an FCS
|
||||
length value of 2, corresponding to a 4-octet FCS.
|
||||
.PP
|
||||
Following the per-file header are zero or more packets; each packet
|
||||
begins with a per-packet header, which is immediately followed by the
|
||||
|
@ -5,9 +5,7 @@
|
||||
* (+961 3 485243)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
@ -124,7 +122,7 @@ loop:
|
||||
caplen = packet_len;
|
||||
}
|
||||
/* Run the packet filter if there is one. */
|
||||
if ((p->fcode.bf_insns == NULL) || pcap_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
|
||||
if ((p->fcode.bf_insns == NULL) || pcapint_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
|
||||
|
||||
|
||||
/* get a time stamp , consisting of :
|
||||
@ -171,7 +169,7 @@ loop:
|
||||
static int
|
||||
septel_inject(pcap_t *handle, const void *buf _U_, int size _U_)
|
||||
{
|
||||
pcap_strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards",
|
||||
pcapint_strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
}
|
||||
@ -207,7 +205,7 @@ static pcap_t *septel_activate(pcap_t* handle) {
|
||||
|
||||
handle->read_op = septel_read;
|
||||
handle->inject_op = septel_inject;
|
||||
handle->setfilter_op = install_bpf_program;
|
||||
handle->setfilter_op = pcapint_install_bpf_program;
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = septel_getnonblock;
|
||||
handle->setnonblock_op = septel_setnonblock;
|
||||
@ -267,7 +265,7 @@ septel_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
/*
|
||||
* XXX - do the notions of "up", "running", or "connected" apply here?
|
||||
*/
|
||||
if (add_dev(devlistp,"septel",0,"Intel/Septel device",errbuf) == NULL)
|
||||
if (pcapint_add_dev(devlistp,"septel",0,"Intel/Septel device",errbuf) == NULL)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
@ -303,7 +301,7 @@ septel_setnonblock(pcap_t *p, int nonblock _U_)
|
||||
* There are no regular interfaces, just Septel interfaces.
|
||||
*/
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@ -312,7 +310,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* Attempts to open a regular interface fail.
|
||||
*/
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device, char *errbuf)
|
||||
pcapint_create_interface(const char *device, char *errbuf)
|
||||
{
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"This version of libpcap only supports Septel cards");
|
||||
|
@ -24,9 +24,7 @@
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -42,7 +40,7 @@
|
||||
|
||||
#include "pcap-sita.h"
|
||||
|
||||
/* non-configureable manifests follow */
|
||||
/* non-configurable manifests follow */
|
||||
|
||||
#define IOP_SNIFFER_PORT 49152 /* TCP port on the IOP used for 'distributed pcap' usage */
|
||||
#define MAX_LINE_SIZE 255 /* max size of a buffer/line in /etc/hosts we allow */
|
||||
@ -302,7 +300,7 @@ int acn_parse_hosts_file(char *errbuf) { /* returns: -1 = error, 0 = OK */
|
||||
}
|
||||
ptr2 = strdup(ptr); /* copy the IP address into our malloc'ed memory */
|
||||
if (ptr2 == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
continue;
|
||||
}
|
||||
@ -372,7 +370,7 @@ static void pcap_cleanup_acn(pcap_t *handle) {
|
||||
close_with_IOP(chassis, geoslot, LIVE);
|
||||
if (u)
|
||||
u->first_time = 0;
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
}
|
||||
|
||||
static void send_to_fd(int fd, int len, unsigned char *str) {
|
||||
@ -584,7 +582,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
ptr = u->imsg; /* point to the start of the msg for this IOP */
|
||||
while (ptr < (u->imsg + u->len)) {
|
||||
if ((iff = malloc(sizeof(pcap_if_t))) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "malloc");
|
||||
return -1;
|
||||
}
|
||||
@ -594,7 +592,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
|
||||
if (*ptr) { /* if there is a count for the name */
|
||||
if ((iff->name = malloc(*ptr + 1)) == NULL) { /* get that amount of space */
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc");
|
||||
return -1;
|
||||
@ -607,7 +605,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
|
||||
if (*ptr) { /* if there is a count for the description */
|
||||
if ((iff->description = malloc(*ptr + 1)) == NULL) { /* get that amount of space */
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc");
|
||||
return -1;
|
||||
@ -629,7 +627,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
prev_addr = 0;
|
||||
while (address_count--) {
|
||||
if ((addr = malloc(sizeof(pcap_addr_t))) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc");
|
||||
return -1;
|
||||
@ -639,7 +637,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
if (prev_addr) prev_addr->next = addr; /* insert a forward link */
|
||||
if (*ptr) { /* if there is a count for the address */
|
||||
if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) { /* get that amount of space */
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return -1;
|
||||
@ -653,7 +651,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
ptr++; /* then forwards one more for the 'length of the address' field */
|
||||
if (*ptr) { /* process any netmask */
|
||||
if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return -1;
|
||||
@ -669,7 +667,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
ptr++;
|
||||
if (*ptr) { /* process any broadcast address */
|
||||
if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return -1;
|
||||
@ -685,7 +683,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
ptr++;
|
||||
if (*ptr) { /* process any destination address */
|
||||
if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
return -1;
|
||||
@ -706,7 +704,7 @@ static int process_client_data (char *errbuf) { /* returns: -1 = error, 0
|
||||
newname = translate_IOP_to_pcap_name(u, iff->name, interfaceType); /* add a translation entry and get a point to the mangled name */
|
||||
bigger_buffer = realloc(iff->name, strlen(newname) + 1);
|
||||
if (bigger_buffer == NULL) { /* we now re-write the name stored in the interface list */
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "realloc");
|
||||
return -1;
|
||||
}
|
||||
@ -841,7 +839,7 @@ static int acn_open_live(const char *name, char *errbuf, int *linktype) { /* re
|
||||
iface_t *p;
|
||||
pcap_if_list_t devlist;
|
||||
|
||||
pcap_platform_finddevs(&devlist, errbuf);
|
||||
pcapint_platform_finddevs(&devlist, errbuf);
|
||||
for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { /* scan the table... */
|
||||
for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
|
||||
u = &units[chassis][geoslot];
|
||||
@ -885,7 +883,7 @@ static void acn_start_monitor(int fd, int snaplen, int timeout, int promiscuous,
|
||||
}
|
||||
|
||||
static int pcap_inject_acn(pcap_t *p, const void *buf _U_, int size _U_) {
|
||||
pcap_strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters",
|
||||
pcapint_strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
}
|
||||
@ -994,8 +992,8 @@ static int pcap_activate_sita(pcap_t *handle) {
|
||||
handle->setfilter_op = pcap_setfilter_acn;
|
||||
handle->setdirection_op = NULL; /* Not implemented */
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
handle->cleanup_op = pcap_cleanup_acn;
|
||||
handle->read_op = pcap_read_acn;
|
||||
handle->stats_op = pcap_stats_acn;
|
||||
@ -1023,7 +1021,7 @@ static int pcap_activate_sita(pcap_t *handle) {
|
||||
|
||||
handle->buffer = malloc(handle->bufsize + handle->offset);
|
||||
if (!handle->buffer) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
pcap_cleanup_acn(handle);
|
||||
return PCAP_ERROR;
|
||||
@ -1038,7 +1036,7 @@ static int pcap_activate_sita(pcap_t *handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pcap_t *pcap_create_interface(const char *device _U_, char *ebuf) {
|
||||
pcap_t *pcapint_create_interface(const char *device _U_, char *ebuf) {
|
||||
pcap_t *p;
|
||||
|
||||
p = PCAP_CREATE_COMMON(ebuf, struct pcap_sita);
|
||||
@ -1049,7 +1047,7 @@ pcap_t *pcap_create_interface(const char *device _U_, char *ebuf) {
|
||||
return (p);
|
||||
}
|
||||
|
||||
int pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) {
|
||||
int pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) {
|
||||
|
||||
//printf("pcap_findalldevs()\n"); // fulko
|
||||
|
||||
@ -1057,7 +1055,7 @@ int pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) {
|
||||
strcpy(errbuf, "");
|
||||
if (acn_parse_hosts_file(errbuf)) /* scan the hosts file for potential IOPs */
|
||||
{
|
||||
//printf("pcap_findalldevs() returning BAD after parsehosts\n"); // fulko
|
||||
//printf("pcap_findalldevs() returning BAD after parse_hosts\n"); // fulko
|
||||
return -1;
|
||||
}
|
||||
//printf("pcap_findalldevs() got hostlist now finding devs\n"); // fulko
|
||||
|
@ -597,7 +597,7 @@ A { text-decoration:none }
|
||||
<TR>
|
||||
<TD VALIGN=TOP>direction</TD>
|
||||
<TD VALIGN=TOP ALIGN=CENTER>1</TD>
|
||||
<TD VALIGN=TOP>A flag indicating the direction of traffic that should be captuted [both(0) / in(1) / out(2)]</TD>
|
||||
<TD VALIGN=TOP>A flag indicating the direction of traffic that should be captured [both(0) / in(1) / out(2)]</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
</TD>
|
||||
@ -803,8 +803,6 @@ A { text-decoration:none }
|
||||
this is also known as a UN*X time_t. You can use the ANSI C
|
||||
<em>time()</em> function from <em>time.h</em> to get this value,
|
||||
but you might use a more optimized way to get this timestamp value.
|
||||
If this timestamp isn't based on GMT (UTC), use <em>thiszone</em>
|
||||
from the global header for adjustments.</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD VALIGN=TOP>tv_usec</TD>
|
||||
|
@ -1,6 +1,4 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/param.h>
|
||||
@ -55,7 +53,7 @@ snf_pcap_stats(pcap_t *p, struct pcap_stat *ps)
|
||||
int rc;
|
||||
|
||||
if ((rc = snf_ring_getstats(snfps->snf_ring, &stats))) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
rc, "snf_get_stats");
|
||||
return -1;
|
||||
}
|
||||
@ -76,7 +74,7 @@ snf_platform_cleanup(pcap_t *p)
|
||||
#endif
|
||||
snf_ring_close(ps->snf_ring);
|
||||
snf_close(ps->snf_handle);
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -181,7 +179,7 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf,
|
||||
PCAP_ERRBUF_SIZE, err, "snf_read");
|
||||
return -1;
|
||||
}
|
||||
@ -192,7 +190,7 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
caplen = p->snapshot;
|
||||
|
||||
if ((p->fcode.bf_insns == NULL) ||
|
||||
pcap_filter(p->fcode.bf_insns, req.pkt_addr, req.length, caplen)) {
|
||||
pcapint_filter(p->fcode.bf_insns, req.pkt_addr, req.length, caplen)) {
|
||||
hdr.ts = snf_timestamp_to_timeval(req.timestamp, p->opt.tstamp_precision);
|
||||
hdr.caplen = caplen;
|
||||
hdr.len = req.length;
|
||||
@ -217,7 +215,7 @@ snf_inject(pcap_t *p, const void *buf _U_, int size _U_)
|
||||
if (ps->snf_inj == NULL) {
|
||||
rc = snf_inject_open(ps->snf_boardnum, 0, &ps->snf_inj);
|
||||
if (rc) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
rc, "snf_inject_open");
|
||||
return (-1);
|
||||
}
|
||||
@ -228,12 +226,12 @@ snf_inject(pcap_t *p, const void *buf _U_, int size _U_)
|
||||
return (size);
|
||||
}
|
||||
else {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
rc, "snf_inject_send");
|
||||
return (-1);
|
||||
}
|
||||
#else
|
||||
pcap_strlcpy(p->errbuf, "Sending packets isn't supported with this snf version",
|
||||
pcapint_strlcpy(p->errbuf, "Sending packets isn't supported with this snf version",
|
||||
PCAP_ERRBUF_SIZE);
|
||||
return (-1);
|
||||
#endif
|
||||
@ -276,7 +274,7 @@ snf_activate(pcap_t* p)
|
||||
flags, /* may want pshared */
|
||||
&ps->snf_handle);
|
||||
if (err != 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
err, "snf_open failed");
|
||||
return -1;
|
||||
}
|
||||
@ -286,7 +284,7 @@ snf_activate(pcap_t* p)
|
||||
}
|
||||
err = snf_ring_open_id(ps->snf_handle, ring_id, &ps->snf_ring);
|
||||
if (err != 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
err, "snf_ring_open_id(ring=%d) failed", ring_id);
|
||||
return -1;
|
||||
}
|
||||
@ -309,7 +307,7 @@ snf_activate(pcap_t* p)
|
||||
|
||||
err = snf_start(ps->snf_handle);
|
||||
if (err != 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
err, "snf_start failed");
|
||||
return -1;
|
||||
}
|
||||
@ -323,7 +321,7 @@ snf_activate(pcap_t* p)
|
||||
p->linktype = DLT_EN10MB;
|
||||
p->read_op = snf_read;
|
||||
p->inject_op = snf_inject;
|
||||
p->setfilter_op = install_bpf_program;
|
||||
p->setfilter_op = pcapint_install_bpf_program;
|
||||
p->setdirection_op = NULL; /* Not implemented.*/
|
||||
p->set_datalink_op = snf_set_datalink;
|
||||
p->getnonblock_op = snf_getnonblock;
|
||||
@ -358,7 +356,7 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
|
||||
if (snf_getifaddrs(&ifaddrs) || ifaddrs == NULL)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "snf_getifaddrs");
|
||||
return (-1);
|
||||
}
|
||||
@ -377,7 +375,7 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
/*
|
||||
* Myricom SNF adapter ports may appear as regular
|
||||
* network interfaces, which would already have been
|
||||
* added to the list of adapters by pcap_platform_finddevs()
|
||||
* added to the list of adapters by pcapint_platform_finddevs()
|
||||
* if this isn't an SNF-only version of libpcap.
|
||||
*
|
||||
* Our create routine intercepts pcap_create() calls for
|
||||
@ -416,7 +414,7 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* See if there's already an entry for the device
|
||||
* with the name ifa->snf_ifa_name.
|
||||
*/
|
||||
dev = find_dev(devlistp, ifa->snf_ifa_name);
|
||||
dev = pcapint_find_dev(devlistp, ifa->snf_ifa_name);
|
||||
if (dev != NULL) {
|
||||
/*
|
||||
* Yes. Update its description.
|
||||
@ -425,7 +423,7 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
|
||||
desc_str = strdup(desc);
|
||||
if (desc_str == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"snf_findalldevs strdup");
|
||||
return -1;
|
||||
@ -442,7 +440,7 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* PCAP_IF_CONNECTION_STATUS_CONNECTED or
|
||||
* PCAP_IF_CONNECTION_STATUS_DISCONNECTED?
|
||||
*/
|
||||
dev = add_dev(devlistp, ifa->snf_ifa_name, 0, desc,
|
||||
dev = pcapint_add_dev(devlistp, ifa->snf_ifa_name, 0, desc,
|
||||
errbuf);
|
||||
if (dev == NULL)
|
||||
return -1;
|
||||
@ -457,14 +455,14 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* to IPv4 address.
|
||||
*/
|
||||
addr.sin_family = AF_INET;
|
||||
if (add_addr_to_dev(dev, &addr, sizeof(addr),
|
||||
if (pcapint_add_addr_to_dev(dev, &addr, sizeof(addr),
|
||||
NULL, 0, NULL, 0, NULL, 0, errbuf) == -1)
|
||||
return -1;
|
||||
} else if (ret == -1) {
|
||||
/*
|
||||
* Error.
|
||||
*/
|
||||
pcap_fmt_errmsg_for_errno(errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"sinf_findalldevs inet_pton");
|
||||
return -1;
|
||||
@ -492,7 +490,7 @@ snf_findalldevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* "disconnected", as "is this plugged into a network?"
|
||||
* would be a per-port property.
|
||||
*/
|
||||
if (add_dev(devlistp, name,
|
||||
if (pcapint_add_dev(devlistp, name,
|
||||
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, desc,
|
||||
errbuf) == NULL)
|
||||
return (-1);
|
||||
@ -566,7 +564,7 @@ snf_create(const char *device, char *ebuf, int *is_ours)
|
||||
*/
|
||||
p->tstamp_precision_list = malloc(2 * sizeof(u_int));
|
||||
if (p->tstamp_precision_list == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno,
|
||||
pcapint_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE, errno,
|
||||
"malloc");
|
||||
pcap_close(p);
|
||||
return NULL;
|
||||
@ -590,7 +588,7 @@ snf_create(const char *device, char *ebuf, int *is_ours)
|
||||
* There are no regular interfaces, just SNF interfaces.
|
||||
*/
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
@ -599,7 +597,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
* Attempts to open a regular interface fail.
|
||||
*/
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device, char *errbuf)
|
||||
pcapint_create_interface(const char *device, char *errbuf)
|
||||
{
|
||||
snprintf(errbuf, PCAP_ERRBUF_SIZE,
|
||||
"This version of libpcap only supports SNF cards");
|
||||
|
@ -23,9 +23,7 @@
|
||||
* This module now handles the STREAMS based NIT.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@ -129,7 +127,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
if (cc < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
return (0);
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "pcap_read");
|
||||
return (-1);
|
||||
}
|
||||
@ -192,7 +190,7 @@ pcap_read_snit(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
if (caplen > p->snapshot)
|
||||
caplen = p->snapshot;
|
||||
|
||||
if (pcap_filter(p->fcode.bf_insns, cp, nlp->nh_pktlen, caplen)) {
|
||||
if (pcapint_filter(p->fcode.bf_insns, cp, nlp->nh_pktlen, caplen)) {
|
||||
struct pcap_pkthdr h;
|
||||
h.ts = ntp->nh_timestamp;
|
||||
h.len = nlp->nh_pktlen;
|
||||
@ -225,7 +223,7 @@ pcap_inject_snit(pcap_t *p, const void *buf, int size)
|
||||
data.len = size;
|
||||
ret = putmsg(p->fd, &ctl, &data);
|
||||
if (ret == -1) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send");
|
||||
return (-1);
|
||||
}
|
||||
@ -249,7 +247,7 @@ nit_setflags(pcap_t *p)
|
||||
si.ic_len = sizeof(zero);
|
||||
si.ic_dp = (char *)&zero;
|
||||
if (ioctl(p->fd, I_STR, (char *)&si) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "NIOCSCHUNK");
|
||||
return (-1);
|
||||
}
|
||||
@ -262,7 +260,7 @@ nit_setflags(pcap_t *p)
|
||||
si.ic_len = sizeof(timeout);
|
||||
si.ic_dp = (char *)&timeout;
|
||||
if (ioctl(p->fd, I_STR, (char *)&si) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "NIOCSTIME");
|
||||
return (-1);
|
||||
}
|
||||
@ -274,7 +272,7 @@ nit_setflags(pcap_t *p)
|
||||
si.ic_len = sizeof(flags);
|
||||
si.ic_dp = (char *)&flags;
|
||||
if (ioctl(p->fd, I_STR, (char *)&si) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "NIOCSFLAGS");
|
||||
return (-1);
|
||||
}
|
||||
@ -341,7 +339,7 @@ pcap_activate_snit(pcap_t *p)
|
||||
dev);
|
||||
} else {
|
||||
err = PCAP_ERROR;
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "%s", dev);
|
||||
}
|
||||
goto bad;
|
||||
@ -349,13 +347,13 @@ pcap_activate_snit(pcap_t *p)
|
||||
|
||||
/* arrange to get discrete messages from the STREAM and use NIT_BUF */
|
||||
if (ioctl(fd, I_SRDOPT, (char *)RMSGD) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "I_SRDOPT");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
}
|
||||
if (ioctl(fd, I_PUSH, "nbuf") < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "push nbuf");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -366,7 +364,7 @@ pcap_activate_snit(pcap_t *p)
|
||||
si.ic_len = sizeof(chunksize);
|
||||
si.ic_dp = (char *)&chunksize;
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "NIOCSCHUNK");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -384,7 +382,7 @@ pcap_activate_snit(pcap_t *p)
|
||||
* Is there one that means "that device doesn't support
|
||||
* STREAMS NIT"?
|
||||
*/
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "NIOCBIND: %s", ifr.ifr_name);
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -395,7 +393,7 @@ pcap_activate_snit(pcap_t *p)
|
||||
si.ic_len = sizeof(p->snapshot);
|
||||
si.ic_dp = (char *)&p->snapshot;
|
||||
if (ioctl(fd, I_STR, (char *)&si) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "NIOCSSNAP");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -414,7 +412,7 @@ pcap_activate_snit(pcap_t *p)
|
||||
p->bufsize = BUFSPACE;
|
||||
p->buffer = malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
@ -437,32 +435,33 @@ pcap_activate_snit(pcap_t *p)
|
||||
* Ethernet framing).
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
err = PCAP_ERROR;
|
||||
goto bad;
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
|
||||
p->read_op = pcap_read_snit;
|
||||
p->inject_op = pcap_inject_snit;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_snit;
|
||||
|
||||
return (0);
|
||||
bad:
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
return (err);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
@ -496,9 +495,9 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
return (pcapint_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
get_if_flags));
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,7 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/file.h>
|
||||
@ -95,7 +93,7 @@ again:
|
||||
case EWOULDBLOCK:
|
||||
return (0); /* XXX */
|
||||
}
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "read");
|
||||
return (-1);
|
||||
}
|
||||
@ -104,7 +102,7 @@ again:
|
||||
|
||||
/*
|
||||
* XXX - Sigh, snoop_packetlen is a 16 bit quantity. If we
|
||||
* got a short length, but read a full sized snoop pakcet,
|
||||
* got a short length, but read a full sized snoop packet,
|
||||
* assume we overflowed and add back the 64K...
|
||||
*/
|
||||
if (cc == (p->snapshot + sizeof(struct snoopheader)) &&
|
||||
@ -126,7 +124,7 @@ again:
|
||||
}
|
||||
|
||||
if (p->fcode.bf_insns == NULL ||
|
||||
pcap_filter(p->fcode.bf_insns, cp, datalen, caplen)) {
|
||||
pcapint_filter(p->fcode.bf_insns, cp, datalen, caplen)) {
|
||||
struct pcap_pkthdr h;
|
||||
++psn->stat.ps_recv;
|
||||
h.ts.tv_sec = sh->snoop_timestamp.tv_sec;
|
||||
@ -150,7 +148,7 @@ pcap_inject_snoop(pcap_t *p, const void *buf, int size)
|
||||
*/
|
||||
ret = write(p->fd, buf, size);
|
||||
if (ret == -1) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "send");
|
||||
return (-1);
|
||||
}
|
||||
@ -167,7 +165,7 @@ pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)
|
||||
rs = &rawstats;
|
||||
memset(rs, 0, sizeof(*rs));
|
||||
if (ioctl(p->fd, SIOCRAWSTATS, (char *)rs) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
|
||||
errno, "SIOCRAWSTATS");
|
||||
return (-1);
|
||||
}
|
||||
@ -212,7 +210,7 @@ pcap_activate_snoop(pcap_t *p)
|
||||
|
||||
fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP);
|
||||
if (fd < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "snoop socket");
|
||||
goto bad;
|
||||
}
|
||||
@ -228,13 +226,13 @@ pcap_activate_snoop(pcap_t *p)
|
||||
* they might be the same error, if they both end up
|
||||
* meaning "snoop doesn't know about that device".
|
||||
*/
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "snoop bind");
|
||||
goto bad;
|
||||
}
|
||||
memset(&sf, 0, sizeof(sf));
|
||||
if (ioctl(fd, SIOCADDSNOOP, &sf) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCADDSNOOP");
|
||||
goto bad;
|
||||
}
|
||||
@ -283,14 +281,14 @@ pcap_activate_snoop(pcap_t *p)
|
||||
* Classical IP devices?
|
||||
*/
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL) {
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_DOCSIS;
|
||||
p->dlt_count = 2;
|
||||
} else if (strncmp("ipg", p->opt.device, 3) == 0 ||
|
||||
strncmp("rns", p->opt.device, 3) == 0 || /* O2/200/2000 FDDI */
|
||||
strncmp("xpi", p->opt.device, 3) == 0) {
|
||||
@ -343,7 +341,7 @@ pcap_activate_snoop(pcap_t *p)
|
||||
*/
|
||||
(void)strncpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name));
|
||||
if (ioctl(fd, SIOCGIFMTU, (char *)&ifr) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCGIFMTU");
|
||||
goto bad;
|
||||
}
|
||||
@ -377,13 +375,13 @@ pcap_activate_snoop(pcap_t *p)
|
||||
if (snooplen < 0)
|
||||
snooplen = 0;
|
||||
if (ioctl(fd, SIOCSNOOPLEN, &snooplen) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCSNOOPLEN");
|
||||
goto bad;
|
||||
}
|
||||
v = 1;
|
||||
if (ioctl(fd, SIOCSNOOPING, &v) < 0) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "SIOCSNOOPING");
|
||||
goto bad;
|
||||
}
|
||||
@ -391,7 +389,7 @@ pcap_activate_snoop(pcap_t *p)
|
||||
p->bufsize = 4096; /* XXX */
|
||||
p->buffer = malloc(p->bufsize);
|
||||
if (p->buffer == NULL) {
|
||||
pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
goto bad;
|
||||
}
|
||||
@ -403,21 +401,21 @@ pcap_activate_snoop(pcap_t *p)
|
||||
|
||||
p->read_op = pcap_read_snoop;
|
||||
p->inject_op = pcap_inject_snoop;
|
||||
p->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
p->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = NULL; /* can't change data link type */
|
||||
p->getnonblock_op = pcap_getnonblock_fd;
|
||||
p->setnonblock_op = pcap_setnonblock_fd;
|
||||
p->getnonblock_op = pcapint_getnonblock_fd;
|
||||
p->setnonblock_op = pcapint_setnonblock_fd;
|
||||
p->stats_op = pcap_stats_snoop;
|
||||
|
||||
return (0);
|
||||
bad:
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
return (PCAP_ERROR);
|
||||
}
|
||||
|
||||
pcap_t *
|
||||
pcap_create_interface(const char *device _U_, char *ebuf)
|
||||
pcapint_create_interface(const char *device _U_, char *ebuf)
|
||||
{
|
||||
pcap_t *p;
|
||||
|
||||
@ -451,9 +449,9 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
|
||||
}
|
||||
|
||||
int
|
||||
pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
|
||||
{
|
||||
return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
return (pcapint_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
|
||||
get_if_flags));
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap.h>
|
||||
#include <pcap-int.h>
|
||||
@ -288,34 +286,34 @@ TC_API_LOAD_STATUS LoadTcFunctions(void)
|
||||
|
||||
currentStatus = TC_API_CANNOT_LOAD;
|
||||
|
||||
g_TcFunctions.hTcApiDllHandle = pcap_load_code("TcApi.dll");
|
||||
g_TcFunctions.hTcApiDllHandle = pcapint_load_code("TcApi.dll");
|
||||
if (g_TcFunctions.hTcApiDllHandle == NULL) break;
|
||||
|
||||
g_TcFunctions.QueryPortList = (TcFcnQueryPortList) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcQueryPortList");
|
||||
g_TcFunctions.FreePortList = (TcFcnFreePortList) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcFreePortList");
|
||||
g_TcFunctions.QueryPortList = (TcFcnQueryPortList) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcQueryPortList");
|
||||
g_TcFunctions.FreePortList = (TcFcnFreePortList) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcFreePortList");
|
||||
|
||||
g_TcFunctions.StatusGetString = (TcFcnStatusGetString) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatusGetString");
|
||||
g_TcFunctions.StatusGetString = (TcFcnStatusGetString) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatusGetString");
|
||||
|
||||
g_TcFunctions.PortGetName = (TcFcnPortGetName) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcPortGetName");
|
||||
g_TcFunctions.PortGetDescription = (TcFcnPortGetDescription) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcPortGetDescription");
|
||||
g_TcFunctions.PortGetName = (TcFcnPortGetName) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcPortGetName");
|
||||
g_TcFunctions.PortGetDescription = (TcFcnPortGetDescription) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcPortGetDescription");
|
||||
|
||||
g_TcFunctions.InstanceOpenByName = (TcFcnInstanceOpenByName) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceOpenByName");
|
||||
g_TcFunctions.InstanceClose = (TcFcnInstanceClose) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceClose");
|
||||
g_TcFunctions.InstanceSetFeature = (TcFcnInstanceSetFeature) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceSetFeature");
|
||||
g_TcFunctions.InstanceQueryFeature = (TcFcnInstanceQueryFeature) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceQueryFeature");
|
||||
g_TcFunctions.InstanceReceivePackets = (TcFcnInstanceReceivePackets) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceReceivePackets");
|
||||
g_TcFunctions.InstanceGetReceiveWaitHandle = (TcFcnInstanceGetReceiveWaitHandle)pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceGetReceiveWaitHandle");
|
||||
g_TcFunctions.InstanceTransmitPackets = (TcFcnInstanceTransmitPackets)pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceTransmitPackets");
|
||||
g_TcFunctions.InstanceQueryStatistics = (TcFcnInstanceQueryStatistics)pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceQueryStatistics");
|
||||
g_TcFunctions.InstanceOpenByName = (TcFcnInstanceOpenByName) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceOpenByName");
|
||||
g_TcFunctions.InstanceClose = (TcFcnInstanceClose) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceClose");
|
||||
g_TcFunctions.InstanceSetFeature = (TcFcnInstanceSetFeature) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceSetFeature");
|
||||
g_TcFunctions.InstanceQueryFeature = (TcFcnInstanceQueryFeature) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceQueryFeature");
|
||||
g_TcFunctions.InstanceReceivePackets = (TcFcnInstanceReceivePackets) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceReceivePackets");
|
||||
g_TcFunctions.InstanceGetReceiveWaitHandle = (TcFcnInstanceGetReceiveWaitHandle)pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceGetReceiveWaitHandle");
|
||||
g_TcFunctions.InstanceTransmitPackets = (TcFcnInstanceTransmitPackets)pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceTransmitPackets");
|
||||
g_TcFunctions.InstanceQueryStatistics = (TcFcnInstanceQueryStatistics)pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcInstanceQueryStatistics");
|
||||
|
||||
g_TcFunctions.PacketsBufferCreate = (TcFcnPacketsBufferCreate) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferCreate");
|
||||
g_TcFunctions.PacketsBufferDestroy = (TcFcnPacketsBufferDestroy) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferDestroy");
|
||||
g_TcFunctions.PacketsBufferQueryNextPacket = (TcFcnPacketsBufferQueryNextPacket)pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferQueryNextPacket");
|
||||
g_TcFunctions.PacketsBufferCommitNextPacket = (TcFcnPacketsBufferCommitNextPacket)pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferCommitNextPacket");
|
||||
g_TcFunctions.PacketsBufferCreate = (TcFcnPacketsBufferCreate) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferCreate");
|
||||
g_TcFunctions.PacketsBufferDestroy = (TcFcnPacketsBufferDestroy) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferDestroy");
|
||||
g_TcFunctions.PacketsBufferQueryNextPacket = (TcFcnPacketsBufferQueryNextPacket)pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferQueryNextPacket");
|
||||
g_TcFunctions.PacketsBufferCommitNextPacket = (TcFcnPacketsBufferCommitNextPacket)pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcPacketsBufferCommitNextPacket");
|
||||
|
||||
g_TcFunctions.StatisticsDestroy = (TcFcnStatisticsDestroy) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatisticsDestroy");
|
||||
g_TcFunctions.StatisticsUpdate = (TcFcnStatisticsUpdate) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatisticsUpdate");
|
||||
g_TcFunctions.StatisticsQueryValue = (TcFcnStatisticsQueryValue) pcap_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatisticsQueryValue");
|
||||
g_TcFunctions.StatisticsDestroy = (TcFcnStatisticsDestroy) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatisticsDestroy");
|
||||
g_TcFunctions.StatisticsUpdate = (TcFcnStatisticsUpdate) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatisticsUpdate");
|
||||
g_TcFunctions.StatisticsQueryValue = (TcFcnStatisticsQueryValue) pcapint_find_function(g_TcFunctions.hTcApiDllHandle, "TcStatisticsQueryValue");
|
||||
|
||||
if ( g_TcFunctions.QueryPortList == NULL
|
||||
|| g_TcFunctions.FreePortList == NULL
|
||||
@ -419,7 +417,7 @@ TcFindAllDevs(pcap_if_list_t *devlist, char *errbuf)
|
||||
dev = TcCreatePcapIfFromPort(pPorts[i]);
|
||||
|
||||
if (dev != NULL)
|
||||
add_dev(devlist, dev->name, dev->flags, dev->description, errbuf);
|
||||
pcapint_add_dev(devlist, dev->name, dev->flags, dev->description, errbuf);
|
||||
}
|
||||
|
||||
if (numPorts > 0)
|
||||
@ -540,14 +538,14 @@ TcActivate(pcap_t *p)
|
||||
|
||||
p->linktype = DLT_EN10MB;
|
||||
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
|
||||
/*
|
||||
* If that fails, just leave the list empty.
|
||||
*/
|
||||
if (p->dlt_list != NULL) {
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_PPI;
|
||||
p->dlt_count = 2;
|
||||
if (p->dlt_list == NULL)
|
||||
{
|
||||
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Error allocating memory");
|
||||
return PCAP_ERROR;
|
||||
}
|
||||
p->dlt_list[0] = DLT_EN10MB;
|
||||
p->dlt_list[1] = DLT_PPI;
|
||||
p->dlt_count = 2;
|
||||
|
||||
/*
|
||||
* ignore promiscuous mode
|
||||
@ -610,7 +608,7 @@ TcActivate(pcap_t *p)
|
||||
}
|
||||
|
||||
p->read_op = TcRead;
|
||||
p->setfilter_op = install_bpf_program;
|
||||
p->setfilter_op = pcapint_install_bpf_program;
|
||||
p->setdirection_op = NULL; /* Not implemented. */
|
||||
p->set_datalink_op = TcSetDatalink;
|
||||
p->getnonblock_op = TcGetNonBlock;
|
||||
@ -774,7 +772,7 @@ static void TcCleanup(pcap_t *p)
|
||||
pt->PpiPacket = NULL;
|
||||
}
|
||||
|
||||
pcap_cleanup_live_common(p);
|
||||
pcapint_cleanup_live_common(p);
|
||||
}
|
||||
|
||||
/* Send a packet to the network */
|
||||
@ -917,7 +915,7 @@ static int TcRead(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
|
||||
/* No underlying filtering system. We need to filter on our own */
|
||||
if (p->fcode.bf_insns)
|
||||
{
|
||||
filterResult = pcap_filter(p->fcode.bf_insns, data, tcHeader.Length, tcHeader.CapturedLength);
|
||||
filterResult = pcapint_filter(p->fcode.bf_insns, data, tcHeader.Length, tcHeader.CapturedLength);
|
||||
|
||||
if (filterResult == 0)
|
||||
{
|
||||
|
@ -107,11 +107,12 @@ routine can be used after a
|
||||
call and before a
|
||||
.BR pcap_activate ()
|
||||
call to specify the type of time stamp to be used on the device.
|
||||
The time stamp types are listed here; the first value is the #define to
|
||||
use in code, the second value is the value returned by
|
||||
The time stamp types are listed here; the first value is the
|
||||
.B #define
|
||||
to use in code, the second value is the value returned by
|
||||
.BR pcap_tstamp_type_val_to_name (3PCAP)
|
||||
and accepted by
|
||||
.BR pcap_tstamp_type_name_to_val (3PCAP) .
|
||||
.BR pcap_tstamp_type_name_to_val (3PCAP).
|
||||
.RS 5
|
||||
.TP 5
|
||||
.BR PCAP_TSTAMP_HOST " - " host
|
||||
|
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that: (1) source code distributions
|
||||
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||
* distributions including binary code include the above copyright notice and
|
||||
* this paragraph in its entirety in the documentation or other materials
|
||||
* provided with the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following acknowledgement:
|
||||
* ``This product includes software developed by the University of California,
|
||||
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||
* the University nor the names of its contributors may be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* pcap-usb-linux-common.c - common code for everything that needs to
|
||||
* deal with Linux USB captures.
|
||||
*/
|
||||
|
||||
#include "pcap/pcap.h"
|
||||
#include "pcap/usb.h"
|
||||
|
||||
#include "pcap-usb-linux-common.h"
|
||||
|
||||
/*
|
||||
* Compute, from the data provided by the Linux USB memory-mapped capture
|
||||
* mechanism, the amount of packet data that would have been provided
|
||||
* had the capture mechanism not chopped off any data at the end, if, in
|
||||
* fact, it did so.
|
||||
*
|
||||
* Set the "unsliced length" field of the packet header to that value.
|
||||
*/
|
||||
void
|
||||
fix_linux_usb_mmapped_length(struct pcap_pkthdr *pkth, const u_char *bp)
|
||||
{
|
||||
const pcap_usb_header_mmapped *hdr;
|
||||
u_int bytes_left;
|
||||
|
||||
/*
|
||||
* All callers of this routine must ensure that pkth->caplen is
|
||||
* >= sizeof (pcap_usb_header_mmapped).
|
||||
*/
|
||||
bytes_left = pkth->caplen;
|
||||
bytes_left -= sizeof (pcap_usb_header_mmapped);
|
||||
|
||||
hdr = (const pcap_usb_header_mmapped *) bp;
|
||||
if (!hdr->data_flag && hdr->transfer_type == URB_ISOCHRONOUS &&
|
||||
hdr->event_type == URB_COMPLETE &&
|
||||
(hdr->endpoint_number & URB_TRANSFER_IN) &&
|
||||
pkth->len == sizeof(pcap_usb_header_mmapped) +
|
||||
(hdr->ndesc * sizeof (usb_isodesc)) + hdr->urb_len) {
|
||||
usb_isodesc *descs;
|
||||
u_int pre_truncation_data_len, pre_truncation_len;
|
||||
|
||||
descs = (usb_isodesc *) (bp + sizeof(pcap_usb_header_mmapped));
|
||||
|
||||
/*
|
||||
* We have data (yes, data_flag is 0 if we *do* have data),
|
||||
* and this is a "this is complete" incoming isochronous
|
||||
* transfer event, and the length was calculated based
|
||||
* on the URB length.
|
||||
*
|
||||
* That's not correct, because the data isn't contiguous,
|
||||
* and the isochronous descriptos show how it's scattered.
|
||||
*
|
||||
* Find the end of the last chunk of data in the buffer
|
||||
* referred to by the isochronous descriptors; that indicates
|
||||
* how far into the buffer the data would have gone.
|
||||
*
|
||||
* Make sure we don't run past the end of the captured data
|
||||
* while processing the isochronous descriptors.
|
||||
*/
|
||||
pre_truncation_data_len = 0;
|
||||
for (uint32_t desc = 0;
|
||||
desc < hdr->ndesc && bytes_left >= sizeof (usb_isodesc);
|
||||
desc++, bytes_left -= sizeof (usb_isodesc)) {
|
||||
u_int desc_end;
|
||||
|
||||
if (descs[desc].len != 0) {
|
||||
desc_end = descs[desc].offset + descs[desc].len;
|
||||
if (desc_end > pre_truncation_data_len)
|
||||
pre_truncation_data_len = desc_end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Now calculate the total length based on that data
|
||||
* length.
|
||||
*/
|
||||
pre_truncation_len = sizeof(pcap_usb_header_mmapped) +
|
||||
(hdr->ndesc * sizeof (usb_isodesc)) +
|
||||
pre_truncation_data_len;
|
||||
|
||||
/*
|
||||
* If that's greater than or equal to the captured length,
|
||||
* use that as the length.
|
||||
*/
|
||||
if (pre_truncation_len >= pkth->caplen)
|
||||
pkth->len = pre_truncation_len;
|
||||
|
||||
/*
|
||||
* If the captured length is greater than the length,
|
||||
* use the captured length.
|
||||
*
|
||||
* For completion events for incoming isochronous transfers,
|
||||
* it's based on data_len, which is calculated the same way
|
||||
* we calculated pre_truncation_data_len above, except that
|
||||
* it has access to all the isochronous descriptors, not
|
||||
* just the ones that the kernel were able to provide us or,
|
||||
* for a capture file, that weren't sliced off by a snapshot
|
||||
* length.
|
||||
*
|
||||
* However, it might have been reduced by the USB capture
|
||||
* mechanism arbitrarily limiting the amount of data it
|
||||
* provides to userland, or by the libpcap capture code
|
||||
* limiting it to being no more than the snapshot, so
|
||||
* we don't want to just use it all the time; we only
|
||||
* do so to try to get a better estimate of the actual
|
||||
* length - and to make sure the on-the-network length
|
||||
* is always >= the captured length.
|
||||
*/
|
||||
if (pkth->caplen > pkth->len)
|
||||
pkth->len = pkth->caplen;
|
||||
}
|
||||
}
|
@ -19,8 +19,109 @@
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* pcap-usb-linux-common.h - common code for everything that needs to
|
||||
* deal with Linux USB captures.
|
||||
* deal with Linux USB captures, whether live or in a capture file;
|
||||
* the later means that this is *not* Linux-only.
|
||||
*/
|
||||
|
||||
extern void fix_linux_usb_mmapped_length(struct pcap_pkthdr *pkth,
|
||||
const u_char *bp);
|
||||
#include <limits.h>
|
||||
|
||||
/*
|
||||
* Return the sum of the two u_int arguments if that sum fits in a u_int,
|
||||
* and return UINT_MAX otherwise.
|
||||
*/
|
||||
static inline u_int
|
||||
u_int_sum(u_int a, u_int b)
|
||||
{
|
||||
return (((b) <= UINT_MAX - (a)) ? (a) + (b) : UINT_MAX);
|
||||
}
|
||||
|
||||
/*
|
||||
* Is this a completion event for an isochronous transfer?
|
||||
*/
|
||||
static inline int
|
||||
is_isochronous_transfer_completion(const pcap_usb_header_mmapped *hdr)
|
||||
{
|
||||
return (hdr->transfer_type == URB_ISOCHRONOUS &&
|
||||
hdr->event_type == URB_COMPLETE &&
|
||||
(hdr->endpoint_number & URB_TRANSFER_IN));
|
||||
}
|
||||
|
||||
/*
|
||||
* Total length of the pseudo-header, including the isochronous
|
||||
* descriptors.
|
||||
*/
|
||||
static inline uint32_t
|
||||
iso_pseudo_header_len(const pcap_usb_header_mmapped *usb_hdr)
|
||||
{
|
||||
return (sizeof(pcap_usb_header_mmapped) +
|
||||
usb_hdr->ndesc * sizeof (usb_isodesc));
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the packet length for a "this is complete" incoming
|
||||
* isochronous transfer event.
|
||||
*
|
||||
* Calculating that from hdr->urb_len is not correct, because the
|
||||
* data is not contiguous, and the isochroous descriptors show how
|
||||
* it's scattered.
|
||||
*/
|
||||
static inline u_int
|
||||
incoming_isochronous_transfer_completed_len(struct pcap_pkthdr *phdr,
|
||||
const u_char *bp)
|
||||
{
|
||||
const pcap_usb_header_mmapped *hdr;
|
||||
u_int bytes_left;
|
||||
const usb_isodesc *descs;
|
||||
u_int pre_truncation_data_len;
|
||||
|
||||
/*
|
||||
* All callers of this routine must ensure that pkth->caplen is
|
||||
* >= sizeof (pcap_usb_header_mmapped).
|
||||
*/
|
||||
bytes_left = phdr->caplen;
|
||||
bytes_left -= sizeof (pcap_usb_header_mmapped);
|
||||
|
||||
hdr = (const pcap_usb_header_mmapped *) bp;
|
||||
descs = (const usb_isodesc *) (bp + sizeof(pcap_usb_header_mmapped));
|
||||
|
||||
/*
|
||||
* Find the end of the last chunk of data in the buffer
|
||||
* referred to by the isochronous descriptors; that indicates
|
||||
* how far into the buffer the data would have gone.
|
||||
*
|
||||
* Make sure we don't run past the end of the captured data
|
||||
* while processing the isochronous descriptors.
|
||||
*/
|
||||
pre_truncation_data_len = 0;
|
||||
for (uint32_t desc = 0;
|
||||
desc < hdr->ndesc && bytes_left >= sizeof (usb_isodesc);
|
||||
desc++, bytes_left -= sizeof (usb_isodesc)) {
|
||||
u_int desc_end;
|
||||
|
||||
if (descs[desc].len != 0) {
|
||||
/*
|
||||
* Compute the end offset of the data
|
||||
* for this descriptor, i.e. the offset
|
||||
* of the byte after the data. Clamp
|
||||
* the sum at UINT_MAX, so that it fits
|
||||
* in a u_int.
|
||||
*/
|
||||
desc_end = u_int_sum(descs[desc].offset,
|
||||
descs[desc].len);
|
||||
if (desc_end > pre_truncation_data_len)
|
||||
pre_truncation_data_len = desc_end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the sum of the total header length (memory-mapped
|
||||
* header and ISO descriptors) and the data length, clamped
|
||||
* to UINT_MAX.
|
||||
*
|
||||
* We've made sure that the number of descriptors is
|
||||
* <= USB_MAXDESC, so we know that the total size,
|
||||
* in bytes, of the descriptors fits in a 32-bit
|
||||
* integer.
|
||||
*/
|
||||
return (u_int_sum(iso_pseudo_header_len(hdr), pre_truncation_data_len));
|
||||
}
|
||||
|
@ -33,14 +33,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "pcap/usb.h"
|
||||
#include "pcap-int.h"
|
||||
#include "pcap-usb-linux.h"
|
||||
#include "pcap-usb-linux-common.h"
|
||||
#include "pcap/usb.h"
|
||||
|
||||
#include "extract.h"
|
||||
|
||||
@ -157,7 +155,7 @@ usb_dev_add(pcap_if_list_t *devlistp, int n, char *err_str)
|
||||
* "connected" vs. "disconnected", as that's a property
|
||||
* that would apply to a particular USB interface.
|
||||
*/
|
||||
if (add_dev(devlistp, dev_name,
|
||||
if (pcapint_add_dev(devlistp, dev_name,
|
||||
PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE,
|
||||
"Raw USB traffic, all USB buses", err_str) == NULL)
|
||||
return -1;
|
||||
@ -169,7 +167,7 @@ usb_dev_add(pcap_if_list_t *devlistp, int n, char *err_str)
|
||||
* PCAP_IF_CONNECTION_STATUS_DISCONNECTED?
|
||||
*/
|
||||
snprintf(dev_descr, 30, "Raw USB traffic, bus number %d", n);
|
||||
if (add_dev(devlistp, dev_name, 0, dev_descr, err_str) == NULL)
|
||||
if (pcapint_add_dev(devlistp, dev_name, 0, dev_descr, err_str) == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -254,7 +252,7 @@ usb_set_ring_size(pcap_t* handle, int header_size)
|
||||
|
||||
/*
|
||||
* Will this get an error?
|
||||
* (There's no wqy to query the minimum or maximum, so we just
|
||||
* (There's no way to query the minimum or maximum, so we just
|
||||
* copy the value from the kernel source. We don't round it
|
||||
* up to a multiple of the page size.)
|
||||
*/
|
||||
@ -277,7 +275,7 @@ usb_set_ring_size(pcap_t* handle, int header_size)
|
||||
}
|
||||
|
||||
if (ioctl(handle->fd, MON_IOCT_RING_SIZE, ring_size) == -1) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't set ring size from fd %d", handle->fd);
|
||||
return -1;
|
||||
}
|
||||
@ -482,11 +480,11 @@ usb_activate(pcap_t* handle)
|
||||
handle->linktype = DLT_USB_LINUX;
|
||||
|
||||
handle->inject_op = usb_inject_linux;
|
||||
handle->setfilter_op = install_bpf_program; /* no kernel filtering */
|
||||
handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
|
||||
handle->setdirection_op = usb_setdirection_linux;
|
||||
handle->set_datalink_op = NULL; /* can't change data link type */
|
||||
handle->getnonblock_op = pcap_getnonblock_fd;
|
||||
handle->setnonblock_op = pcap_setnonblock_fd;
|
||||
handle->getnonblock_op = pcapint_getnonblock_fd;
|
||||
handle->setnonblock_op = pcapint_setnonblock_fd;
|
||||
|
||||
/*get usb bus index from device name */
|
||||
if (sscanf(handle->opt.device, USB_IFACE"%d", &handlep->bus_index) != 1)
|
||||
@ -544,7 +542,7 @@ DIAG_ON_FORMAT_TRUNCATION
|
||||
/*
|
||||
* Something went wrong.
|
||||
*/
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno,
|
||||
"Can't open USB bus file %s", full_path);
|
||||
return PCAP_ERROR;
|
||||
@ -609,7 +607,7 @@ DIAG_ON_FORMAT_TRUNCATION
|
||||
* buffer */
|
||||
handle->buffer = malloc(handle->bufsize);
|
||||
if (!handle->buffer) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "malloc");
|
||||
close(handle->fd);
|
||||
return PCAP_ERROR;
|
||||
@ -645,7 +643,7 @@ usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
|
||||
ret = ioctl(handle->fd, MON_IOCG_STATS, &st);
|
||||
if (ret < 0)
|
||||
{
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't read stats from fd %d", handle->fd);
|
||||
return -1;
|
||||
}
|
||||
@ -688,7 +686,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets _U_, pcap_handler callback, u
|
||||
if (errno == EAGAIN)
|
||||
return 0; /* no data there */
|
||||
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't read from fd %d", handle->fd);
|
||||
return -1;
|
||||
}
|
||||
@ -717,14 +715,14 @@ usb_read_linux_bin(pcap_t *handle, int max_packets _U_, pcap_handler callback, u
|
||||
pkth.caplen = sizeof(pcap_usb_header) + clen;
|
||||
if (info.hdr->data_flag) {
|
||||
/*
|
||||
* No data; just base the on-the-wire length on
|
||||
* No data; just base the original length on
|
||||
* info.hdr->data_len (so that it's >= the captured
|
||||
* length).
|
||||
*/
|
||||
pkth.len = sizeof(pcap_usb_header) + info.hdr->data_len;
|
||||
} else {
|
||||
/*
|
||||
* We got data; base the on-the-wire length on
|
||||
* We got data; base the original length on
|
||||
* info.hdr->urb_len, so that it includes data
|
||||
* discarded by the USB monitor device due to
|
||||
* its buffer being too small.
|
||||
@ -735,7 +733,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets _U_, pcap_handler callback, u
|
||||
pkth.ts.tv_usec = info.hdr->ts_usec;
|
||||
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, handle->buffer,
|
||||
pcapint_filter(handle->fcode.bf_insns, handle->buffer,
|
||||
pkth.len, pkth.caplen)) {
|
||||
handlep->packets_read++;
|
||||
callback(user, &pkth, handle->buffer);
|
||||
@ -818,7 +816,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
|
||||
if (errno == EAGAIN)
|
||||
return 0; /* no data there */
|
||||
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf,
|
||||
PCAP_ERRBUF_SIZE, errno, "Can't mfetch fd %d",
|
||||
handle->fd);
|
||||
return -1;
|
||||
@ -877,34 +875,53 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
|
||||
pkth.caplen = sizeof(pcap_usb_header_mmapped) + clen;
|
||||
if (hdr->data_flag) {
|
||||
/*
|
||||
* No data; just base the on-the-wire length
|
||||
* No data; just base the original length
|
||||
* on hdr->data_len (so that it's >= the
|
||||
* captured length).
|
||||
* captured length). Clamp the result
|
||||
* at UINT_MAX, so it fits in an unsigned
|
||||
* int.
|
||||
*/
|
||||
pkth.len = sizeof(pcap_usb_header_mmapped) +
|
||||
hdr->data_len;
|
||||
pkth.len = u_int_sum(sizeof(pcap_usb_header_mmapped),
|
||||
hdr->data_len);
|
||||
} else {
|
||||
/*
|
||||
* We got data; base the on-the-wire length
|
||||
* on hdr->urb_len, so that it includes
|
||||
* data discarded by the USB monitor device
|
||||
* due to its buffer being too small.
|
||||
* We got data.
|
||||
*/
|
||||
pkth.len = sizeof(pcap_usb_header_mmapped) +
|
||||
(hdr->ndesc * sizeof (usb_isodesc)) + hdr->urb_len;
|
||||
|
||||
/*
|
||||
* Now clean it up if it's a completion
|
||||
* event for an incoming isochronous
|
||||
* transfer.
|
||||
*/
|
||||
fix_linux_usb_mmapped_length(&pkth, bp);
|
||||
if (is_isochronous_transfer_completion(hdr)) {
|
||||
/*
|
||||
* For isochronous transfer completion
|
||||
* events, hdr->urb_len doesn't take
|
||||
* into account the way the data is
|
||||
* put into the buffer, as it doesn't
|
||||
* count any padding between the
|
||||
* chunks of isochronous data, so
|
||||
* we have to calculate the amount
|
||||
* of data from the isochronous
|
||||
* descriptors.
|
||||
*/
|
||||
pkth.len = incoming_isochronous_transfer_completed_len(&pkth, bp);
|
||||
} else {
|
||||
/*
|
||||
* For everything else, the original
|
||||
* data length is just the length of
|
||||
* the memory-mapped Linux USB header
|
||||
* plus hdr->urb_len; we use
|
||||
* hdr->urb_len so that it includes
|
||||
* data discarded by the USB monitor
|
||||
* device due to its buffer being
|
||||
* too small. Clamp the result at
|
||||
* UINT_MAX, so it fits in an
|
||||
* unsigned int.
|
||||
*/
|
||||
pkth.len = u_int_sum(sizeof(pcap_usb_header_mmapped),
|
||||
hdr->urb_len);
|
||||
}
|
||||
}
|
||||
pkth.ts.tv_sec = (time_t)hdr->ts_sec;
|
||||
pkth.ts.tv_usec = hdr->ts_usec;
|
||||
|
||||
if (handle->fcode.bf_insns == NULL ||
|
||||
pcap_filter(handle->fcode.bf_insns, (u_char*) hdr,
|
||||
pcapint_filter(handle->fcode.bf_insns, (u_char*) hdr,
|
||||
pkth.len, pkth.caplen)) {
|
||||
handlep->packets_read++;
|
||||
callback(user, &pkth, (u_char*) hdr);
|
||||
@ -913,7 +930,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
|
||||
}
|
||||
|
||||
/*
|
||||
* If max_packets specifiesg "unlimited", we stop after
|
||||
* If max_packets specifies "unlimited", we stop after
|
||||
* the first chunk.
|
||||
*/
|
||||
if (PACKET_COUNT_IS_UNLIMITED(max_packets) ||
|
||||
@ -923,7 +940,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
|
||||
|
||||
/* flush pending events*/
|
||||
if (ioctl(handle->fd, MON_IOCH_MFLUSH, nflush) == -1) {
|
||||
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
|
||||
errno, "Can't mflush fd %d", handle->fd);
|
||||
return -1;
|
||||
}
|
||||
@ -940,5 +957,5 @@ usb_cleanup_linux_mmap(pcap_t* handle)
|
||||
munmap(handlep->mmapbuf, handlep->mmapbuflen);
|
||||
handlep->mmapbuf = NULL;
|
||||
}
|
||||
pcap_cleanup_live_common(handle);
|
||||
pcapint_cleanup_live_common(handle);
|
||||
}
|
||||
|
@ -18,26 +18,24 @@
|
||||
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* pcap-common.c - common code for pcap and pcapng files
|
||||
* pcap-util.c - common code for various files
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pcap-types.h>
|
||||
|
||||
#include "pcap/can_socketcan.h"
|
||||
#include "pcap/sll.h"
|
||||
#include "pcap/usb.h"
|
||||
#include "pcap/nflog.h"
|
||||
|
||||
#include "pcap-int.h"
|
||||
#include "extract.h"
|
||||
#include "pcap-usb-linux-common.h"
|
||||
|
||||
#include "pcap-util.h"
|
||||
|
||||
#include "pflog.h"
|
||||
#include "pcap/can_socketcan.h"
|
||||
#include "pcap/sll.h"
|
||||
#include "pcap/usb.h"
|
||||
#include "pcap/nflog.h"
|
||||
|
||||
/*
|
||||
* Most versions of the DLT_PFLOG pseudo-header have UID and PID fields
|
||||
@ -103,6 +101,80 @@ swap_pflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
pflhdr->rule_pid = SWAPLONG(pflhdr->rule_pid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Linux cooked capture packets with a protocol type of LINUX_SLL_P_CAN or
|
||||
* LINUX_SLL_P_CANFD have SocketCAN CAN classic/CAN FD headers in front
|
||||
* of the payload,with the CAN ID being in the byte order of the host
|
||||
* that wrote the packet, and Linux cooked capture packets with a protocol
|
||||
* type of LINUX_SLL_P_CANXL have SocketCAN CAN XL headers in front of the
|
||||
* payload with the protocol/VCID field, the payload length, and the
|
||||
* acceptance field in the byte order of the host that wrote the packet.
|
||||
*
|
||||
* When reading a Linux cooked capture packet, we need to check for those
|
||||
* packets and, if the byte order host that wrote the packet, as
|
||||
* indicated by the byte order of the pcap file or pcapng section
|
||||
* containing the packet, is the opposite of our byte order, convert
|
||||
* the header files to our byte order by byte-swapping them.
|
||||
*/
|
||||
static void
|
||||
swap_socketcan_header(uint16_t protocol, u_int caplen, u_int length,
|
||||
u_char *buf)
|
||||
{
|
||||
pcap_can_socketcan_hdr *hdrp;
|
||||
pcap_can_socketcan_xl_hdr *xl_hdrp;
|
||||
|
||||
switch (protocol) {
|
||||
|
||||
case LINUX_SLL_P_CAN:
|
||||
case LINUX_SLL_P_CANFD:
|
||||
/*
|
||||
* CAN classic/CAN FD packet; fix up the packet's header
|
||||
* by byte-swapping the CAN ID field.
|
||||
*/
|
||||
hdrp = (pcap_can_socketcan_hdr *)buf;
|
||||
if (caplen < (u_int) (offsetof(pcap_can_socketcan_hdr, can_id) + sizeof hdrp->can_id) ||
|
||||
length < (u_int) (offsetof(pcap_can_socketcan_hdr, can_id) + sizeof hdrp->can_id)) {
|
||||
/* Not enough data to have the can_id field */
|
||||
return;
|
||||
}
|
||||
hdrp->can_id = SWAPLONG(hdrp->can_id);
|
||||
break;
|
||||
|
||||
case LINUX_SLL_P_CANXL:
|
||||
/*
|
||||
* CAN XL packet; fix up the packet's header by
|
||||
* byte-swapping the priority/VCID field, the
|
||||
* payload length, and the acceptance field.
|
||||
*/
|
||||
xl_hdrp = (pcap_can_socketcan_xl_hdr *)buf;
|
||||
if (caplen < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, priority_vcid) + sizeof xl_hdrp->priority_vcid) ||
|
||||
length < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, priority_vcid) + sizeof xl_hdrp->priority_vcid)) {
|
||||
/* Not enough data to have the priority_vcid field */
|
||||
return;
|
||||
}
|
||||
xl_hdrp->priority_vcid = SWAPLONG(xl_hdrp->priority_vcid);
|
||||
if (caplen < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, payload_length) + sizeof xl_hdrp->payload_length) ||
|
||||
length < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, payload_length) + sizeof xl_hdrp->payload_length)) {
|
||||
/* Not enough data to have the payload_length field */
|
||||
return;
|
||||
}
|
||||
xl_hdrp->payload_length = SWAPSHORT(xl_hdrp->payload_length);
|
||||
if (caplen < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, acceptance_field) + sizeof xl_hdrp->acceptance_field) ||
|
||||
length < (u_int) (offsetof(pcap_can_socketcan_xl_hdr, acceptance_field) + sizeof xl_hdrp->acceptance_field)) {
|
||||
/* Not enough data to have the acceptance_field field */
|
||||
return;
|
||||
}
|
||||
xl_hdrp->acceptance_field = SWAPLONG(xl_hdrp->acceptance_field);
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
* Not a CAN packet; nothing to do.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DLT_LINUX_SLL packets with a protocol type of LINUX_SLL_P_CAN or
|
||||
* LINUX_SLL_P_CANFD have SocketCAN headers in front of the payload,
|
||||
@ -113,13 +185,11 @@ swap_pflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
* wrote the file to this host's byte order.
|
||||
*/
|
||||
static void
|
||||
swap_linux_sll_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
swap_linux_sll_socketcan_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
{
|
||||
u_int caplen = hdr->caplen;
|
||||
u_int length = hdr->len;
|
||||
struct sll_header *shdr = (struct sll_header *)buf;
|
||||
uint16_t protocol;
|
||||
pcap_can_socketcan_hdr *chdr;
|
||||
|
||||
if (caplen < (u_int) sizeof(struct sll_header) ||
|
||||
length < (u_int) sizeof(struct sll_header)) {
|
||||
@ -127,33 +197,24 @@ swap_linux_sll_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
return;
|
||||
}
|
||||
|
||||
protocol = EXTRACT_BE_U_2(&shdr->sll_protocol);
|
||||
if (protocol != LINUX_SLL_P_CAN && protocol != LINUX_SLL_P_CANFD)
|
||||
return;
|
||||
|
||||
/*
|
||||
* SocketCAN packet; fix up the packet's header.
|
||||
* Byte-swap what needs to be byte-swapped.
|
||||
*/
|
||||
chdr = (pcap_can_socketcan_hdr *)(buf + sizeof(struct sll_header));
|
||||
if (caplen < (u_int) sizeof(struct sll_header) + sizeof(chdr->can_id) ||
|
||||
length < (u_int) sizeof(struct sll_header) + sizeof(chdr->can_id)) {
|
||||
/* Not enough data to have the CAN ID */
|
||||
return;
|
||||
}
|
||||
chdr->can_id = SWAPLONG(chdr->can_id);
|
||||
swap_socketcan_header(EXTRACT_BE_U_2(&shdr->sll_protocol),
|
||||
caplen - (u_int) sizeof(struct sll_header),
|
||||
length - (u_int) sizeof(struct sll_header),
|
||||
buf + sizeof(struct sll_header));
|
||||
}
|
||||
|
||||
/*
|
||||
* The same applies for DLT_LINUX_SLL2.
|
||||
*/
|
||||
static void
|
||||
swap_linux_sll2_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
swap_linux_sll2_socketcan_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
{
|
||||
u_int caplen = hdr->caplen;
|
||||
u_int length = hdr->len;
|
||||
struct sll2_header *shdr = (struct sll2_header *)buf;
|
||||
uint16_t protocol;
|
||||
pcap_can_socketcan_hdr *chdr;
|
||||
|
||||
if (caplen < (u_int) sizeof(struct sll2_header) ||
|
||||
length < (u_int) sizeof(struct sll2_header)) {
|
||||
@ -161,20 +222,13 @@ swap_linux_sll2_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
return;
|
||||
}
|
||||
|
||||
protocol = EXTRACT_BE_U_2(&shdr->sll2_protocol);
|
||||
if (protocol != LINUX_SLL_P_CAN && protocol != LINUX_SLL_P_CANFD)
|
||||
return;
|
||||
|
||||
/*
|
||||
* SocketCAN packet; fix up the packet's header.
|
||||
* Byte-swap what needs to be byte-swapped.
|
||||
*/
|
||||
chdr = (pcap_can_socketcan_hdr *)(buf + sizeof(struct sll2_header));
|
||||
if (caplen < (u_int) sizeof(struct sll2_header) + sizeof(chdr->can_id) ||
|
||||
length < (u_int) sizeof(struct sll2_header) + sizeof(chdr->can_id)) {
|
||||
/* Not enough data to have the CAN ID */
|
||||
return;
|
||||
}
|
||||
chdr->can_id = SWAPLONG(chdr->can_id);
|
||||
swap_socketcan_header(EXTRACT_BE_U_2(&shdr->sll2_protocol),
|
||||
caplen - (u_int) sizeof(struct sll2_header),
|
||||
length - (u_int) sizeof(struct sll2_header),
|
||||
buf + sizeof(struct sll2_header));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -344,7 +398,7 @@ swap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
|
||||
nflog_tlv_t *tlv;
|
||||
u_int caplen = hdr->caplen;
|
||||
u_int length = hdr->len;
|
||||
uint16_t size;
|
||||
u_int size;
|
||||
|
||||
if (caplen < (u_int) sizeof(nflog_hdr_t) ||
|
||||
length < (u_int) sizeof(nflog_hdr_t)) {
|
||||
@ -407,11 +461,11 @@ swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
|
||||
break;
|
||||
|
||||
case DLT_LINUX_SLL:
|
||||
swap_linux_sll_header(hdr, data);
|
||||
swap_linux_sll_socketcan_header(hdr, data);
|
||||
break;
|
||||
|
||||
case DLT_LINUX_SLL2:
|
||||
swap_linux_sll2_header(hdr, data);
|
||||
swap_linux_sll2_socketcan_header(hdr, data);
|
||||
break;
|
||||
|
||||
case DLT_USB_LINUX:
|
||||
@ -428,47 +482,146 @@ swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
packet_length_might_be_wrong(struct pcap_pkthdr *hdr,
|
||||
const pcap_usb_header_mmapped *usb_hdr)
|
||||
{
|
||||
uint32_t old_style_packet_length;
|
||||
|
||||
/*
|
||||
* Calculate the packet length the old way.
|
||||
* We know that the multiplication won't overflow, but
|
||||
* we don't know that the additions won't. Calculate
|
||||
* it with no overflow checks, as that's how it
|
||||
* would have been calculated when it was captured.
|
||||
*/
|
||||
old_style_packet_length = iso_pseudo_header_len(usb_hdr) +
|
||||
usb_hdr->urb_len;
|
||||
return (hdr->len == old_style_packet_length);
|
||||
}
|
||||
|
||||
void
|
||||
pcap_post_process(int linktype, int swapped, struct pcap_pkthdr *hdr,
|
||||
pcapint_post_process(int linktype, int swapped, struct pcap_pkthdr *hdr,
|
||||
u_char *data)
|
||||
{
|
||||
if (swapped)
|
||||
swap_pseudo_headers(linktype, hdr, data);
|
||||
|
||||
fixup_pcap_pkthdr(linktype, hdr, data);
|
||||
}
|
||||
|
||||
void
|
||||
fixup_pcap_pkthdr(int linktype, struct pcap_pkthdr *hdr, const u_char *data)
|
||||
{
|
||||
const pcap_usb_header_mmapped *usb_hdr;
|
||||
|
||||
usb_hdr = (const pcap_usb_header_mmapped *) data;
|
||||
if (linktype == DLT_USB_LINUX_MMAPPED &&
|
||||
hdr->caplen >= sizeof (pcap_usb_header_mmapped)) {
|
||||
/*
|
||||
* Is this a memory-mapped Linux USB capture?
|
||||
*/
|
||||
if (linktype == DLT_USB_LINUX_MMAPPED) {
|
||||
/*
|
||||
* In older versions of libpcap, in memory-mapped captures,
|
||||
* the "on-the-bus length" for completion events for
|
||||
* incoming isochronous transfers was miscalculated; it
|
||||
* needed to be calculated based on the* offsets and lengths
|
||||
* in the descriptors, not on the raw URB length, but it
|
||||
* wasn't.
|
||||
* Yes.
|
||||
*
|
||||
* In older versions of libpcap, in memory-mapped Linux
|
||||
* USB captures, the original length of completion events
|
||||
* for incoming isochronous transfers was miscalculated;
|
||||
* it needed to be calculated based on the offsets and
|
||||
* lengths in the descriptors, not on the raw URB length,
|
||||
* but it wasn't.
|
||||
*
|
||||
* If this packet contains transferred data (yes, data_flag
|
||||
* is 0 if we *do* have data), and the total on-the-network
|
||||
* length is equal to the value calculated from the raw URB
|
||||
* length, then it might be one of those transfers.
|
||||
* is 0 if we *do* have data), it's a completion event
|
||||
* for an incoming isochronous transfer, and the
|
||||
* transfer length appears to have been calculated
|
||||
* from the raw URB length, fix it.
|
||||
*
|
||||
* We only do this if we have the full USB pseudo-header.
|
||||
* We only do this if we have the full USB pseudo-header,
|
||||
* because we will have to look at that header and at
|
||||
* all of the isochronous descriptors.
|
||||
*/
|
||||
if (!usb_hdr->data_flag &&
|
||||
hdr->len == sizeof(pcap_usb_header_mmapped) +
|
||||
(usb_hdr->ndesc * sizeof (usb_isodesc)) + usb_hdr->urb_len) {
|
||||
if (hdr->caplen < sizeof (pcap_usb_header_mmapped)) {
|
||||
/*
|
||||
* It might need fixing; fix it if it's a completion
|
||||
* event for an incoming isochronous transfer.
|
||||
* We don't have the full pseudo-header.
|
||||
*/
|
||||
fix_linux_usb_mmapped_length(hdr, data);
|
||||
return;
|
||||
}
|
||||
|
||||
const pcap_usb_header_mmapped *usb_hdr =
|
||||
(const pcap_usb_header_mmapped *) data;
|
||||
|
||||
/*
|
||||
* Make sure the number of descriptors is sane.
|
||||
*
|
||||
* The Linux binary USB monitor code limits the number of
|
||||
* isochronous descriptors to 128; if the number in the file
|
||||
* is larger than that, either 1) the file's been damaged
|
||||
* or 2) the file was produced after the number was raised
|
||||
* in the kernel.
|
||||
*
|
||||
* In case 1), the number can't be trusted, so don't rely on
|
||||
* it to attempt to fix the original length field in the pcap
|
||||
* or pcapng header.
|
||||
*
|
||||
* In case 2), the system was probably running a version of
|
||||
* libpcap that didn't miscalculate the original length, so
|
||||
* it probably doesn't need to be fixed.
|
||||
*
|
||||
* This avoids the possibility of the product of the number of
|
||||
* descriptors and the size of descriptors won't overflow an
|
||||
* unsigned 32-bit integer.
|
||||
*/
|
||||
if (usb_hdr->ndesc > USB_MAXDESC)
|
||||
return;
|
||||
|
||||
if (!usb_hdr->data_flag &&
|
||||
is_isochronous_transfer_completion(usb_hdr) &&
|
||||
packet_length_might_be_wrong(hdr, usb_hdr)) {
|
||||
u_int len;
|
||||
|
||||
/*
|
||||
* Make sure we have all of the descriptors,
|
||||
* as we will have to look at all of them.
|
||||
*
|
||||
* If not, we don't bother trying to fix
|
||||
* anything.
|
||||
*/
|
||||
if (hdr->caplen < iso_pseudo_header_len(usb_hdr))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Calculate what the length should have been.
|
||||
*/
|
||||
len = incoming_isochronous_transfer_completed_len(hdr,
|
||||
data);
|
||||
|
||||
/*
|
||||
* len is the smaller of UINT_MAX and the total
|
||||
* header plus data length. That's guaranteed
|
||||
* to fit in a UINT_MAX.
|
||||
*
|
||||
* Don't reduce the original length to a value
|
||||
* below the captured length, however, as that
|
||||
* is bogus.
|
||||
*/
|
||||
if (len >= hdr->caplen)
|
||||
hdr->len = len;
|
||||
|
||||
/*
|
||||
* If the captured length is greater than the
|
||||
* length, use the captured length.
|
||||
*
|
||||
* For completion events for incoming isochronous
|
||||
* transfers, it's based on data_len, which is
|
||||
* calculated the same way we calculated
|
||||
* pre_truncation_data_len above, except that
|
||||
* it has access to all the isochronous descriptors,
|
||||
* not just the ones that the kernel were able to
|
||||
* provide us or, for a capture file, that weren't
|
||||
* sliced off by a snapshot length.
|
||||
*
|
||||
* However, it might have been reduced by the USB
|
||||
* capture mechanism arbitrarily limiting the amount
|
||||
* of data it provides to userland, or by the libpcap
|
||||
* capture code limiting it to being no more than the
|
||||
* snapshot, so we don't want to just use it all the
|
||||
* time; we only do so to try to get a better estimate
|
||||
* of the actual length - and to make sure the
|
||||
* original length is always >= the captured length.
|
||||
*/
|
||||
if (hdr->caplen > hdr->len)
|
||||
hdr->len = hdr->caplen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +47,5 @@
|
||||
((u_short)(((((u_int)(y))&0xff)<<8) | \
|
||||
((((u_int)(y))&0xff00)>>8)))
|
||||
|
||||
extern void pcap_post_process(int linktype, int swapped,
|
||||
extern void pcapint_post_process(int linktype, int swapped,
|
||||
struct pcap_pkthdr *hdr, u_char *data);
|
||||
|
||||
extern void fixup_pcap_pkthdr(int linktype, struct pcap_pkthdr *hdr,
|
||||
const u_char *data);
|
||||
|
||||
|
@ -598,35 +598,35 @@ The callback for
|
||||
and
|
||||
.BR pcap_loop ()
|
||||
is supplied a pointer to a
|
||||
.IR "struct pcap_pkthdr" ,
|
||||
.BR "struct pcap_pkthdr" ,
|
||||
which includes the following members:
|
||||
.RS
|
||||
.TP
|
||||
.B ts
|
||||
a
|
||||
.I struct timeval
|
||||
.B struct timeval
|
||||
containing the time when the packet was captured
|
||||
.TP
|
||||
.B caplen
|
||||
a
|
||||
.I bpf_u_int32
|
||||
.B bpf_u_int32
|
||||
giving the number of bytes of the packet that are available from the
|
||||
capture
|
||||
.TP
|
||||
.B len
|
||||
a
|
||||
.I bpf_u_int32
|
||||
.B bpf_u_int32
|
||||
giving the length of the packet, in bytes (which might be more than the
|
||||
number of bytes available from the capture, if the length of the packet
|
||||
is larger than the maximum number of bytes to capture).
|
||||
.RE
|
||||
.PP
|
||||
The callback is also supplied a
|
||||
.I const u_char
|
||||
.B const u_char
|
||||
pointer to the first
|
||||
.B caplen
|
||||
(as given in the
|
||||
.I struct pcap_pkthdr
|
||||
.B struct pcap_pkthdr
|
||||
mentioned above)
|
||||
bytes of data from the packet. This won't necessarily be the entire
|
||||
packet; to capture the entire packet, you will have to provide a value
|
||||
@ -641,10 +641,10 @@ performed will limit the amount of packet data available.
|
||||
.PP
|
||||
.BR pcap_next ()
|
||||
is passed an argument that points to a
|
||||
.I struct pcap_pkthdr
|
||||
.B struct pcap_pkthdr
|
||||
structure, and fills it in with the time stamp and length values for the
|
||||
packet. It returns a
|
||||
.I const u_char
|
||||
.B const u_char *
|
||||
to the first
|
||||
.B caplen
|
||||
bytes of the packet on success, and
|
||||
@ -653,11 +653,11 @@ on error.
|
||||
.PP
|
||||
.BR pcap_next_ex ()
|
||||
is passed two pointer arguments, one of which points to a
|
||||
.IR struct pcap_pkthdr *
|
||||
and one of which points to a
|
||||
.IR "const u_char" *.
|
||||
.B struct pcap_pkthdr *
|
||||
and the other points to a
|
||||
.BR "const u_char *" .
|
||||
It sets the first pointer to point to a
|
||||
.I struct pcap_pkthdr
|
||||
.B struct pcap_pkthdr
|
||||
structure with the time stamp and length values for the packet, and sets
|
||||
the second pointer to point to the first
|
||||
.B caplen
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -42,8 +42,8 @@
|
||||
#include <pcap/pcap-inttypes.h>
|
||||
|
||||
/*
|
||||
* SocketCAN header, as per Documentation/networking/can.txt in the
|
||||
* Linux source.
|
||||
* SocketCAN header for CAN and CAN FD frames, as per
|
||||
* Documentation/networking/can.rst in the Linux source.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t can_id;
|
||||
@ -58,4 +58,25 @@ typedef struct {
|
||||
#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
|
||||
#define CANFD_FDF 0x04 /* mark CAN FD for dual use of CAN format */
|
||||
|
||||
/*
|
||||
* SocketCAN header for CAN XL frames, as per Linux's can.h header.
|
||||
* This is different from pcap_can_socketcan_hdr; the flags field
|
||||
* overlaps with the payload_length field in pcap_can_socketcan_hdr -
|
||||
* the payload_length field in a CAN or CAN FD frame never has the
|
||||
* 0x80 bit set, and the flags field in a CAN XL frame always has
|
||||
* it set, allowing code reading the frame to determine whether
|
||||
* it's CAN XL or not.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t priority_vcid;
|
||||
uint8_t flags;
|
||||
uint8_t sdu_type;
|
||||
uint16_t payload_length;
|
||||
uint32_t acceptance_field;
|
||||
} pcap_can_socketcan_xl_hdr;
|
||||
|
||||
/* Bits in the flags field */
|
||||
#define CANXL_SEC 0x01 /* Simple Extended Context */
|
||||
#define CANXL_XLF 0x80 /* mark to distinguish CAN XL from CAN/CAN FD frames */
|
||||
|
||||
#endif
|
||||
|
@ -58,7 +58,12 @@
|
||||
/*
|
||||
* These are the types that are the same on all platforms, and that
|
||||
* have been defined by <net/bpf.h> for ages.
|
||||
*
|
||||
* DLT_LOW_MATCHING_MIN is the lowest such value; DLT_LOW_MATCHING_MAX
|
||||
* is the highest such value.
|
||||
*/
|
||||
#define DLT_LOW_MATCHING_MIN 0
|
||||
|
||||
#define DLT_NULL 0 /* BSD loopback encapsulation */
|
||||
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
|
||||
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
|
||||
@ -71,6 +76,25 @@
|
||||
#define DLT_PPP 9 /* Point-to-point Protocol */
|
||||
#define DLT_FDDI 10 /* FDDI */
|
||||
|
||||
/*
|
||||
* In case the code that includes this file (directly or indirectly)
|
||||
* has also included OS files that happen to define DLT_LOW_MATCHING_MAX,
|
||||
* with a different value (perhaps because that OS hasn't picked up
|
||||
* the latest version of our DLT definitions), we undefine the
|
||||
* previous value of DLT_LOW_MATCHING_MAX.
|
||||
*
|
||||
* (They shouldn't, because only those 10 values were assigned in
|
||||
* the Good Old Days, before DLT_ code assignment became a bit of
|
||||
* a free-for-all. Perhaps 11 is DLT_ATM_RFC1483 everywhere 11
|
||||
* is used at all, but 12 is DLT_RAW on some platforms but not
|
||||
* OpenBSD, and the fun continues for several other values.)
|
||||
*/
|
||||
#ifdef DLT_LOW_MATCHING_MAX
|
||||
#undef DLT_LOW_MATCHING_MAX
|
||||
#endif
|
||||
|
||||
#define DLT_LOW_MATCHING_MAX DLT_FDDI /* highest value in this "matching" range */
|
||||
|
||||
/*
|
||||
* These are types that are different on some platforms, and that
|
||||
* have been defined by <net/bpf.h> for ages. We use #ifdefs to
|
||||
@ -78,7 +102,9 @@
|
||||
* libpcap <net/bpf.h>
|
||||
*
|
||||
* XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS,
|
||||
* but I don't know what the right #define is for BSD/OS.
|
||||
* but I don't know what the right #define is for BSD/OS. The last
|
||||
* release was in October 2003; if anybody cares about making this
|
||||
* work on BSD/OS, give us a pull request for a change to make it work.
|
||||
*/
|
||||
#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */
|
||||
|
||||
@ -186,12 +212,10 @@
|
||||
* anything and doesn't appear to have ever used it for anything.)
|
||||
*
|
||||
* We define it as 18 on those platforms; it is, unfortunately, used
|
||||
* for DLT_CIP in Suse 6.3, so we don't define it as DLT_PFSYNC
|
||||
* in general. As the packet format for it, like that for
|
||||
* DLT_PFLOG, is not only OS-dependent but OS-version-dependent,
|
||||
* we don't support printing it in tcpdump except on OSes that
|
||||
* have the relevant header files, so it's not that useful on
|
||||
* other platforms.
|
||||
* for DLT_CIP in SUSE 6.3, so we don't define it as 18 on all
|
||||
* platforms. We define it as 121 on FreeBSD and as the same
|
||||
* value that we assigned to LINKTYPE_PFSYNC on all remaining
|
||||
* platforms.
|
||||
*/
|
||||
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
||||
#define DLT_PFSYNC 18
|
||||
@ -236,10 +260,10 @@
|
||||
* and the LINKTYPE_ value that appears in capture files, are the
|
||||
* same.
|
||||
*
|
||||
* DLT_MATCHING_MIN is the lowest such value; DLT_MATCHING_MAX is
|
||||
* DLT_HIGH_MATCHING_MIN is the lowest such value; DLT_HIGH_MATCHING_MAX is
|
||||
* the highest such value.
|
||||
*/
|
||||
#define DLT_MATCHING_MIN 104
|
||||
#define DLT_HIGH_MATCHING_MIN 104
|
||||
|
||||
/*
|
||||
* This value was defined by libpcap 0.5; platforms that have defined
|
||||
@ -1019,9 +1043,9 @@
|
||||
#define DLT_AOS 222
|
||||
|
||||
/*
|
||||
* Wireless HART (Highway Addressable Remote Transducer)
|
||||
* WirelessHART (Highway Addressable Remote Transducer)
|
||||
* From the HART Communication Foundation
|
||||
* IES/PAS 62591
|
||||
* IEC/PAS 62591
|
||||
*
|
||||
* Requested by Sam Roberts <vieuxtech@gmail.com>.
|
||||
*/
|
||||
@ -1556,33 +1580,14 @@
|
||||
|
||||
/*
|
||||
* In case the code that includes this file (directly or indirectly)
|
||||
* has also included OS files that happen to define DLT_MATCHING_MAX,
|
||||
* has also included OS files that happen to define DLT_HIGH_MATCHING_MAX,
|
||||
* with a different value (perhaps because that OS hasn't picked up
|
||||
* the latest version of our DLT definitions), we undefine the
|
||||
* previous value of DLT_MATCHING_MAX.
|
||||
* previous value of DLT_HIGH_MATCHING_MAX.
|
||||
*/
|
||||
#ifdef DLT_MATCHING_MAX
|
||||
#undef DLT_MATCHING_MAX
|
||||
#ifdef DLT_HIGH_MATCHING_MAX
|
||||
#undef DLT_HIGH_MATCHING_MAX
|
||||
#endif
|
||||
#define DLT_MATCHING_MAX 289 /* highest value in the "matching" range */
|
||||
|
||||
/*
|
||||
* DLT and savefile link type values are split into a class and
|
||||
* a member of that class. A class value of 0 indicates a regular
|
||||
* DLT_/LINKTYPE_ value.
|
||||
*/
|
||||
#define DLT_CLASS(x) ((x) & 0x03ff0000)
|
||||
|
||||
/*
|
||||
* NetBSD-specific generic "raw" link type. The class value indicates
|
||||
* that this is the generic raw type, and the lower 16 bits are the
|
||||
* address family we're dealing with. Those values are NetBSD-specific;
|
||||
* do not assume that they correspond to AF_ values for your operating
|
||||
* system.
|
||||
*/
|
||||
#define DLT_CLASS_NETBSD_RAWAF 0x02240000
|
||||
#define DLT_NETBSD_RAWAF(af) (DLT_CLASS_NETBSD_RAWAF | (af))
|
||||
#define DLT_NETBSD_RAWAF_AF(x) ((x) & 0x0000ffff)
|
||||
#define DLT_IS_NETBSD_RAWAF(x) (DLT_CLASS(x) == DLT_CLASS_NETBSD_RAWAF)
|
||||
#define DLT_HIGH_MATCHING_MAX 289 /* highest value in the "matching" range */
|
||||
|
||||
#endif /* !defined(lib_pcap_dlt_h) */
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user