aboutsummaryrefslogtreecommitdiff
path: root/pcap-bt-linux.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix spellingJosh Soref2023-06-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * amount * anymore * authentication * availability * bracket * captured * casted * communications * compliant * configurable * cumulate * deinitialize * descriptors * didn't * disassembler * disassociate * distributions * divvy * doing * entries * everything * explicitly * explosion * expression * extracting * failed * family * find * github * global * implementations * incorrectly * intel * interlocked * justifying * know * launched * libraries * malloced * mask * maximum * network * nonexistent * number * occurred * optimizer * overflow * overwrite lower * packet * packetfilter * packets * parse hosts * payload * phase * programmers * promiscuous * protocol * receiving * redefinition * sampling * savefile * schwartz * should * snapshot * something * specifies * straightforward * stream * subdir * support * surrogate * suse * system is * test with * than * those * unmaintained * valid * way * western * wireshark Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
* 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.
* struct pcap: Update buffer type from "void *" to "u_char *"Francois-Xavier Le Bail2023-05-181-1/+1
| | | | | | | | | | | | | | | | | | | | | This change should avoid these cppcheck warnings: pcap-hurd.c:77:18: warning: 'p->buffer' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer] pkt = p->buffer + offsetof(struct net_rcv_msg, packet) ^ pcap-hurd.c:78:8: warning: 'p->buffer+offsetof(struct net_rcv_msg,packet)' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer] + sizeof(struct packet_header) - ETH_HLEN; ^ pcap-hurd.c:79:25: warning: 'p->buffer' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer] memmove(pkt, p->buffer + offsetof(struct net_rcv_msg, header), ^ Remove some '(u_char *)' casts accordingly.
* Fix spaces before tabs in indentationFrancois-Xavier Le Bail2023-02-151-3/+3
|
* Squelch a false Valgrind error in bt_findalldevs().Denis Ovsienko2022-01-151-0/+8
| | | | This issue was reported by Andrea Odetti in GH #1083.
* Bluetooth: fix non-blocking modeMatias Karhumaa2021-03-191-0/+4
| | | | | | | | | Fix non-blocking mode with bt-linux and bt-monitor-linux. Previously when fd was set to non-blocking mode and pcap_dispatch() was called from application, it returned -1 with errno EAGAIN breaking the api contract. Fix is to handle errnos EAGAIN and EWOULDBLOCK so that 0 is returned.
* 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.
* Do the check for a valid direction value in pcap_setdirection().Guy Harris2019-11-091-12/+5
| | | | | That way, we don't have to do the check in the individual setdirection op routines.
* More pcap_setdirection() cleanups.Guy Harris2019-11-081-4/+27
| | | | | | | | Say "...on this device" for errors; it may be the OS's capture mechanism that doesn't support setting the direction, but there may be other devices on the system that *do* support it. Check the validity of the direction argument in more places.
* Remove some workarounds for old compilers.Guy Harris2019-08-091-5/+5
| | | | | | | | | | | | | 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.
* Clean up some "injection not supported" messages.Guy Harris2018-12-101-2/+2
|
* bt-typo: Extra word existed in comment and minor message fix-upsagnosticdev2018-12-101-3/+3
|
* Squelch more narrowing warnings.Guy Harris2018-09-121-3/+3
|
* 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.
* Address another -Wformat-truncation warning.Denis Ovsienko2018-07-181-4/+5
| | | | | | | | | | | | | | | add_dev() does not imply a particular string length for the name and the description, so it is OK just to increase the buffer size to make the description fit. While at it, use sizeof() for snprintf() and unsigned props for the unsigned structure members from <bluetooth/hci.h>. ./pcap-bt-linux.c: In function ‘bt_findalldevs’: ./pcap-bt-linux.c:115:58: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 5 [-Wformat-truncation=] pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i); ^~ ./pcap-bt-linux.c:115:32: note: directive argument in the range [0, 2147483646] pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Add more interface flags to pcap_findalldevs().Guy Harris2018-04-291-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix a set of trivial unused warningsJoerg Mayer2018-04-041-2/+2
|
* Use AC_CHECK_TYPES and AC_CHECK_MEMBERS.Guy Harris2018-01-201-1/+1
| | | | | | | | | Rather than rolling our own autoconf macros to test for the existence of data types and structure members, use AC_CHECK_TYPES and AC_CHECK_MEMBERS. That cleans the configure script code up a bit, and makes it a bit more like the CMakeLists.txt file.
* Add a routine to format error messages with an errno-based message at the end.Guy Harris2017-11-151-28/+22
| | | | | | | | | | | | | | 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.
* 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.
* Have a pcap_if_list_t structure for use by the findalldevs code.Guy Harris2017-01-181-2/+2
| | | | | | | 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.
* Clean up findalldevs code.Guy Harris2016-12-171-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Have a routine that unconditionally adds a device to the list of devices, without bothering to check whether there's already a device with that name, and a separate routine that does the check and, if it doesn't find the device, calls the routine to add ti. That avoids scanning the entire list in cases where we know the search will fail. The only reasons for doing the check are that we're on a platform where we find the list of interfaces by a call that returns a list of *addresses*, with an interface name attached to each address, and 1) for each address, we need to make sure we don't already have the interface, create it if we don't, and add the address to the now-guaranteed-to-exist entry for the interface; 2) we might have to make a *separate* call to enumerate interfaces, to find interfaces with *no* addresses, and that call also enumerates the ones that *do* have addresses, and we don't want to create a duplicate entry for them. Change some findalldevs helper routines to have "dev" rather than "if" in the name, as not all devices are regular network interfaces. For the DAG findalldevs routine, make sure it always provides an error message if it fails. We don't need add_addr_to_iflist() or get_if_description() on Windows, so don't define them on Windows. Update comments to reflect reality.
* also fix Linux compiling with Bluetooth supportDenis Ovsienko2016-06-301-1/+1
|
* Rename opt.source to opt.device.Guy Harris2016-06-291-2/+2
| | | | | | | 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.
* 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.
* Squelch a signed vs. unsigned warning.Guy Harris2015-10-141-2/+2
|
* Fix warning as "ISO C90 forbids mixed declarations and code"Francois-Xavier Le Bail2015-09-021-1/+1
|
* Make the buffer member of a pcap_t a void *.Guy Harris2015-08-091-8/+8
| | | | | | | | | | | Yes, in some sense, it's an array of bytes - on modern processors, *all* data is ultimately an array of bytes - but different modules will use it in different ways, not all of which will be an undifferentiated array of bytes. This squelches a complaint from the Clang static analyzer. Clean up some code while we're at it.
* Delete trailing spaces/tabsFrancois-Xavier Le Bail2015-03-081-1/+1
|
* Delete trailing spaces/tabsFrancois-Xavier Le Bail2015-03-081-25/+25
|
* remove libpcap's own CVS keywordsDenis Ovsienko2014-01-031-4/+0
| | | | | | This change removes CVS keywords that express that the file belongs to libpcap repository. All such keywords represented the revision and timestamp by the end of 2008 or even older.
* Fix for bluetooth adapters not showing upMansour Behabadi2013-09-291-2/+1
| | | | when they are added to top of the list of devices
* Rename the "private" member of a pcap_t to avoid C++ issues.Guy Harris2013-08-071-2/+2
| | | | | "private" is a C++ keyword; rename the "private" member of a pcap_t to "priv" to avoid that, as per Gisle Vanem's suggestion.
* Move platform-dependent pcap_t data out of the pcap_t structure.Guy Harris2013-05-061-5/+14
| | | | | | | | | | | | | | | Put the private data right after the pcap_t structure, with a pointer to it in the pcap_t. The initial goal is to allow new pcap modules to be added without having to hack pcap-int.h. In the longer term, we may want to freeze the pcap_t structure, except possibly for adding new method pointers at the end, and provide an ABI for adding modules. We also put the stuff used by the read path at the beginning of the pcap_t structure, to try to keep it on the same set of cache lines.
* Merge remote-tracking branch 'github/master'Michael Richardson2013-03-251-1/+1
|\ | | | | | | | | Conflicts: pcap-bt-linux.c
| * Bluetooth: Fix interface initializationMichal Labedzki2013-03-251-1/+2
| | | | | | | | There is a missing field to fill to get Bluetooth to work.
* | Cope with Bluetooth API breakage in some Linux 3.x(?) kernel.Guy Harris2013-03-251-0/+3
|/ | | | | | | | | | | In the 2.6.32.4 kernel, struct sockaddr_hci has no hci_channel member. In the 3.0.4 kernel, struct sockaddr_hci has an hci_channel member, and it has to get set in order for binds of AF_BLUETOOTH/BTPROTO_HCI sockets to work. Cope with this API breakage by checking whether struct sockaddr_hci has an hci_channel member and, if it does, set it to HCI_CHANNEL_RAW.
* And un-constify some others.Guy Harris2012-06-111-1/+2
|
* Constify some variables.Guy Harris2012-06-111-1/+1
|
* Have non-interface modules take responsibility for identifying their devices.Guy Harris2012-06-111-2/+31
| | | | | | | | | | | | | | Have a table of routines to do pcap_create() for devices that aren't regular network interfaces. Try each of those in succession until one says "it's mine" (whether it succeeds or fails); if none do, do a pcap_create() for a regular interface. Have those routines do more stringent tests of the name - don't just accept any name that has a particular substring anywhere in it. That reduces the likelihood of a false match (as happened with the CANbus module when somebody renamed their Ethernet interface "canopy"). Have the table also include routines for pcap_findalldevs().
* recvmsg() returns an ssize_t; put its return value into an ssize_t.Guy Harris2011-11-301-22/+26
| | | | | | | | | This makes the check for a negative value valid. Thanks to Michal Sekletar for catching this. While we're at it, don't use the numerical value of errno in error messages.
* Fix typos in the Bluetooth capture code.Jakub Zawadzki2011-06-141-2/+2
| | | | | | | | | The "set the buffer size" code check for a zero, rather than a non-zero, opt.buffer_size when deciding whether to explicitly set the buffer size. Fix a typo in a comment. Reviewed-By: Guy Harris <guy@alum.mit.edu>
* Do filtering on USB and Bluetooth capturing.Guy Harris2010-06-041-13/+11
| | | | | | | | | | Do the standard userland filtering on USB and Bluetooth captures, rather than returning "success" when the filter is installed without doing anything with the filter. Also, squelch some "dereferencing type-punned pointer will break strict-aliasing rules" warnings in pcap-bt-linux.c, by using memcpy rather than pointer-casting.
* Get rid of declaration of non-existent routine.guy2008-07-011-2/+1
|
* Fix typoes (sigh, using both "p" and "handle" for the pcap_t pointer inguy2008-04-141-3/+3
| | | | different modules can lead to confusion).
* Turn close_op into cleanup_op; the routine that handles it can also beguy2008-04-141-12/+12
| | | | | | | | | | | | | | | | | | | | | | | used to clean up after a failed pcap_activate() call. Convert the existing close_op routines to cleanup_op routines, and use them to clean up; rename pcap_close_common() to pcap_cleanup_live_common(), and use it directly if there's no platform-dependent cleanup needed. That means we don't have to write the same cleanup code twice (and possibly forget stuff in the version done on a failed pcap_activate() call). Have the cleanup routines do whatever is necessary to indicate that cleanup has been done, and not do any particular cleaning up if it's already been done (i.e., don't free something if the pointer to it is null and null out the pointer once it's been freed, don't close an FD if it's -1 and set it to -1 once it's been closed, etc.). For device types/platforms where we don't support monitor mode, check for it and return PCAP_ERROR_RFMON_NOTSUP - but do so after we've checked whether we can open the device, so we return "no such device" or "permission denied" rather than "that device doesn't support monitor mode" if we can't open the device in the first place. Fix a comment.
* For Linux non-mmapped captures, Linux bluetooth captures, and Irixguy2008-04-071-4/+18
| | | | | | | captures, set the socket buffer size to the value specified by pcap_set_buffer_size() if a value was set. Clean up if memory buffer allocation fails on Linux.
* From Paolo Abeni and me: split pcap_open_live() into a "get a pcap_tguy2008-04-041-45/+45
| | | | | | | | | | | | | | | | handle" routine, an 'activate a pcap_t handle" routine, and some "set the properties of the pcap_t handle" routines, so that, for example, the buffer size can be set on a BPF device before the device is bound to an interface. Add additional routines to set monitor mode, and make at least an initial attempt at supporting that on Linux, *BSD, and Mac OS X 10.4 and 10.5. (Very much "initial" for Linux, which is a twisty little maze of wireless drivers, many different.) Have a "timeout" member of the pcap_md structure on all platforms, use that on Windows instead of the "timeout" member of the pcap_t structure, and get rid of the "timeout" member of that structure.
* Use %zu to print something with the type size_t - I think most if notguy2008-02-141-2/+2
| | | | | all versions of glibc support it, and it handles both 32-bit and 64-bit size_t.