aboutsummaryrefslogtreecommitdiff
path: root/pcap-linux.c
Commit message (Collapse)AuthorAgeFilesLines
...
* | Clean up pcap_do_addexit() and calls to it.Guy Harris2016-02-221-2/+0
| | | | | | | | | | | | | | | | atexit() is only specified in standards as returning "a non-zero value" on error; don't assume it returns -1, even if it's documented as doing so on some platforms. pcap_do_addexit() already fills in p->errbuf; don't do so in its callers.
* | Split out the UN*X flags to pcap flags mapping.Guy Harris2016-01-251-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | Add an if_flags_to_pcap_flags() routine to map the interface name (if necessary) and IFF_ flags to PCAP_IF_ flags, and call that in the platform-specific routines. That means that the calls to add to the interface list don't need to use IFF_ flags, which are UN*Xisms. Move the routines that update the interface list to fad-helpers.c, leaving just the legacy APIs in inet.c. Update finalldevstest to print out all the flags.
* | Clean up indentation.Guy Harris2015-12-241-1/+1
| |
* | OK, fine, PF_UNIX/SOCK_RAW.Guy Harris2015-12-241-3/+3
| | | | | | | | | | That way, you can at least get interface flags and time stamping capabilities without requiring permission to actually open a device.
* | Use PF_PACKET/SOCK_RAW sockets as "generic" sockets.Guy Harris2015-12-241-3/+3
| | | | | | | | | | That way, uou don't have to have AF_INET support. (You have to have PF_PACKET support, but you need that for those code paths *anyway*.)
* | More cleanups of the "is this a bonding device?" check.Guy Harris2015-12-221-9/+11
| |
* | Clean up the "is this a bond device" check.Guy Harris2015-12-221-5/+6
| |
* | Add some comments to better explain the VLAN tag insertion.Guy Harris2015-11-081-1/+34
| | | | | | | | | | Also, calculate the VLAN tag offset for DLT_LINUX_SLL based on the DLT_LINUX_SLL header length, to make the code clearer.
* | Use pcap_snprintf() instead of snprintf().Guy Harris2015-11-031-102/+102
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Fix warnings as "C++ style comments are not allowed in ISO C90"Francois-Xavier Le Bail2015-09-051-2/+2
| |
* | Don't dereference a known-to-be-null pointer.Guy Harris2015-09-031-1/+1
| | | | | | | | | | | | | | handlep->mondevice is null because strdup() failed; don't pass it to del_mon_if(), pass what we tried to duplicate. Fixes Coverity issue 1322848.
* | Fix some compile errors.Guy Harris2015-09-021-1/+6
| |
* | Fix warning as "ISO C90 forbids mixed declarations and code"Francois-Xavier Le Bail2015-09-021-1/+3
| |
* | Make the buffer member of a pcap_t a void *.Guy Harris2015-08-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Set handlep->mondevice in add_mon_if(), and fail if strdup() fails.Guy Harris2015-07-131-2/+24
| | | | | | | | | | | | | | That catches an admittedly-unlikely-but-not-impossible failure mode, and cleans up a bit more, removing the newly-created monitor device. Also clean up better if atexit() fails.
* | Check for both SO_BPF_EXTENSIONS and SKF_AD_VLAN_TAG_PRESENT.Guy Harris2015-06-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Apparently, RHEL 6.3 and CentOS 6.4 define SO_BPF_EXTENSIONS but not SKF_AD_VLAN_TAG_PRESENT in the userland header files; the kernel that comes with them appears not to define or use either of them, so I guess it doesn't actually support them. Work around that nonsense by checking for both of them rather than just for SO_BPF_EXTENSIONS. Fixes GitHub issue #443.
* | Add another necessary "#ifdef HAVE_TPACKET3" check.Guy Harris2015-06-081-0/+2
| | | | | | | | Fixes GitHub issue #441.
* | Another comment to note why we poll with a timeout of 0 in non-blocking mode.Guy Harris2015-06-041-2/+8
| |
* | Note why we use poll() even in non-blocking mode.Guy Harris2015-06-041-0/+8
| | | | | | | | | | With memory-mapped sockets, you have to call poll() to receive error indications.
* | Don't timeout poll() with TPACKET_V3 in 3.19 and later.Guy Harris2015-06-041-18/+62
| | | | | | | | | | | | | | | | | | | | | | | | We don't need to do the workaround for not getting wakeups when buffers are handed to us, nor do we have to do a timeout in poll() for the benefit of programs that expect the timeout to expire even if no packets have arrived, so, with TPACKET_V3 in 3.19 and later, we always use a timeout of -1 for poll(). This eliminates some spurious wakeups from poll(), due to the poll() call *itself* timing out, that turn into spurious timeouts; see GitHub issue #383.
* | Clean up the frame processing in memory-mapped captures.Guy Harris2015-06-031-119/+148
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Pull the check for the current ring buffer frame being owned by the kernel out of pcap_wait_for_frames_mmap() and move it to its callers. Replace most calls to pcap_get_ring_frame() with the appropriate code for that particular version of tpacket; in most places, it's already known what version of tpacket we have. The one remaining place is the place in the pcap_setfilter() code where we scan backwards to find out which packet buffers have already been processed by the old filter; change that one *not* to move the current pointer backwards and then restore it, but to check arbitrary buffers in the ring. Have a pcap_get_ring_frame_status() routine which gets the status field of a specified buffer. When checking a buffer's status, check against TP_STATUS_KERNEL; it's either exactly TP_STATUS_KERNEL, meaning it's owned by the kernel, or it's TP_STATUS_USER ORed with zero or more flags, meaning it's owned by userland. This makes it a bit more obvious, in the pcap_read_linux_mmap_XXX routines, what's being done.
* | Don't calculate the poll timeout on every poll call().Guy Harris2015-06-031-30/+44
| | | | | | | | | | Instead, save it in the private per-handle structure, calculate it at activate time, and recalculate it every time it needs to change.
* | Don't use struct ifbond when there's no if_binding.hBaruch Siach2015-06-021-2/+4
| | | | | | | | | | | | | | | | | | | | | | Fixes build failures like: ./pcap-linux.c: In function ‘is_bonding_device’: ./pcap-linux.c:962: error: ‘ifbond’ undeclared (first use in this function) ./pcap-linux.c:962: error: (Each undeclared identifier is reported only once ./pcap-linux.c:962: error: for each function it appears in.) ./pcap-linux.c:962: error: expected ‘;’ before ‘ifb’ ./pcap-linux.c:966: error: ‘ifb’ undeclared (first use in this function)
* | Use pcap_close() if pcap_create_handle() fails.Guy Harris2015-05-041-4/+2
|/ | | | | | | 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.
* Work around a Linux bonding driver bug.Guy Harris2015-03-301-0/+52
| | | | | | | | | Bonding devices on Linux return ENODEV for unknown socket ioctls, rather than returning a normal "not supported" error such as ENOTSUP or EOPNOTSUPP or ENOTTY, so, if we try Wireless Extension ioctls on them, we get "no such device" errors rather than "no Wireless Extensions" errors. Check for bonding devices, if possible, and avoid doing Wireless Extensions ioctls on them.
* Fix error message.Guy Harris2015-03-291-1/+1
|
* Delete trailing spaces/tabsFrancois-Xavier Le Bail2015-03-081-1/+1
|
* Delete trailing spaces/tabsFrancois-Xavier Le Bail2015-03-081-34/+34
|
* Merge pull request #422 from busterb/tpacket-v1Guy Harris2015-02-251-2/+0
|\ | | | | remove duplicate includes, align h1_64 with the other struct members
| * remove duplicate includes, align h1_64Brent Cook2015-02-251-3/+1
| |
* | Handle non-x86 K64/U32 combinations.Guy Harris2015-02-251-15/+75
| | | | | | | | | | | | | | | | | | | | | | Have a gauntlet of ISAs where the ISA has both 32-bit and 64-bit flavors and Linux has supported the 64-bit flavor since before TPACKET_V2 as introduced; define ISA_64_BIT to the uname() .machine value for the 64-bit architecture, and compare against that, rather than a hardcoded "x86_64". Clean up white space, expand some comments, and check whether uname() fails.
* | Make prepare_tpacket_socket() a bit more of a straightforward gauntlet.Guy Harris2015-02-251-24/+48
|/ | | | | | | | | | | | | | Try TPACKET_V3 first, if it's defined and if immediate mode was not requested; return if that succeeds or if it fails for a reason other than "the kernel doesn't support TPACKET_V3". Then try TPACKET_V2, if it's defined; return if that succeeds or fails for a reson other than "the kernel doesn't support TPACKET_V2". Then go with TPACKET_V1 or TPACKET_V1_64. Don't set handlep->tp_version to TPACKET_V1 and handlep->tp_hdrlen to sizeof(struct tpacket_hdr) until after we've found out that the kernel supports neither TPACKET_V2 nor TPACKET_V3; init_tpacket() sets them if it succeeds.
* whitespaceBrent Cook2015-02-251-5/+5
|
* remove superfluous debug message, clarify commentBrent Cook2015-02-251-4/+5
|
* linux 64-bit kernel + 32-bit TPACKET V1 userspace workaroundBrent Cook2015-02-251-0/+114
| | | | | This is a port of the patch from an earlier bug report: https://bugzilla.redhat.com/show_bug.cgi?id=557728
* Check /sys/class/net/{device}/wireless first when checking for Wi-Fi devices.Guy Harris2015-02-231-19/+55
| | | | | | | | | If there's a /sys/class/net/{device}/wireless directory for {device}, then it's a Wi-Fi device; check that first, and only use the wireless extensions if that directory doesn't exist, to handle kernels that don't have /sys or do but don't have /sys/class/net/{device}/wireless directories. That way, we don't depend on Wi-Fi devices (or the kernel) supporting the wireless extensions, at least for newer kernels.
* Fix previous change.Guy Harris2015-02-201-6/+10
|
* Check for Wi-Fi interfaces and don't offer DOCSIS on them.Guy Harris2015-02-201-10/+21
|
* We only need the offloading information if we're using turbopacket.Guy Harris2015-02-151-0/+5
| | | | | Don't define iface_get_offload(), or anything it uses, if HAVE_PACKET_RING isn't defined.
* Merge pull request #358 from bonsaiviking/config-packet-ringMichael Richardson2015-02-151-0/+2
|\ | | | | Add the --disable-packet-ring configure option.
| * Add the --disable-packet-ring configure option.Daniel Miller2014-06-051-0/+2
| | | | | | | | | | | | | | | | This allows the creation of 32-bit binaries that are compatible with 64-bit Linux kernels before version 2.6.27. Original patch credit: David Fifield of the Nmap project (https://svn.nmap.org/nmap/libpcap/NMAP_MODIFICATIONS/0002-Add-the-disable-packet-ring-configure-option.patch)
* | Merge pull request #346 from atzm/linux-vlan-tpidMichael Richardson2015-02-151-5/+15
|\ \ | | | | | | pcap-linux: Obtain VLAN TPID from the kernel when available
| * | pcap-linux: Fix the VLAN TPID handling for the readabilityAtzm Watanabe2014-04-091-16/+9
| | | | | | | | | | | | Unify the VLAN TPID selection logic into a helper macro VLAN_TPID().
| * | pcap-linux: Obtain VLAN TPID from the kernel when availableAtzm Watanabe2014-03-251-5/+22
| | | | | | | | | | | | | | | | | | | | | The VLAN TPID was hardcoded in pcap-linux.c but recent Linux kernel supports 802.1ad Q-in-Q. Since Linux 3.14, kernel gives the TPID value to the userspace when available.
* | | Make sure the userland filtering happens correctly on cooked interfaces.Tommy Beadle2015-02-101-21/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If filtering in userland and capturing on a cooked interface, the packet buffer being sent to bpf_filter_with_aux_data did not include the sll header, so the filter was being applied improperly. The buffer would start at the layer3 header. This change moves the code to fill out the sll structure and update the bp pointer to point to it to before the call to bpf_filter_with_aux_data.
* | | Some cleanups.Guy Harris2015-02-051-4/+8
| | |
* | | Clean up error message.Guy Harris2015-02-051-1/+1
| | |
* | | tp_mac and tp_snaplen are unsigned; print them with %u, not %d.Guy Harris2015-02-051-1/+1
| | | | | | | | | | | | See, for example, GitHub libpcap issue #404.
* | | pcap-linux.c: Closing the file descriptorBaptiste Peugnez2015-02-031-1/+1
| | | | | | | | | | | | The file descriptor was not closed in the right place
* | | pcap-linux.c: Initialize variable lenBaptiste PEUGNEZ2015-01-271-1/+1
| | | | | | | | | | | | The variable "len" contains the buffer size "& bpf_extensions" but len is not initialized.