Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ fn main() {

fn from_pkg_config() -> Result<pkg_config::Library, pkg_config::Error> {
let mut config = pkg_config::Config::new();
config.cargo_metadata(false);
// If the user has went out of their way to specify LIBPCAP_VER (even though
// LIBCAP_LIBDIR wasn't set), respect it. Otherwise fall back to any version
// as long as it's supported.
Expand Down
3 changes: 3 additions & 0 deletions examples/easylisten.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "helpers/link.rs"]
mod link;

fn main() {
// get the default Device
let device = pcap::Device::lookup()
Expand Down
3 changes: 3 additions & 0 deletions examples/getdevices.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "helpers/link.rs"]
mod link;

fn main() {
// list all of the devices pcap tells us are available
for device in pcap::Device::list().expect("device lookup failed") {
Expand Down
3 changes: 3 additions & 0 deletions examples/getstatistics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "helpers/link.rs"]
mod link;

fn main() {
// get the default Device
let device = pcap::Device::lookup()
Expand Down
9 changes: 9 additions & 0 deletions examples/helpers/link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Trigger linking against the appropriate library for example binaries.

#[cfg(not(windows))]
#[link(name = "pcap")]
extern "C" {}

#[cfg(windows)]
#[link(name = "wpcap")]
extern "C" {}
3 changes: 3 additions & 0 deletions examples/iterprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
use pcap::{Capture, Device, Packet, PacketCodec, PacketHeader};
use std::error;

#[path = "helpers/link.rs"]
mod link;

/// Represents a owned packet
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PacketOwned {
Expand Down
3 changes: 3 additions & 0 deletions examples/lendingiterprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::error;

use gat_std::gatify;

#[path = "helpers/link.rs"]
mod link;

#[gatify]
fn main() -> Result<(), Box<dyn error::Error>> {
let device = Device::lookup()?.ok_or("no device available")?;
Expand Down
3 changes: 3 additions & 0 deletions examples/listenlocalhost.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "helpers/link.rs"]
mod link;

fn main() {
// listen on the device named "any", which is only available on Linux. This is only for
// demonstration purposes.
Expand Down
3 changes: 3 additions & 0 deletions examples/loop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "helpers/link.rs"]
mod link;

fn main() {
// get the default Device
let device = pcap::Device::lookup()
Expand Down
3 changes: 3 additions & 0 deletions examples/nfbpfcompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use pcap::{BpfProgram, Capture, Linktype};
use std::env;
use std::process;

#[path = "helpers/link.rs"]
mod link;

fn main() {
let (layertype, prog) = match env::args().len() {
2 => ("RAW".to_string(), env::args().nth(1).unwrap()),
Expand Down
3 changes: 3 additions & 0 deletions examples/savefile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use pcap::*;

#[path = "helpers/link.rs"]
mod link;

fn main() {
{
// open capture from default device
Expand Down
3 changes: 3 additions & 0 deletions examples/savemultiplefiles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use pcap::Capture;

#[path = "helpers/link.rs"]
mod link;

fn main() {
// get the default Device
let device = pcap::Device::lookup().unwrap().unwrap();
Expand Down
3 changes: 3 additions & 0 deletions examples/stdin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//! tcpdump -i en0 -U -w - | cargo run --example stdin
//!

#[path = "helpers/link.rs"]
mod link;

#[cfg(not(windows))]
mod inner {
use pcap::{Packet, PacketCodec, PacketHeader};
Expand Down
3 changes: 3 additions & 0 deletions examples/streamecho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use futures::StreamExt;
use pcap::{Active, Capture, Device, Error, Packet, PacketCodec, PacketStream};
use std::error;

#[path = "helpers/link.rs"]
mod link;

// Simple codec that returns owned copies, since the result may not
// reference the input packet.
pub struct BoxCodec;
Expand Down
3 changes: 3 additions & 0 deletions examples/streamlisten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use futures::StreamExt;
use pcap::{Active, Capture, Device, Error, Packet, PacketCodec, PacketStream};

#[path = "helpers/link.rs"]
mod link;

pub struct SimpleDumpCodec;

impl PacketCodec for SimpleDumpCodec {
Expand Down
3 changes: 3 additions & 0 deletions examples/streamlisten_mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use futures::StreamExt;
use pcap::{Active, Capture, Device, Error, Packet, PacketCodec, PacketStream};
use std::error;

#[path = "helpers/link.rs"]
mod link;

pub struct SimpleDumpCodec;

impl PacketCodec for SimpleDumpCodec {
Expand Down
2 changes: 0 additions & 2 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ pub mod ffi {
pub mod ffi_unix {
use super::*;

#[link(name = "pcap")]
extern "C" {
// pub fn pcap_inject(arg1: *mut pcap_t, arg2: *const c_void, arg3: size_t) -> c_int;
pub fn pcap_set_rfmon(arg1: *mut pcap_t, arg2: c_int) -> c_int;
Expand All @@ -287,7 +286,6 @@ pub mod ffi_windows {

pub const WINPCAP_MINTOCOPY_DEFAULT: c_int = 16000;

#[link(name = "wpcap")]
extern "C" {
pub fn pcap_setmintocopy(arg1: *mut pcap_t, arg2: c_int) -> c_int;
pub fn pcap_getevent(p: *mut pcap_t) -> HANDLE;
Expand Down
8 changes: 8 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ type suseconds_t = libc::suseconds_t;
#[allow(non_camel_case_types)]
type suseconds_t = libc::c_long;

#[cfg(not(windows))]
#[link(name = "pcap")]
extern "C" {}

#[cfg(windows)]
#[link(name = "wpcap")]
extern "C" {}

fn capture_from_test_file(file_name: &str) -> Capture<Offline> {
let path = Path::new("tests/data/").join(file_name);
Capture::from_file(path).unwrap()
Expand Down
3 changes: 3 additions & 0 deletions tests/tap_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#[cfg(not(windows))]
mod tests {

#[link(name = "pcap")]
extern "C" {}

use etherparse::{PacketBuilder, PacketHeaders};
use pcap::Capture;
use tun_tap::Iface;
Expand Down
Loading