aboutsummaryrefslogtreecommitdiff
path: root/pcap-snf.c
Commit message (Collapse)AuthorAgeFilesLines
* Prefix routines declared in pcap-int.h with pcap_.Guy Harris2023-05-261-5/+5
| | | | | This avoids potential and, in one case (SIMH), actual collisions with names in other libraries or in applications using libpcap.
* Fix spaces before tabs in indentationFrancois-Xavier Le Bail2023-02-151-10/+10
|
* Remove an always-false pointer test from snf_read().Denis Ovsienko2023-01-021-3/+0
| | | | | | | Guy Harris: "The only way snf_read() gets called is through the read_op function pointer in the pcap_t, so the only way it gets called is if you have a non-NULL pcap_t * pointing to a pcap_t with a read_op set to snf_read()."
* Revert "Fix NULL pointer dereference in snf_read()"Denis Ovsienko2023-01-021-2/+1
| | | | | | As Guy points out, in this context the variable p never is NULL. This reverts commit 1f3650863b97f6f3d62db2b524de3ba61ffadf6b.
* Fix NULL pointer dereference in snf_read()Ege Çetin2023-01-011-1/+2
|
* Make sure no read routine process more than INT_MAX packets.Guy Harris2022-01-261-1/+17
| | | | | | | | | | | | | | | | | | | Some read routines don't read a single bufferful of packets and process just those packets; if packets continue to be made available, they could conceivably process an arbitrary number of packets. That would mean that the packet count overflows; either that makes it look like a negative number, making it look as if an error occurred, or makes it look like a too-small positive number. This can't be fixed by making the count 64-bit, as it ultimately gets returned by pcap_dispatch(), which is defined to return an int. Instead, if the maximum packet count argument to those routines is a value that means "no maximum", we set the maximum to INT_MAX. Those routines are *not* defined to loop forever, so this isn't an issue. This should fix issue #1087.
* Clean up allocation of some lists.Guy Harris2020-09-271-1/+1
| | | | | | | | Always heck wehther the allocation succeeds, and fail if it doesn't. Set the count of elements of the list only if the list was successfully allocated. For stylistic consistency, also seet it after we've set all the elements of the list.
* 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.
* Don't use ctype.h macros.Guy Harris2019-08-311-1/+0
| | | | | | | | | | | | | | | Some of them are locale-dependent, and all of them run the risk of failing if you hand them a char with the 8th bit set. Define our own locale-independent macros that can be handed any integral value. Don't include <ctype.h>. This should address the issue in GitHub pull request #839, and should also catch any (highly unlikely) cases in which something other than Boring Old Space And Tab and, sometimes, CR and LF are treated as white space. (No, we don't want FF or VT treated as white space.)
* Remove some workarounds for old compilers.Guy Harris2019-08-091-7/+7
| | | | | | | | | | | | | 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-20/+1
| | | | | That's how to do it for modules that do filtering in the module itself; there's no need for a wrapper.
* Count only packets that were handed to the callback.Guy Harris2018-11-201-1/+1
| | | | That's how other devices work.
* Provide out own strlcpy() and strlcat() routines if necessary.Guy Harris2018-10-161-1/+1
| | | | | | | | | | | | | | We now depend on the *full* semantics of those routines, including the return value being usable for truncation checks. If we're building for a UN*X that has them, define pcap_strl{cpy,cat} to be strl{cpy,cat}. If we're building for Windows using MSVC, define pcap_strl{cpy,cat}, not strl{cpy,cat}. Otherwise, build our won versions of pcap_strl{cpy,cat} from BSD-derived source code.
* Squelch more narrowing warnings.Guy Harris2018-09-121-1/+1
|
* 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.
* Add more interface flags to pcap_findalldevs().Guy Harris2018-04-291-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We add: PCAP_IF_WIRELESS, which indicates whether the interface is "wireless" or not. PCAP_IF_CONNECTION_STATUS, which is a bitmask for a two-bit field that can have one of the values: PCAP_IF_CONNECTION_STATUS_UNKNOWN if the status of whether the interface is "connected" or "disconnected" is unknown; PCAP_IF_CONNECTION_STATUS_CONNECTED if the interface is "connected"; PCAP_IF_CONNECTION_STATUS_DISCONNECTED if the interface is "disconnected"; PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE if the notion of "connected" or "disconnected" doesn't apply to this interface. Take that into account when sorting interfaces in the interface list, penalizing "disconnected" interfaces, as you won't see traffic on them if they're not wireless and you'd have to be in some form of "monitor mode" to see traffic on them if they're wireless. This should address GitHub issue #700.
* Add a routine to format error messages with an errno-based message at the end.Guy Harris2017-11-151-24/+25
| | | | | | | | | | | | | | 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.
* No need to generate version.c or pcap_version.h.Guy Harris2017-10-031-2/+0
| | | | We can get the project version from config.h, so do so.
* Push pcap_lib_version() into the pcap-XXX.c files.Guy Harris2017-09-061-3/+5
| | | | | | | | This lets us move the Windows version to pcap-win32.c, so we don't have to include packet32.h in pcap.c. It also gets rid of some #ifdefs, and lets us construct the version string on UN*X platforms, and MS-DOS, at compile time.
* Get rid of pcap-stdinc.h.Guy Harris2017-09-051-3/+1
| | | | | On Windows, in each file, include whatever that particular file needs, just as we do on UN*X and MS-DOS.
* 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.
* Allow a platform to add information to the version string.Guy Harris2017-05-161-0/+9
| | | | | For example, on Linux, we add information about memory-mapped capture support; see comments on GitHub issue #600.
* Use add_addr_to_dev() to add an address based on the device name.Guy Harris2017-03-011-24/+17
|
* Update file to allow building on Windows VS2010.Christopher K Lee2017-03-011-3/+52
| | | | Also on Windows, device name has IP# so use this as address of interface.
* Support setting non-blocking mode before activating.Guy Harris2017-02-251-2/+2
| | | | | | | | | | | | | | | | | | 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.
* Have a pcap_if_list_t structure for use by the findalldevs code.Guy Harris2017-01-181-6/+5
| | | | | | | It's not part of the API, but it's an internal structure used by the findalldevs code. Currently, it just has a pointer to the beginning of the list, but it could change in order to speed up the process of adding to the list.
* Have separate "find device" and "find or add device" routines.Guy Harris2016-12-241-127/+67
| | | | | | | | | | Use the "find device" routine for CSPi's Myricom adapters; those adapters can appear as regular network interfaces, but, when we enumerate the Myricom adapters, we want to update the description for those adapters, rather than adding separate entries for them. While we're at it, add comments to packet-snf.c explaining this. Fix some comments and some indentation while we're at it.
* Fixes to snf_findalldevs().Guy Harris2016-12-131-16/+21
| | | | | | | | | Always provide an error message if it fails. Plug memory leaks when updating the description of a device. Also, use a for loop to make it clearer what we're doing, and get rid of a no-longer-pertinent comment.
* Get rid of trailing white space.Guy Harris2016-12-131-4/+4
|
* Leave the interface address lists empty.Guy Harris2016-12-131-54/+10
| | | | | | | | | | There's no need to put an incompletely-initialized address into the list; empty interface address lists are valid and any program that can't handle them is buggy (and will probably crash on perfectly ordinary interfaces on perfectly ordinary systems, so there's no need to allocate fake addresses for fear of such programs). Fix another string comparison.
* Fix indentation, clean up strcmp() calls.Guy Harris2016-12-131-45/+45
| | | | | | | | | If you want to compare strings with a given C comparison operator, you are expected to do strcmp(str1, str2) {operator} 0; that makes it clearer what comparison is being done. "!x" checks for x being zero, but it's mainly intended for testing Boolean variables; using it on strcmp() makes it a bit figure out, as comparing against 0 means comparing for "equal", not for "not equal".
* Remove use of p->opt.buffer_size from snf_open. SNF will use env var.Christopher K Lee2016-12-131-3/+2
|
* Merge branch 'master' of https://github.com/the-tcpdump-group/libpcapChristopher K Lee2016-12-131-5/+30
|\
| * Clean up {DAG, Septel, Myricom SNF}-only builds.Guy Harris2016-06-301-0/+28
| | | | | | | | | | | | | | | | | | | | | | In the core code, treat them similarly to other builds. In the configure script, ensure that no other pcap-XXX.c file is built, so we have only the entries for the capture mechanism in question in the tables for pcap_findalldevs() and pcap_create(), so that those routines are the only ones called. If XXX_ONLY is defined in pcap-XXX.c, define a stub pcap_platform_finddevs() that finds no regular interfaces and a stub pcap_create_interface() that fails with a "we only support XXX" error message.
| * 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.
| * Don't check for NULL in cleanup routines, and don't pass NULL to them.Guy Harris2016-04-151-3/+0
| | | | | | | | | | | | | | | | | | pcap_close() won't pass a null pointer - it'll crash long before that when handed a null pointer, as the platforms on which we run map out page 0. Remove the null pointer checks, and, in cases where the cleanup routines are called internally, make sure we don't pass them a null pointer.
* | Update snf_findalldevs() to handle existing device list and SNF_FLAGS=0x2.Christopher K Lee2015-11-251-11/+135
| | | | | | | | | | | | It now will update description info if existing device list matches a SNF interface. It will also adjust SNF interface name in description field if SNF_FLAGS=0x2(port aggregation enabled).
* | Merge branch 'master' of https://github.com/the-tcpdump-group/libpcapChristopher K Lee2015-11-251-16/+16
|\|
| * Use pcap_snprintf() instead of snprintf().Guy Harris2015-11-031-16/+16
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Allow pcap_set_buffer_size() value in bytes to set SNF_DATARING_SIZEChristopher K Lee2015-05-151-1/+1
| | | | | | | | in pcap-snf.c. value is adjusted to the minimum of 1MB.
* | Allow pcap_set_buffer_size() to set SNF_DATARING_SIZE in pcap-snf.c.Christopher K Lee2015-05-141-1/+1
|/
* Use pcap_close() if pcap_create_handle() fails.Guy Harris2015-05-041-3/+1
| | | | | | | Use it to free up all memory attached to the pcap_t, as well as the pcap_t itself; that closes some memory leaks. Fixes GitHub issue #432.
* Delete trailing spaces/tabsFrancois-Xavier Le Bail2015-03-081-1/+1
|
* Updated pcap-snf.c to support --time-stamp-precision=nano option.Christopher K Lee2015-02-021-4/+29
|
* using the PACKET_COUNT_IS_UNLIMITED() macroMyricom Help2014-09-071-1/+1
|
* using the PACKET_COUNT_IS_UNLIMITED() macroMyricom Help2014-09-071-1/+1
|
* Added back in EBUSY as it can be returned in SNFv3 by snf_ring_recv().Christopher K Lee2014-07-311-1/+1
|
* Added parsing of SNF_FLAGS, packet injection, snf_findalldevs for SNF APIChristopher K Lee2014-07-301-14/+156
| | | | Bug Fixes so --with-pcap=snf builds properly