aboutsummaryrefslogtreecommitdiff
path: root/pcap.c
Commit message (Collapse)AuthorAgeFilesLines
* Get rid of trailing blanks.Guy Harris2023-07-271-6/+6
|
* remove additional ifdefs based upon MSDOSMichael Richardson2023-07-261-19/+8
|
* Fix spellingJosh Soref2023-06-251-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Add the Solaris "any" device in pcap_findalldevs() if we have it.Guy Harris2023-06-131-0/+18
| | | | | | | | There's no good run-time test, so we test at configure time, by checking whether /usr/include/inet/ipnet.h exists and contains IPNET_ANY_LINK. See https://github.com/the-tcpdump-group/tcpdump/issues/1057#issuecomment-1584088911 We make a common routine to use to add that device.
* Add a routine to use as an atexit() routine to clean up Winsock 2.Guy Harris2023-05-301-1/+14
| | | | | | | | Wrap WSACleanup() in a routine that calls it but returns nothing, so that the wrapper has the right type for an atexit() routine. This is cleaner that casting a pointer to WSACleanup(), and should avoid warnings from VS 2022.
* Prefix routines declared in pcap-int.h with pcap_.Guy Harris2023-05-261-11/+11
| | | | | This avoids potential and, in one case (SIMH), actual collisions with names in other libraries or in applications using libpcap.
* Make some static variables thread-local.Guy Harris2023-05-051-4/+6
| | | | | | | | This should make some functions thread-safe, even if it doesn't make them fully-reentrant; at least some of them would requiree API changes to full reentrancy. This should fix #1174.
* Address a few compiler warnings on Haiku.Denis Ovsienko2023-04-231-0/+17
| | | | | | | | | | | | | | | | | | | In gencode.c instead of casting pointer types copy the data to squelch 4 previously known warnings from GCC and Clang. (Oddly enough, Haiku is the only OS that unconditionally puts a 32-bit array into the union inside struct in6_addr, yet the only OS where these warnings appeared.) In pcap.c add a temporary workaround for ioctl() to squelch two other Clang warnings: pcap.c:1619:6: error: missing field 'size' initializer [-Werror,-Wmissing-field-initializers] pcap.c:1638:6: error: missing field 'size' initializer [-Werror,-Wmissing-field-initializers] With these changes GCC builds are now warning-free, so in build.sh set LIBPCAP_TAINTED for Clang only and update the comment to show the current remaining warnings.
* Refine comments for the recent DLT allocations.Denis Ovsienko2023-03-021-0/+3
|
* Added DLT_FIRA_UCI and LINKTYPE_FIRA_UCIHenri Chataing2023-03-021-0/+1
|
* Do not define IF_NAMESIZE on Un*x. [skip appveyor]Denis Ovsienko2023-02-101-4/+0
| | | | | | BSDi 3.x is from 1997-1998, the workaround was introduced via commit b63de9e in 2001. In the unlikely case it is still required, it would have to be reinstated with a better comment.
* Spell WirelessHART details properly. [skip ci]Denis Ovsienko2023-01-211-1/+1
|
* Merge pull request #1142 from hansleidekker/mmapGuy Harris2023-01-161-0/+5
|\ | | | | Add an option to force memory-mapped buffers to be mapped as accessible to 32-bit code
| * Add an option to force memory-mapped buffers to be mapped as accessible to ↵Hans Leidekker2022-12-201-0/+5
| | | | | | | | 32-bit code.
* | Fix some comments. [skip ci]Guy Harris2022-12-211-1/+9
| |
* | Fix the error fix of #1147hopper-vul2022-12-211-5/+3
| | | | | | | | | | | | | | 1. change pcap_read_dead to return void. 2. let pcap_read_dead do nothing. Signed-off-by: hopper-vul <hopper.vul@gmail.com>
* | Fix two null pointer crashes of breakloop and can_set_rfmonhopper-vul2022-12-211-0/+9
|/ | | | | | | | | | pcap_open_dead and pcap_fopen_offline has not initialized the breakloop_op and can_set_rfmon_op callback respectively, if pcap_breakloop() is called followed by pcap_open_dead() and pcap_can_set_rfmon() is called followed by pcap_fopen_offline() then the null function pointer crashes will happen. This commit adds two default implementation pcap_breakloop_dead and sf_cant_set_rfmon and uses them to initialize those two missed callbacks. Signed-off-by: hopper-vul <hopper.vul@gmail.com>
* DllMain() isn't required in a DLL, so remove it.Guy Harris2022-10-091-14/+5
| | | | | | | | | | It used to set up a critical section intended to protect pcap_compile() against simultaneous use in more than one thread, but that is no longer necessary, given that pcap_compile() is now thread-safe; the code to set up the critical section was removed when the first changes to make the compiler thread-safe were made. This should fix issue #1127.
* Fix some typosFrancois-Xavier Le Bail2022-07-041-1/+1
| | | | [skip ci]
* Add speed specific USB 2.0/1.1/1.0 linktypesTomasz Moń2022-05-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | USB 2.0/1.1/1.0 devices (or 3.x and newer when connected to hosts that are not Super-Speed capable) operate at one of three speeds: * Low-Speed (1.5 Mbps) * Full-Speed (12 Mbps) * High-Speed (480 Mbps) While the packets are generally common to all three speeds, there are some differences that span across different layers. The capture speed should be available to analyzer and it makes sense to expose it via speed specific linktypes. Existing USB 2.0/1.1/1.0 captures can be manually, retroactively updated to speed specific linktype. Low-Speed device will always operate at Low-Speed, regardless of what host it is connected to. USB cable connected to Low-Speed device only ever carries packets sent at Low-Speed. High-Speed device will operate at High-Speed when connected to High-Speed capable host. If High-Speed Detection Handshake succeeds, the cable will only carry High-Speed packets. Full-Speed device will always operate at Full-Speed, regardless of what host it is connected to. High-Speed device connected to Full-Speed host or hub, will operate at Full-Speed. The cable connected to device operating at Full-Speed can only carry Full-Speed or Low-Speed packets preceded by Low-Speed preamble (PRE packet) sent at Full-Speed. Non-hub device operating at Full-Speed always ignores Low-Speed packets. The hub forwards the Low-Speed packets to downstream ports but does not act upon the actual Low-Speed packet contents. The packets intended for device operating at Full-Speed are always sent at Full-Speed.
* pcap_init: return PCAP_ERROR rather than -1, to match the man page.Guy Harris2022-05-081-4/+4
|
* Make the error message for PCAP_ERROR_PERM_DENIED a little more open-ended.Guy Harris2022-03-181-1/+1
| | | | | | | | | | | | | | | | PCAP_ERROR_PERM_DENIED can be returned for reasons other than "you don't have any permission to capture on that device", e.g. it might be "you have permission to capture on it, but not to capture on it with hardware time stamps (as on Linux) or to capture in monitor mode or to...". This leaves it more open-ended, in case we add support for device-dependent or platform-dependent configuration parameters and some of them require more privileges than just capturing with the default setting does, without having to keep adding more PERM_DENIED error codes. This, along with some other changes, may help debug problems such as the one in issue #1098.
* pcap_open_live(); don't show an empty additional message.Guy Harris2022-03-141-7/+19
| | | | "{error message} ()" looks bogus.
* support user/pass in rpcap:// and rpcaps:// source URIsRyan Castellucci2022-03-071-13/+17
|
* Use "%d" to print a signed intFrancois-Xavier Le Bail2022-03-011-1/+1
| | | | | | | | | Fix this cppcheck warning: pcap.c:3372:23: warning: %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. [invalidPrintfArgType_uint] (void)snprintf(unkbuf, sizeof(unkbuf), "DLT %u", dlt); ^
* Add link-type value <-> string and -> descriptions for new linktypes.Guy Harris2022-02-201-0/+2
| | | | Add entries for DLT_NETANALYZER_NG and DLT_ZBOSS_NCP.
* Merge pull request #1026 from Biswa96/fix-mingwGuy Harris2022-01-021-2/+2
|\ | | | | Fix some build issues with MinGW
| * Cast HANDLE to intptr_t first.Biswapriyo Nath2021-07-201-2/+2
| | | | | | | | | | | | | | In 64 bit system, pcap.handle is of type HANDLE aka. void* which is 8 bytes, different that 4 bytes int. So, gcc shows warning while casting void* to int like this warning: cast from pointer to integer of different size. This change fixes that warning.
* | Revert the DIAG_{OFF,ON}_PTR_TO_INT changes.Guy Harris2022-01-021-2/+2
| | | | | | | | | | | | | | | | Windows programs shouldn't use pcap_fileno(); we're already deprecating it, and the fix for GitHub issue #1026 squelches the warning in a fashion that doesn't require any DIAG_OFF/DIAG_ON stuff, and there's no reason for us to care how a deprecated function works around its brokenness-by-design.
* | Have a separate DIAG_OFF_ for pointer-to-integer narrowing.Guy Harris2022-01-011-2/+2
| | | | | | | | | | | | | | | | | | Use that for pcap_fileno() on Windows; that API shouldn't exist on Windows, and should never be used, but WinPcap offered it, so we're stuck with it. At least try to prevent compilation errors when libpcap is built. This should fix the warnings for pcap_fileno() in GitHub issue #1026.
* | Move all cleanup actions to pcap_cleanup_live_commonDaniel Miller2021-11-121-2/+4
| | | | | | | | | | | | | | pcap-npf.c's pcap_cleanup_npf() expects to be able to access opt.device in order to restore the monitor mode. This results in a use-after-free when calling pcap_close(). Instead, do this free in pcap_cleanup_live_common, just like all the others.
* | Fix comments.Guy Harris2021-11-031-2/+6
| | | | | | | | | | | | | | | | On success, pcap_offline_read() and the read_op routine return a value > 0 that is the number of packets read or captured, respectively. Given that, in the calls to them in pcap_next_ex(), we pass a maximum packet count of 1, they will read or capture, respectively, at most one packet, so, in those particular calls, they will return 1 on success.
* | Address two truncation warnings in pcap_open_live().Denis Ovsienko2021-07-311-6/+18
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | These warnings have been around for a while in the REMOTE=yes space of all Linux builds and OpenBSD/AMD64 build. Pass each of the offending strings through a tailored buffer to satisfy GCC. ./pcap.c: In function 'pcap_open_live': ./pcap.c:2858:47: warning: '%.*s' directive output may be truncated writing up to 250 bytes into a region of size between 249 and 252 [-Wformat-truncation=] 2858 | snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%.*s)", device, | ^~~~ In file included from /usr/include/stdio.h:867, from ./pcap.c:56: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output 6 or more bytes (assuming 259) into a destination of size 256 ./pcap.c:2853:43: warning: '%.*s' directive output may be truncated writing up to 253 bytes into a region of size between 251 and 254 [-Wformat-truncation=] 2853 | snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %.*s", device, | ^~~~ In file included from /usr/include/stdio.h:867, from ./pcap.c:56: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output 3 or more bytes (assuming 259) into a destination of size 256
* Revert "Don't wrap chunks of headers with extern "C" { ... }."Guy Harris2021-03-171-4/+4
| | | | | | | This reverts commit 8b6b13d4cbb685db047af04c49817ed81fff7c35. That solution allowed you to intermix declarations/definitions and before the extern "C", so you can see what's being imported.
* Don't wrap chunks of headers with extern "C" { ... }.Guy Harris2021-03-171-4/+4
| | | | | | | | | | | Instead, explictly flag individual functions with extern "C" by adding it to the tag we're already using for exported functions, and creating a new tag to use for non-exported functions. Rename those tags, and the tags used for exported data, to say what they do, rather than saying "this is an API" (we may export things we don't want to be treated as part of the API, but that we have to export because some programs use them).
* Add DLT_ETW to the list of link-layer type descriptions.Guy Harris2021-01-271-0/+1
|
* Update some URLs.Guy Harris2020-12-251-2/+12
|
* Remove test code.Guy Harris2020-07-031-14/+0
| | | | | | | | The code that should have given a warning wasn't compiled in AppVeyor, because we were building libpcap on its own rather than as part of a WinPcap or Npcap build. [skip ci]
* Spell _WIN32 correctly.Guy Harris2020-07-031-1/+1
| | | | [skip ci]
* OK, see if *this* fixes the link error.Guy Harris2020-07-031-0/+14
| | | | [skip ci]
* Revert "Quick test to make sure compilers warn about de-constification."Guy Harris2020-07-021-13/+0
| | | | | | This reverts commit 10dbaabafb2ea88f5c3cce8a66f00831abca1ebd. OK, we got the warnings we expected.
* Quick test to make sure compilers warn about de-constification.Guy Harris2020-07-021-0/+13
| | | | | | | There appears to be a case with MSVC where that's not happening; make sure all the compilers we use, including MSVC, warn about that. This will be removed once the CI builders are done with it.
* Handle the pcap_t+private data in a fashion that makes fewer assumptions.Guy Harris2020-07-011-29/+16
| | | | | | | | | | | | | | | 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.
* Update a comment.Guy Harris2020-06-051-2/+5
| | | | | | | | I backed pcap_handle() out; we'll provide it if there's a demand for it, but I'm not sure how useful getting the HANDLE for an NPF device is (what can you do with it?). [skip ci]
* Add a missing parentheseFrancois-Xavier Le Bail2020-06-031-1/+1
|
* Don't introduce pcap_handle() unless a need for it is demonstrated.Guy Harris2020-05-311-6/+0
|
* Fix typo.Guy Harris2020-05-301-1/+1
|
* Include "diag-control.h", as we're now using diagnostic suppression macros.Guy Harris2020-05-301-0/+2
|
* Add pcap_handle(), and deprecate pcap_fileno(), on Windows.Guy Harris2020-05-301-6/+24
| | | | | | | | | | | | | I don't know whether a Windows HANDLE can be expected to survive conversion to an int - and there's no need for it to have to be converted. If a caller needs to do something with a HANDLE associated with a pcap_t, it should call the new pcap_handle() routine and get a HANDLE; code for UN*X that uses the result of pcap_fileno() is unlikely to work on Windows anyway. Squelch the "pointer truncation from 'HANDLE' to 'DWORD'" warning, as, if that truncation causes an issue, callers should use pcap_handle(), and if it *doesn't* cause an issue, it's, well, not an issue.
* Support AirPcap devices with a pcap module.Guy Harris2020-05-071-2/+76
| | | | | | | | 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.