pcap-sys-0.1.3/build.rs010064400007650000024000000045431337217617200131550ustar0000000000000000#[cfg(unix)] extern crate pkg_config; #[cfg(windows)] use std::path::PathBuf; #[cfg(unix)] use std::process::Command; #[cfg(windows)] fn main() { let dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let mut lib_path = PathBuf::from(&dir).join("Lib"); if cfg!(target_arch = "x86_64") { lib_path.push("x64") } println!("cargo:rustc-link-search=native={}", lib_path.display()); println!("cargo:rustc-link-lib=packet"); println!("cargo:rustc-link-lib=wpcap"); } #[cfg(unix)] fn main() { // First, try pkg_config (available in libpcap 1.9.0+) if pkg_config::probe_library("libpcap").is_ok() { return; } // Fall back to pcap-config match Command::new("pcap-config").arg("--libs").output() { Ok(output) => { parse_libs_cflags(&output.stdout) }, _ => (), } // on macOS, pcap-config returns /usr/local/lib, but libpcap is actually in /usr/lib println!("cargo:rustc-link-search=native=/usr/lib"); } /// Adapted from pkg_config #[cfg(unix)] fn parse_libs_cflags(output: &[u8]) { let words = split_flags(output); let parts = words .iter() .filter(|l| l.len() > 2) .map(|arg| (&arg[0..2], &arg[2..])) .collect::>(); for &(flag, val) in &parts { match flag { "-L" => { println!("cargo:rustc-link-search=native={}", val); } "-F" => { println!("cargo:rustc-link-search=framework={}", val); } "-l" => { println!("cargo:rustc-link-lib={}", val); } _ => {} } } } /// Copied from pkg_config #[cfg(unix)] fn split_flags(output: &[u8]) -> Vec { let mut word = Vec::new(); let mut words = Vec::new(); let mut escaped = false; for &b in output { match b { _ if escaped => { escaped = false; word.push(b); } b'\\' => escaped = true, b'\t' | b'\n' | b'\r' | b' ' => { if !word.is_empty() { words.push(String::from_utf8(word).unwrap()); word = Vec::new(); } } _ => word.push(b), } } if !word.is_empty() { words.push(String::from_utf8(word).unwrap()); } words } pcap-sys-0.1.3/Cargo.toml.orig010064400007650000024000000010341337220230300143510ustar0000000000000000[package] name = "pcap-sys" version = "0.1.3" description = "Low-level bindings to libpcap" homepage = "https://github.com/jmmk/rustcap" repository = "https://github.com/jmmk/rustcap" authors = ["Michael McLellan "] keywords = ["pcap", "libpcap"] build = "build.rs" license = "MIT" readme = "README.md" documentation = "https://docs.rs/pcap-sys" [dependencies] libc = "0.2.43" [target.'cfg(windows)'.dependencies.winapi] version = "0.3.6" features = ["ws2def", "winsock2"] [build-dependencies] pkg-config = "0.3.14" pcap-sys-0.1.3/Cargo.toml0000644000000020650000000000000106340ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "pcap-sys" version = "0.1.3" authors = ["Michael McLellan "] build = "build.rs" description = "Low-level bindings to libpcap" homepage = "https://github.com/jmmk/rustcap" documentation = "https://docs.rs/pcap-sys" readme = "README.md" keywords = ["pcap", "libpcap"] license = "MIT" repository = "https://github.com/jmmk/rustcap" [dependencies.libc] version = "0.2.43" [build-dependencies.pkg-config] version = "0.3.14" [target."cfg(windows)".dependencies.winapi] version = "0.3.6" features = ["ws2def", "winsock2"] pcap-sys-0.1.3/Cargo.toml.orig0000644000000010340000000000000115660ustar00[package] name = "pcap-sys" version = "0.1.3" description = "Low-level bindings to libpcap" homepage = "https://github.com/jmmk/rustcap" repository = "https://github.com/jmmk/rustcap" authors = ["Michael McLellan "] keywords = ["pcap", "libpcap"] build = "build.rs" license = "MIT" readme = "README.md" documentation = "https://docs.rs/pcap-sys" [dependencies] libc = "0.2.43" [target.'cfg(windows)'.dependencies.winapi] version = "0.3.6" features = ["ws2def", "winsock2"] [build-dependencies] pkg-config = "0.3.14" pcap-sys-0.1.3/generate-bindings010075500007650000024000000023421336773020100150070ustar0000000000000000#!/usr/bin/env bash set -eu readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) readonly LIBPCAP_DIR="$DIR/libpcap" if ! [ -f "$LIBPCAP_DIR/.git" ]; then git submodule update --init fi readonly PCAP_HEADER="$LIBPCAP_DIR/pcap.h" readonly PCAP_BINDINGS="$DIR/src/bindings.rs" if ! command -v bindgen > /dev/null 2>&1; then echo "bindgen must be installed" >&2 echo "to install: cargo install bindgen && rustup component add rustfmt-preview" >&2 exit 1 fi bindgen \ "$PCAP_HEADER" \ --ctypes-prefix 'libc' \ --raw-line 'extern crate libc;' \ --raw-line '#[cfg(windows)] extern crate winapi;' \ --raw-line 'pub use libc::FILE;' \ --raw-line '#[cfg(unix)] pub use libc::{sockaddr, timeval};' \ --raw-line '#[cfg(windows)] pub use winapi::shared::ws2def::SOCKADDR as sockaddr;' \ --raw-line '#[cfg(windows)] pub use winapi::um::winsock2::timeval;' \ --whitelist-function '^pcap_.*' \ --whitelist-type '^pcap_.*' \ --whitelist-var '^PCAP_.*' \ --blacklist-type 'sockaddr' \ --blacklist-type 'timeval' \ --blacklist-type '__.*' \ --blacklist-type 'FILE' \ --blacklist-type 'fpos_t' \ --distrust-clang-mangling \ --no-layout-tests \ -o "$PCAP_BINDINGS" pcap-sys-0.1.3/LICENSE-MIT010064400007650000024000000020401336774362500131410ustar0000000000000000Copyright 2018 Michael McLellan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pcap-sys-0.1.3/README.md010064400007650000024000000006311337005302200127430ustar0000000000000000# pcap-sys Low-level bindings to libpcap [![*nix build status](https://travis-ci.org/jmmk/rustcap.svg?branch=master)](https://travis-ci.org/jmmk/rustcap) [![Windows build status](https://ci.appveyor.com/api/projects/status/6rf0ygpcww6fegt2/branch/master?svg=true)](https://ci.appveyor.com/project/jmmk/rustcap/branch/master) [![](http://meritbadge.herokuapp.com/pcap-sys)](https://crates.io/crates/pcap-sys) pcap-sys-0.1.3/src/bindings.rs010064400007650000024000000270051336773523500144450ustar0000000000000000/* automatically generated by rust-bindgen */ extern crate libc; #[cfg(windows)] extern crate winapi; pub use libc::FILE; #[cfg(unix)] pub use libc::{sockaddr, timeval}; #[cfg(windows)] pub use winapi::shared::ws2def::SOCKADDR as sockaddr; #[cfg(windows)] pub use winapi::um::winsock2::timeval; pub const PCAP_VERSION_MAJOR: u32 = 2; pub const PCAP_VERSION_MINOR: u32 = 4; pub const PCAP_ERRBUF_SIZE: u32 = 256; pub const PCAP_IF_LOOPBACK: u32 = 1; pub const PCAP_IF_UP: u32 = 2; pub const PCAP_IF_RUNNING: u32 = 4; pub const PCAP_ERROR: i32 = -1; pub const PCAP_ERROR_BREAK: i32 = -2; pub const PCAP_ERROR_NOT_ACTIVATED: i32 = -3; pub const PCAP_ERROR_ACTIVATED: i32 = -4; pub const PCAP_ERROR_NO_SUCH_DEVICE: i32 = -5; pub const PCAP_ERROR_RFMON_NOTSUP: i32 = -6; pub const PCAP_ERROR_NOT_RFMON: i32 = -7; pub const PCAP_ERROR_PERM_DENIED: i32 = -8; pub const PCAP_ERROR_IFACE_NOT_UP: i32 = -9; pub const PCAP_ERROR_CANTSET_TSTAMP_TYPE: i32 = -10; pub const PCAP_ERROR_PROMISC_PERM_DENIED: i32 = -11; pub const PCAP_ERROR_TSTAMP_PRECISION_NOTSUP: i32 = -12; pub const PCAP_WARNING: u32 = 1; pub const PCAP_WARNING_PROMISC_NOTSUP: u32 = 2; pub const PCAP_WARNING_TSTAMP_TYPE_NOTSUP: u32 = 3; pub const PCAP_NETMASK_UNKNOWN: u32 = 4294967295; pub const PCAP_TSTAMP_HOST: u32 = 0; pub const PCAP_TSTAMP_HOST_LOWPREC: u32 = 1; pub const PCAP_TSTAMP_HOST_HIPREC: u32 = 2; pub const PCAP_TSTAMP_ADAPTER: u32 = 3; pub const PCAP_TSTAMP_ADAPTER_UNSYNCED: u32 = 4; pub const PCAP_TSTAMP_PRECISION_MICRO: u32 = 0; pub const PCAP_TSTAMP_PRECISION_NANO: u32 = 1; pub type u_char = libc::c_uchar; pub type u_short = libc::c_ushort; pub type u_int = libc::c_uint; pub type bpf_int32 = libc::c_int; pub type bpf_u_int32 = u_int; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct bpf_program { pub bf_len: u_int, pub bf_insns: *mut bpf_insn, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct bpf_insn { pub code: u_short, pub jt: u_char, pub jf: u_char, pub k: bpf_u_int32, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct pcap { _unused: [u8; 0], } pub type pcap_t = pcap; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct pcap_dumper { _unused: [u8; 0], } pub type pcap_dumper_t = pcap_dumper; pub type pcap_if_t = pcap_if; pub type pcap_addr_t = pcap_addr; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct pcap_file_header { pub magic: bpf_u_int32, pub version_major: u_short, pub version_minor: u_short, pub thiszone: bpf_int32, pub sigfigs: bpf_u_int32, pub snaplen: bpf_u_int32, pub linktype: bpf_u_int32, } pub const pcap_direction_t_PCAP_D_INOUT: pcap_direction_t = 0; pub const pcap_direction_t_PCAP_D_IN: pcap_direction_t = 1; pub const pcap_direction_t_PCAP_D_OUT: pcap_direction_t = 2; pub type pcap_direction_t = u32; #[repr(C)] pub struct pcap_pkthdr { pub ts: timeval, pub caplen: bpf_u_int32, pub len: bpf_u_int32, pub comment: [libc::c_char; 256usize], } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct pcap_stat { pub ps_recv: u_int, pub ps_drop: u_int, pub ps_ifdrop: u_int, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct pcap_if { pub next: *mut pcap_if, pub name: *mut libc::c_char, pub description: *mut libc::c_char, pub addresses: *mut pcap_addr, pub flags: bpf_u_int32, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct pcap_addr { pub next: *mut pcap_addr, pub addr: *mut sockaddr, pub netmask: *mut sockaddr, pub broadaddr: *mut sockaddr, pub dstaddr: *mut sockaddr, } pub type pcap_handler = ::std::option::Option< unsafe extern "C" fn(arg1: *mut u_char, arg2: *const pcap_pkthdr, arg3: *const u_char), >; extern "C" { pub fn pcap_lookupdev(arg1: *mut libc::c_char) -> *mut libc::c_char; } extern "C" { pub fn pcap_lookupnet( arg1: *const libc::c_char, arg2: *mut bpf_u_int32, arg3: *mut bpf_u_int32, arg4: *mut libc::c_char, ) -> libc::c_int; } extern "C" { pub fn pcap_create(arg1: *const libc::c_char, arg2: *mut libc::c_char) -> *mut pcap_t; } extern "C" { pub fn pcap_set_snaplen(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_promisc(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_can_set_rfmon(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_set_rfmon(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_timeout(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_tstamp_type(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_immediate_mode(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_buffer_size(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_tstamp_precision(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_get_tstamp_precision(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_activate(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_apple_set_exthdr(p: *mut pcap_t, arg1: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_list_tstamp_types(arg1: *mut pcap_t, arg2: *mut *mut libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_free_tstamp_types(arg1: *mut libc::c_int); } extern "C" { pub fn pcap_tstamp_type_name_to_val(arg1: *const libc::c_char) -> libc::c_int; } extern "C" { pub fn pcap_tstamp_type_val_to_name(arg1: libc::c_int) -> *const libc::c_char; } extern "C" { pub fn pcap_tstamp_type_val_to_description(arg1: libc::c_int) -> *const libc::c_char; } extern "C" { pub fn pcap_open_live( arg1: *const libc::c_char, arg2: libc::c_int, arg3: libc::c_int, arg4: libc::c_int, arg5: *mut libc::c_char, ) -> *mut pcap_t; } extern "C" { pub fn pcap_open_dead(arg1: libc::c_int, arg2: libc::c_int) -> *mut pcap_t; } extern "C" { pub fn pcap_open_dead_with_tstamp_precision( arg1: libc::c_int, arg2: libc::c_int, arg3: u_int, ) -> *mut pcap_t; } extern "C" { pub fn pcap_open_offline_with_tstamp_precision( arg1: *const libc::c_char, arg2: u_int, arg3: *mut libc::c_char, ) -> *mut pcap_t; } extern "C" { pub fn pcap_open_offline(arg1: *const libc::c_char, arg2: *mut libc::c_char) -> *mut pcap_t; } extern "C" { pub fn pcap_fopen_offline_with_tstamp_precision( arg1: *mut FILE, arg2: u_int, arg3: *mut libc::c_char, ) -> *mut pcap_t; } extern "C" { pub fn pcap_fopen_offline(arg1: *mut FILE, arg2: *mut libc::c_char) -> *mut pcap_t; } extern "C" { pub fn pcap_close(arg1: *mut pcap_t); } extern "C" { pub fn pcap_loop( arg1: *mut pcap_t, arg2: libc::c_int, arg3: pcap_handler, arg4: *mut u_char, ) -> libc::c_int; } extern "C" { pub fn pcap_dispatch( arg1: *mut pcap_t, arg2: libc::c_int, arg3: pcap_handler, arg4: *mut u_char, ) -> libc::c_int; } extern "C" { pub fn pcap_next(arg1: *mut pcap_t, arg2: *mut pcap_pkthdr) -> *const u_char; } extern "C" { pub fn pcap_next_ex( arg1: *mut pcap_t, arg2: *mut *mut pcap_pkthdr, arg3: *mut *const u_char, ) -> libc::c_int; } extern "C" { pub fn pcap_breakloop(arg1: *mut pcap_t); } extern "C" { pub fn pcap_stats(arg1: *mut pcap_t, arg2: *mut pcap_stat) -> libc::c_int; } extern "C" { pub fn pcap_setfilter(arg1: *mut pcap_t, arg2: *mut bpf_program) -> libc::c_int; } extern "C" { pub fn pcap_setdirection(arg1: *mut pcap_t, arg2: pcap_direction_t) -> libc::c_int; } extern "C" { pub fn pcap_getnonblock(arg1: *mut pcap_t, arg2: *mut libc::c_char) -> libc::c_int; } extern "C" { pub fn pcap_setnonblock( arg1: *mut pcap_t, arg2: libc::c_int, arg3: *mut libc::c_char, ) -> libc::c_int; } extern "C" { pub fn pcap_inject(arg1: *mut pcap_t, arg2: *const libc::c_void, arg3: usize) -> libc::c_int; } extern "C" { pub fn pcap_sendpacket( arg1: *mut pcap_t, arg2: *const u_char, arg3: libc::c_int, ) -> libc::c_int; } extern "C" { pub fn pcap_statustostr(arg1: libc::c_int) -> *const libc::c_char; } extern "C" { pub fn pcap_strerror(arg1: libc::c_int) -> *const libc::c_char; } extern "C" { pub fn pcap_geterr(arg1: *mut pcap_t) -> *mut libc::c_char; } extern "C" { pub fn pcap_perror(arg1: *mut pcap_t, arg2: *const libc::c_char); } extern "C" { pub fn pcap_compile( arg1: *mut pcap_t, arg2: *mut bpf_program, arg3: *const libc::c_char, arg4: libc::c_int, arg5: bpf_u_int32, ) -> libc::c_int; } extern "C" { pub fn pcap_compile_nopcap( arg1: libc::c_int, arg2: libc::c_int, arg3: *mut bpf_program, arg4: *const libc::c_char, arg5: libc::c_int, arg6: bpf_u_int32, ) -> libc::c_int; } extern "C" { pub fn pcap_freecode(arg1: *mut bpf_program); } extern "C" { pub fn pcap_offline_filter( arg1: *const bpf_program, arg2: *const pcap_pkthdr, arg3: *const u_char, ) -> libc::c_int; } extern "C" { pub fn pcap_datalink(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_datalink_ext(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_list_datalinks(arg1: *mut pcap_t, arg2: *mut *mut libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_set_datalink(arg1: *mut pcap_t, arg2: libc::c_int) -> libc::c_int; } extern "C" { pub fn pcap_free_datalinks(arg1: *mut libc::c_int); } extern "C" { pub fn pcap_datalink_name_to_val(arg1: *const libc::c_char) -> libc::c_int; } extern "C" { pub fn pcap_datalink_val_to_name(arg1: libc::c_int) -> *const libc::c_char; } extern "C" { pub fn pcap_datalink_val_to_description(arg1: libc::c_int) -> *const libc::c_char; } extern "C" { pub fn pcap_snapshot(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_is_swapped(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_major_version(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_minor_version(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_file(arg1: *mut pcap_t) -> *mut FILE; } extern "C" { pub fn pcap_fileno(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_dump_open(arg1: *mut pcap_t, arg2: *const libc::c_char) -> *mut pcap_dumper_t; } extern "C" { pub fn pcap_dump_fopen(arg1: *mut pcap_t, fp: *mut FILE) -> *mut pcap_dumper_t; } extern "C" { pub fn pcap_dump_open_append( arg1: *mut pcap_t, arg2: *const libc::c_char, ) -> *mut pcap_dumper_t; } extern "C" { pub fn pcap_dump_file(arg1: *mut pcap_dumper_t) -> *mut FILE; } extern "C" { pub fn pcap_dump_ftell(arg1: *mut pcap_dumper_t) -> libc::c_long; } extern "C" { pub fn pcap_dump_flush(arg1: *mut pcap_dumper_t) -> libc::c_int; } extern "C" { pub fn pcap_dump_close(arg1: *mut pcap_dumper_t); } extern "C" { pub fn pcap_dump(arg1: *mut u_char, arg2: *const pcap_pkthdr, arg3: *const u_char); } extern "C" { pub fn pcap_findalldevs(arg1: *mut *mut pcap_if_t, arg2: *mut libc::c_char) -> libc::c_int; } extern "C" { pub fn pcap_freealldevs(arg1: *mut pcap_if_t); } extern "C" { pub fn pcap_lib_version() -> *const libc::c_char; } extern "C" { pub fn pcap_get_selectable_fd(arg1: *mut pcap_t) -> libc::c_int; } extern "C" { pub fn pcap_get_selectable_fd_list( arg1: *mut pcap_t, arg2: *mut *mut libc::c_int, ) -> libc::c_int; } extern "C" { pub fn pcap_free_selectable_fd_list(arg1: *mut libc::c_int); } pcap-sys-0.1.3/src/lib.rs010064400007650000024000000002461336320770600134050ustar0000000000000000#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] #[cfg(windows)] extern crate winapi; extern crate libc; pub use bindings::*; mod bindings; pcap-sys-0.1.3/.cargo_vcs_info.json0000644000000001120000000000000126250ustar00{ "git": { "sha1": "1684f3c23e98660c62cff8958bb1c52b5aa85985" } }