| 1 | #!/usr/bin/env bash |
| 2 | set -eu |
| 3 | |
| 4 | readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 5 | |
| 6 | readonly LIBPCAP_DIR="$DIR/libpcap" |
| 7 | if ! [ -f "$LIBPCAP_DIR/.git" ]; then |
| 8 | 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/null 2>&1; then |
| 15 | echo "bindgen must be installed" >&2 |
| 16 | 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" |