aboutsummaryrefslogtreecommitdiff
path: root/sf-pcapng.c
Commit message (Collapse)AuthorAgeFilesLines
* Prefix routines declared in pcap-int.h with pcap_.Guy Harris2023-05-261-1/+1
| | | | | 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-3/+3
| | | | | | | | | | | | | | | | | | | | | 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.
* rpcap: have the server tell the client its byte order.Guy Harris2022-08-061-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Stick a byte-order magic number, in the host byte order of the server, into the authentication reply. If the authentication reply is large enough to contain that magic number, extract it and, from it, determine whether the server's byte order is the opposite of the client's byte order; if it's not present, assume the server has the same byte order. If the two byte orders are differen, do the same byte-order fixing of the packet contents that we do when reading a pcap file or pcapng section with the opposite byte order, so that host-byte-order fields are converted from the byte order of the host that sent or wrote them to the byte order of the host that received or read them. This change will allow a client to work with all servers, regardless of whether they provide the byte order or not, although if the server doesn't provide the byte order, and it happens to be the opposite of the client's byte order, packets with a link-layer header type that contains host-byte-order fields will not be able to be processed correctly. It also allows clients that don't handle the byte order magic number in the authentication reply to work with all servers, as they will just discard what they consider extra data at the end of the reply. (Note: fixing the byte order in the server requires that the client send a byte order indication to the server, so *either* fix works only between an updated client and an updated server. We already have optional data in the authentication reply, to allow updated servers and clients to negotiate a protocol version while still allowing updated clients to work with older servers and older clients to work with updated servers, so this just continues that mechanism.)
* Linux USB: fix incorrect values for the packet length.Guy Harris2022-06-031-0/+2
| | | | | | | | Correctly compute the "real" length for isochronous transfers. When reading memory-mapped Linux capture files, fix up the "real" length field, in case the file was written by a program doing a capture with the bug.
* Fix pcap_dispatch() to return number of packets processed even at EOF.Guy Harris2021-11-021-3/+3
| | | | | | | | If it successfully read one or more packets and then got an EOF, it would return 0 rather than the number of packets it processed. While we're at it, change the next_packet_op routines to return 0 on EOF and 1 on success, rather than vice versa, so that it's a bit clearer.
* Fix a typoFrancois-Xavier Le Bail2021-04-171-1/+1
| | | | [skip ci]
* Handle pcapng version 1.2.Guy Harris2021-04-081-3/+18
| | | | | | | | Some programs wrote it, even though the only "difference" is that some new sysdig block types were added. Any program that can read version 1.2 and its new block types should be able to read 1.0 files with the same block types, so that wasn't a reason to bump the minor version number.
* 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.
* pcapng: save a per-interface snapshot length.Guy Harris2020-05-211-3/+7
| | | | | | | | | | | | | | | We don't currently use it, but 1) we would do so in the future if we ever fully support pcapng and 2) Apple will do so if they pick up the patch I'll provide once I file the bug originally reported as https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=16573 as an Apple bug, so this makes one less place where Apple's libpcap fork would differ from our libpcap if they pick up 1.10 when it's released. (This also keeps them from claiming that change is licensed under the APSL, as we got it first, and none of *our* code is licensed under the APSL.)
* Fix an error messageFrancois-Xavier Le Bail2020-03-121-1/+1
| | | | Probably a copy & paste error.
* Get rid of extra blank lines.Guy Harris2019-10-021-2/+0
|
* Fix some format warnings.Guy Harris2019-10-021-5/+5
|
* do sanity checks on PHB header length before allocating memory. There was no ↵Michael Richardson2019-10-021-16/+10
| | | | fault; but doing the check results in a more consistent error
* Remove some workarounds for old compilers.Guy Harris2019-08-091-31/+31
| | | | | | | | | | | | | 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.
* Use %zu as the print format for size_tFrancois-Xavier Le Bail2019-08-091-4/+4
| | | | | | C99 support it and also Visual Studio VS 2015 and after. No more need for PRIsize format.
* Make sure the *adjusted* snapshot length is the same for all IDBs.Guy Harris2019-08-041-14/+8
| | | | | | | | | | | | | | | | | If the snapshot length is 0, or doesn't fit in an int, we adjust it. If we see an IDB after the first IDB, perform the same adjustment on *its* snapshot length before comparing it with the adjusted snapshot length for the first IDB. (Yes, this means that if the IDBs have different snapshot lengths, but they both adjust to the same value, they will be treated as equal. That's not a bug, that's a feature - the only reason we insist that they be the same is so that the value that pcap_snapshot() returns, which, for pcapng files, is the adjusted snapshot length for the first IDB, applies to all IDBs, so the IDBs all just have to have the same adjusted snapshot length.) This should fix GitHub issue #832.
* Test hdr.snaplen to see whether it fits in an int.Guy Harris2019-07-251-3/+4
| | | | | | | | | | Assigning it to p->snapshot, and then checking whether the result is negative, should work in practice, but it gets unsigned-behavior warnings. Test beforehand whether it's valid, and only assign it to p->snapshot if it is. This should address the pcap.c part of GitHub issue the-tcpdump-group/tcpdump#785.
* Read the magic number into a byte array.Guy Harris2019-06-121-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | Apparently, in some C implementations, attempting to do an fread() into a variable of a 32-bit unsigned integral type with a size of 1 and a count of 4 returns 0 with an EOF indication; see GitHub pull request We can make the size be the size of the variable and the count be 1, but that means that the count returned by an fread() terminated by an EOF will be 0, not the number of bytes successfully read, so the "truncated dump file" message will give an invalid count: tcpdump: truncated dump file; tried to read 4 file header bytes, only got 0 If, instead, we read into an array of 4 bytes, with a size of 1 and a count of 4, we'll get the right short count back. Pass the byte array to the file-type-specific "is this a file of this type?" routines, so that if we add support for files where the magic number isn't byte-order dependent (e.g., Microsoft Network Monitor), we can handle them more cleanly (check for the standard magic number as a 4-byte array, rather than as its numerical value in both the host's byte order and the byte-swapped byte order).
* Require block lengths to be a multiple of 4.Guy Harris2018-11-111-51/+8
| | | | | | | I'm not sure what files, if any, required the Wireshark library to round up the block length, but it was only for packet blocks, not all blocks. We'll add it *if* there are files with which there are problems.
* Fix a couple of issues.Guy Harris2018-11-101-0/+77
| | | | | | | | Handle the block total length not being a multiple of 4. Pad it to a multiple of 4 if possible; fail if that would exceed 2^32-1. Do the same for the total length in the trailer, and make sure the (padded, if necessary) lengths in the header and trailer match.
* Make sure the *first* SHB, which we read when opening, isn't too big.Guy Harris2018-09-181-32/+35
| | | | | | | | | | Start out with the 16 MiB maximum block size, check against that when trying to read the SHB at the beginning of the file, and then increase the maximum block size if we see an IDB with a snaplen that would result in a bigger maximum block size. When reading a block, we don't need to check against the maximum block size unless we need to increase the block size.
* Add PRIsize, to use as the print format for size_t, and use it.Guy Harris2018-08-051-7/+6
| | | | | | | | | | size_t may be bigger than unsigned long, so don't just cast to unsigned long and print with %lu". (In practice, the value is unlikely to be bigger, but this is cleaner.) We could use %zu on UN*X, as we require C99 support and C99 requires support for z as a size modifier, but MSVC doesn't support z as a size modifier until Visual Studio 2017.
* Remove no more used field 'tzoff' in some structuresFrancois-Xavier Le Bail2018-08-031-1/+0
| | | | As a follow-up to comit 5f2a5c03e0f91bc2dc2ae33838db273dd6c7d8d9.
* Make the time stamp scale factor 64-bit.Guy Harris2018-07-141-1/+1
| | | | | It's calculated as the quotient of two 64-bit values, and is used only in 64-bit calculations, so it should be made 64-bit as well.
* Make the time stamp resolution 64-bit.Guy Harris2018-07-101-12/+12
| | | | | This allows higher-resolution time stamps; we now allow powers of 2 up to 2^-63 seconds and powers of 10 up to 10^-19.
* Make sure the compiler/UBSAN doesn't while about the LHS of << being signed.Guy Harris2018-07-091-1/+1
|
* No need to re-calculate the shift.Guy Harris2018-07-091-1/+1
|
* Check the time stamp resolution up front before calculating with it.Guy Harris2018-07-091-17/+28
| | | | | | | | | | | | | | | ISO C says that if a left shift is done that's the full bit width of the operand being shifted, the behavior is undefined. In practice, it probably just does a single shift instruction, which does whatever it does with such a shift on the processor on which you're running; that is likely either to be "all the bits are cleared" or "no shift is done", but we can't rely on "all the bits are cleared". So, instead, check the time stamp resolution exponent before using it, and reject it if it'll result in a resolution that doesn't fit into a 32-bit quantity. Use uint8_t for an 8-bit unsigned integral quantity while we're at it.
* Rename sf-pcap-ng.[ch] to reflect that the file type is now called pcapng.Guy Harris2018-01-081-0/+1464