aboutsummaryrefslogtreecommitdiff
path: root/pcap-tc.c
Commit message (Collapse)AuthorAgeFilesLines
* If we can't allocate a DLT_ list, fail.Guy Harris2023-06-241-7/+7
| | | | | | | | Some code already was doing that (for example, pcap-bpf.c if fetching the DLT list with an ioctl), and, if you can't allocate a DLT_ list, which is usually pretty small, you may have other memory allocation problems later, so letting the program open an interface (and not get a correct list of all link-layer types supported) may not be worth it.
* Prefix routines declared in pcap-int.h with pcap_.Guy Harris2023-05-261-2/+2
| | | | | This avoids potential and, in one case (SIMH), actual collisions with names in other libraries or in applications using libpcap.
* Fix some typosFrancois-Xavier Le Bail2022-12-241-1/+1
| | | | [skip ci]
* TurboCap: Use "%d" to print a signed intFrancois-Xavier Le Bail2022-03-011-1/+1
| | | | | | | | | | Fix this cppcheck warning: pcap-tc.c:1127:3: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint] snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Mode %u not supported by TurboCap devices. TurboCap only supports capture.", mode); ^
* Handle the pcap_t+private data in a fashion that makes fewer assumptions.Guy Harris2020-07-011-1/+1
| | | | | | | | | | | | | | | The sizeof operator and alignof macro can be given a type "name" that's anonymous, e.g. sizeof(struct { int a; char *b; }). Have pcap_create_common() and pcap_open_offline_common() take, as arguments, the total size of a structure containing both the pcap_t and the private data as members, and the offset of the private data in that structure, and define macros that calculate those given, as an argument, the data type of the private data. This avoids making assumptions about the alignment of those two items within the structure; that *might* fix GitHub issue #940 if the issue is that the ARM compiler being used does 16-byte alignment of the private structure, rather than the 8-byte alignment we were wiring in.
* Support AirPcap devices with a pcap module.Guy Harris2020-05-071-73/+21
| | | | | | | | This allows us to update the support for newer APIs in the future - and in the present, with pcap_set_datalink() - and would allow Npcap to remove its AirPcap support. Add another test program, while we're at it.
* Remove some workarounds for old compilers.Guy Harris2019-08-091-27/+27
| | | | | | | | | | | | | Require Visual Studio 2015 or later; fail if we don't have it, and remove checks for older versions. That means we have C99-compliant snprintf() and vsnprintf(); require them when configuring for UN*X, and then use them directly, rather than having wrappers for systems lacking them. If we're using MSVC, skip the tests for options to request C99 compatibility - either we have VS 2015, which is sufficient, or we don't, in which case we fail.
* Just use install_bpf_program as the setfilter operation.Guy Harris2018-12-231-23/+1
| | | | | That's how to do it for modules that do filtering in the module itself; there's no need for a wrapper.
* Fix compile errors.Gisle Vanem2018-12-051-19/+4
| | | | Should fix GitHub issue #764.
* Clean up the declaration of the packet-filtering routines.Guy Harris2018-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If net/bpf.h declares bpf_filter() one way and libpcap defines it another way, even pcap-bpf.c needs a declaration that matches how libpcap defines it, not how net/bpf.h (mistakenly) declares it. ("Mistakenly" because it should *not* be declaring the kernel's version of bpf_filter() unless it's being used in a *kernel* build; other *BSDs, and macOS, declare it only in kernel builds by testing for a #define such as KERNEL or KERNEL_PRIVATE, but NetBSD doesn't - it *should*, but it doesn't.) So we rename the internal-to-pcap filtering routine as pcap_filter(), which is not exported from libpcap, and have bpf_filter() be a wrapper around pcap_filter() that is exported. Use pcap_filter(), rather than bpf_filter(), for all filtering inside libpcap (except for filtering that uses bpf_filter_with_aux_data(), which we rename pcap_filter_with_aux_data()). Do the same for bpf_validate(), which is *also* declared in net/bpf.h, even for non-kernel builds, in NetBSD. As we're not exporting pcap_filter_with_aux_data(), don't even *declare* it in a public header; don't declare struct bpf_aux_data in a public header, either. That way we can change it without worrying about breaking APIs or ABIs; we may do that if, for example, we want to support the "inbound" and "outbound" filters when reading pcapng files, adding a direction indicator to that structure. Declare bpf_filter() in pcap/bpf.h even on NetBSD and QNX; pcap-bpf.c doesn't include pcap/bpf.h (it sets a #define to force pcap/pcap.h not to include it), so we won't get any collisions if net/bpf.h (which it does include) declares it. The only collisions will occur in programs that include *both* pcap/pcap.h or pcap/bpf.h *and* net/bpf.h, and that will occur only if net/bpf.h declares bpf_filter() even when building userland code, and the correct fix for *that* is to fix net/bpf.h not to declare them in non-kernel builds.
* Don't set errbuf if install_bpf_program() has returned -1.Guy Harris2017-11-191-2/+0
| | | | | install_bpf_program() already fills in the errbuf; there's no need to set it in the caller of install_bpf_program().
* Add a routine to format error messages with an errno-based message at the end.Guy Harris2017-11-151-2/+2
| | | | | | | | | | | | | | That routine will use strerror_s() or strerror_r() if available, in a fashion that's thread-safe. Otherwise, it falls back on pcap_strerror(). Use it in both libpcap and rpcapd. Given that we check for errors in strerror_r(), hopefully this will squelch warnings with newer version of GCC and GNU libc; whilst the macOS (and other BSD-flavored?) strerror_r() always fills in a message, that's not required by the Single UNIX Specification, as far as I can tell, so we apparently really *do* need to check for errors.
* Call the flag to enable remote capture ENABLE_REMOTE.Guy Harris2017-10-031-2/+2
| | | | | | HAVE_REMOTE implies that there's some feature in our build environment that we have, but this is a flag that controls what the user specified at configuration time.
* Explain why we need a TcSetDatalink() routine.Guy Harris2017-10-021-1/+5
|
* Improve a comment.Guy Harris2017-10-011-1/+5
| | | | Make it clearer why we have a set_datalink_op that just says "OK".
* Clean up handling of non-blocking mode.Guy Harris2017-10-011-7/+14
| | | | | | | Clean up the error messages (and indentation) a bit. Catch attempts to get non-blocking mode before we're activated, just as we do after it's activate.
* Always include <config.h> rather than "config.h".Guy Harris2017-08-181-1/+1
| | | | | | | | This can prevent bizarre failures if, for example, you've done a configuration in the top-level source directory, leaving behind one config.h file, and then do an out-of-tree build in another directory, with different configuration options. This way, we always pick up the same config.h, in the build directory.
* Make the checks and adjustment of the snapshot length module-dependent.Guy Harris2017-06-011-0/+11
| | | | | | | | | | | | | Also, initialize the snapshot length to 0, meaning "not specified", so that the default snapshot length, if not specified, is also module-dependent. That way, D-Bus has a maximum and default of 128MB, as that's the maximum message size, but other capture devices have the current MAXIMUM_SNAPLEN, so we can handle full-size D-Bus messages without advertising an overly-large snapshot length for other devices, potentially causing libpcap and programs using it or reading libpcap files to allocate overly-large buffers for other capture devices.
* Support setting non-blocking mode before activating.Guy Harris2017-02-251-8/+5
| | | | | | | | | | | | | | | | | | We just set a flag and attempt to set non-blocking mode after activating. If a module can't support non-blocking mode, it should set the set non-blocking operator in the create routine, so a pre-activation call will fail the same way a post-activation call fails. While we're at it: Have the get non-blocking and set non-blocking modes not take an error buffer as an argument; they have the error buffer in the pcap_t to set. pcap_getnonblock() and pcap_setnonblock() just copy the error from there to the argument passed in. Make sure we set the cleanup op pointer when appropriate.
* Update for the new "list of devices" structure.Guy Harris2017-01-181-4/+6
|
* Don't set non-existent structure members.Guy Harris2016-10-271-1/+1
| | | | | ps_capt, ps_sent, and ps_netdrop are only available on Windows if HAVE_REMOTE is defined; don't set them otherwise.
* make more pcap_create_common() fixesDenis Ovsienko2016-06-301-1/+1
| | | | | | | | | * CAN bus over USB on Linux * DAG * D-Bus * Septel * SNF * TurboCap
* Rename opt.source to opt.device.Guy Harris2016-06-291-1/+1
| | | | | | | For local captures, it's jut the device. If we add remote capture support, we'll be handed a URL, and will split the URL into multiple components, and will store the various components in the opt structure, with the path of the URL being opt.device.
* Update variable names and comments to reflect the previous change.Guy Harris2016-06-041-4/+4
| | | | | | | The last argument to pcap_oid_get_request() and pcap_oid_set_request() is a pointer to the length, not the length itself, so call it lenp rather than len. Update comments to speak of "*lenp" rather than "len" being the length.
* Pass a pointer to the length to the OID get/set routines.Guy Harris2016-06-041-4/+4
| | | | | | | | An OID get request may return less data than requested; pass a pointer to the length to pcap_oid_get_request(), so that it can supply the amount of data actually supplied. It also appears that a set request may copy less data than supplied, so do the same for pcap_oid_set_request().
* Use pcap_snprintf() instead of snprintf().Guy Harris2015-11-031-30/+30
| | | | | | | | | | | On UN*Xes with snprintf(), we just #define pcap_snprintf to snprintf. On UN*Xes without snprintf(), we provide our own, but call it pcap_snprintf(). On Windows, we have a routine that wraps _snprintf(), with C99 semantics (ensuring null termination if the string won't fit), called pcap_snprintf(), and use that.
* Delete trailing spaces/tabsFrancois-Xavier Le Bail2015-09-221-44/+44
|
* Fix compiler error.Gisle Vanem2015-09-201-2/+2
| | | | The raw data should just be an array of u_char.
* Add missing parenthesis.Guy Harris2015-09-141-1/+1
|
* Fix prototype declarations for the OID get/set API changes.Gisle Vanem2015-09-141-2/+2
|
* Have better APIs for the OID get/set request calls.Guy Harris2015-09-131-2/+3
| | | | | | | | | Have them take the OID, the buffer, and the length as arguments, and, for pcap-win32.c, have the routines for those calls allocate a PACKET_OID_DATA, fill it in as appropriate, and copy the data back. Yeah, it's more work and another memory allocation, but it's still a cleaner API and avoids some compiler warnings.
* Enable the prototype for TcSetUserBuffer().Gisle Vanem2015-09-101-1/+1
|
* Style cleanup.Guy Harris2015-09-081-21/+21
| | | | | | Consistently avoid unnecessary parentheses in return statements. (If somebody prefers them, feel free to consistently use them.)
* Remove "Oid" from "TcOidSendqueueTransmit()".Guy Harris2015-09-081-3/+3
| | | | | That was there through sloppy copy-and-pasting; there's nothing NDIS OID-related there.
* Don't export TcGetReceiveWaitHandle().Guy Harris2015-09-081-1/+2
| | | | | | It's now "exported" through the pcap_t ops vector, rather than being directly called from pcap-win32.c, so make it static again and remove it from pcap-tc.h.
* Set setuserbuffer_op in WinPcap.Guy Harris2015-09-081-3/+1
| | | | | Set it for pcap-win32.c. Fix the name, and set it (and bring TcSetUserBuffer() back from the dead), for pcap-tc.c.
* Fix compile errors.Gisle Vanem2015-09-081-15/+15
| | | | | Since TcGetReceiveWaitHandle() is already in pcap-tc.h (cannot be static here). I dropped TcSetUserBuffer() since set_userbuffer_op is missing.
* There's no "md" substructure; the timeout is now in opt.timeout.Guy Harris2015-09-081-5/+3
| | | | | "md.use_bpf" is now "filtering_in_kernel", but we always do the filtering in our module, so there's no need to record that fact.
* Add TurboCap support from WinPcap.Guy Harris2015-09-031-0/+1286
1) It's also apparently supported on Linux. 2) This cleans it up to match the way we're currently dealing with pcap modules. 3) This cleans it up to the way we're handling the Win32 extensions. Fix the configure script so that, if a pcap module that is supported only if the relevant support software is available is being configured in, we *add* its source to the list of source files to compile, rather than making it *the* source file to compile, in case there's more than one of them. Fix a typo in a comment. Add a comment about TurboCap using DLT_PPI for Ethernet. Move the struct pcap_stat used for pcap_stats_ex() into the pcap structure on Windows, as it's used by multiple modules. Remove the stuff that handles TurboCap from pcap-win32.c, as the routines that did that are now just module ops, so we call the TurboCap versions for TurboCap devices. Remove the stuff that handles remote captures from there as well; that will eventually be handles by modules (plural) for the remote capture protocols (plural). Make all of the fields added to struct pcap_stat dependent on _WIN32 and HAVE_REMOTE being defined. We don't want any of them for UN*X, as that would potentially break binary compatibility; we make them all dependent on HAVE_REMOTE being defined because that's what WinPcap currently does (yes, that's a bad idea, but we'll be fixing this by deprecating that structure as well as pcap_stats() and pcap_stats_ex() in favor of something a bit more pcapng-like, which would be more extensible).