| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | set -eu |
| 3 | |
| 4 | readonly DIR=$( cd "$( dirnamescip-shell system . . dirname. "${BASH_SOURCE[0]}" )" && pwdscip-shell system . . pwd. ) |
| 5 | |
| 6 | readonly LIBPCAP_DIR="$DIR/libpcap" |
| 7 | if ! [scip-shell system . . `[`. -f "$LIBPCAP_DIR/.git" ]; then |
| 8 | gitscip-shell system . . git. submodule update --init |
| 9 | fi |
| 10 | |
| 11 | readonly PCAP_HEADER="$LIBPCAP_DIR/pcap.h" |
| 12 | readonly PCAP_BINDINGS="$DIR/src/bindings.rs" |
| 13 | |
| 14 | if ! command -v bindgen > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 15 | echoscip-shell system . . echo. "bindgen must be installed" >&2 |
| 16 | echoscip-shell system . . echo. "to install: cargo install bindgen && rustup component add rustfmt-preview" >&2 |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | bindgen \ |
| 21 | "$PCAP_HEADER" \ |
| 22 | --ctypes-prefix 'libc' \ |
| 23 | --raw-line 'extern crate libc;' \ |
| 24 | --raw-line '#[cfg(windows)] extern crate winapi;' \ |
| 25 | --raw-line 'pub use libc::FILE;' \ |
| 26 | --raw-line '#[cfg(unix)] pub use libc::{sockaddr, timeval};' \ |
| 27 | --raw-line '#[cfg(windows)] pub use winapi::shared::ws2def::SOCKADDR as sockaddr;' \ |
| 28 | --raw-line '#[cfg(windows)] pub use winapi::um::winsock2::timeval;' \ |
| 29 | --whitelist-function '^pcap_.*' \ |
| 30 | --whitelist-type '^pcap_.*' \ |
| 31 | --whitelist-var '^PCAP_.*' \ |
| 32 | --blacklist-type 'sockaddr' \ |
| 33 | --blacklist-type 'timeval' \ |
| 34 | --blacklist-type '__.*' \ |
| 35 | --blacklist-type 'FILE' \ |
| 36 | --blacklist-type 'fpos_t' \ |
| 37 | --distrust-clang-mangling \ |
| 38 | --no-layout-tests \ |
| 39 | -o "$PCAP_BINDINGS" |