Skip to content

Commit 79304f4

Browse files
Don't automatically link to libpcap
pkg-config's default config will output `rustc-link-lib` when it finds a package. However, per this project's readme, linkage is the responsibility of the user, so it seems like merely probing for the version should not change any subsequent build config. Lines previously present in build.rs output that are now gone: ``` [pcap 2.3.0] cargo:rustc-link-search=native=/usr/lib/x86_64-linux-gnu [pcap 2.3.0] cargo:rustc-link-lib=pcap ``` Similarly, the `#[link(name = "pcap")]` in `raw` was making dependent binaries automatically link to libpcap.so.
1 parent f138c4b commit 79304f4

19 files changed

+63
-2
lines changed

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ fn main() {
197197

198198
fn from_pkg_config() -> Result<pkg_config::Library, pkg_config::Error> {
199199
let mut config = pkg_config::Config::new();
200+
config.cargo_metadata(false);
200201
// If the user has went out of their way to specify LIBPCAP_VER (even though
201202
// LIBCAP_LIBDIR wasn't set), respect it. Otherwise fall back to any version
202203
// as long as it's supported.

examples/easylisten.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[path = "helpers/link.rs"]
2+
mod link;
3+
14
fn main() {
25
// get the default Device
36
let device = pcap::Device::lookup()

examples/getdevices.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[path = "helpers/link.rs"]
2+
mod link;
3+
14
fn main() {
25
// list all of the devices pcap tells us are available
36
for device in pcap::Device::list().expect("device lookup failed") {

examples/getstatistics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[path = "helpers/link.rs"]
2+
mod link;
3+
14
fn main() {
25
// get the default Device
36
let device = pcap::Device::lookup()

examples/helpers/link.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Trigger linking against the appropriate library for example binaries.
2+
3+
#[cfg(not(windows))]
4+
#[link(name = "pcap")]
5+
extern "C" {}
6+
7+
#[cfg(windows)]
8+
#[link(name = "wpcap")]
9+
extern "C" {}

examples/iterprint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
use pcap::{Capture, Device, Packet, PacketCodec, PacketHeader};
33
use std::error;
44

5+
#[path = "helpers/link.rs"]
6+
mod link;
7+
58
/// Represents a owned packet
69
#[derive(Debug, Clone, PartialEq, Eq)]
710
pub struct PacketOwned {

examples/lendingiterprint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use std::error;
44

55
use gat_std::gatify;
66

7+
#[path = "helpers/link.rs"]
8+
mod link;
9+
710
#[gatify]
811
fn main() -> Result<(), Box<dyn error::Error>> {
912
let device = Device::lookup()?.ok_or("no device available")?;

examples/listenlocalhost.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[path = "helpers/link.rs"]
2+
mod link;
3+
14
fn main() {
25
// listen on the device named "any", which is only available on Linux. This is only for
36
// demonstration purposes.

examples/loop.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[path = "helpers/link.rs"]
2+
mod link;
3+
14
fn main() {
25
// get the default Device
36
let device = pcap::Device::lookup()

examples/nfbpfcompile.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use pcap::{BpfProgram, Capture, Linktype};
77
use std::env;
88
use std::process;
99

10+
#[path = "helpers/link.rs"]
11+
mod link;
12+
1013
fn main() {
1114
let (layertype, prog) = match env::args().len() {
1215
2 => ("RAW".to_string(), env::args().nth(1).unwrap()),

0 commit comments

Comments
 (0)