107.4. bandwhich-0.23.1
Shows bandwidth use by process and connection
| Version | 0.23.1, release 1 |
| Shelf | net-diag — Network diagnostics, capture, measurement and low-level socket tools |
| Phase | 41_system (System), 783 of 1047 in build order |
| Licence | MIT |
| Homepage | https://github.com/imsnif/bandwhich |
| Build time | 1.1 SBU |
| Installed size | 4.4 MiB in 3 files |
| Recipe | ports/core/net-diag/bandwhich/kpkgbuild |
About
bandwhich shows, live in the terminal, which processes and which connections are using the network and how much bandwidth each takes. It sniffs packets on an interface and matches them to processes through /proc. It is built from its Rust vendor bundle with no network.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/net-diag.txt:
Needs CAP_NET_RAW and is not given it — there is no third setuid program on this system and a packet sniffer is not the one to add.
Sources
bandwhich-0.23.1.tar.gz(2.9 MiB)
sha256aafb96d059cf9734da915dca4f5940c319d2e6b54e2ffb884332e9f5e820e6d7
upstream: https://github.com/imsnif/bandwhich/archive/refs/tags/v0.23.1.tar.gz
archive copy: sources-3/net-diag--bandwhich-0.23.1.tar.gzbandwhich-vendor-0.23.1.tar.xz(27.3 MiB)
sha256a78e3222e44d12b8b6208845966be70ed56103f70ea909f026cb5ea6a92c883c
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-3/net-diag--bandwhich-vendor-0.23.1.tar.xz
Dependencies
Depends on: rust.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install bandwhich'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/net-diag/bandwhich.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/net-diag/bandwhich
echo 'aafb96d059cf9734da915dca4f5940c319d2e6b54e2ffb884332e9f5e820e6d7 bandwhich-0.23.1.tar.gz' | sha256sum -c -
echo 'a78e3222e44d12b8b6208845966be70ed56103f70ea909f026cb5ea6a92c883c bandwhich-vendor-0.23.1.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/bandwhich
SRC=$SRC_ROOT/bandwhich-0.23.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf bandwhich-0.23.1.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
mkdir -p gen
export BANDWHICH_GEN_DIR="$SRC/gen"
export RUSTFLAGS="-C target-feature=-crt-static"
cargo build --release --frozen --offline
install -Dm755 target/release/bandwhich $PKG/usr/bin/bandwhich
install -Dm644 gen/bandwhich.1 -t "$PKG/usr/share/man/man1"
The switches, and why each is set:
BANDWHICH_GEN_DIR— bandwhich’sbuild.rsrenders a manual page and a completion file for every shell clap knows into this directory, falling back to cargo’s hashedOUT_DIRundertarget/when it is unset. Pointing it atgen/in the source tree givesbuild.sha fixed path to installbandwhich.1from. The completion files land there too and are not installed.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/bandwhich, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf bandwhich-0.23.1-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/bandwhich, and runs the triggers its paths call for.
Contents
Installed programs: bandwhich.
Installed directories: /usr/share/licenses/bandwhich.
Notes
Capturing packets needs CAP_NET_RAW and CAP_NET_ADMIN, and matching a connection to its process needs CAP_SYS_PTRACE and CAP_DAC_READ_SEARCH to read other processes’ /proc/<pid>/fd/. The package grants none of them: bandwhich is not setuid and carries no file capability, so it runs as root or with the four capabilities set on the file yourself, as upstream’s README shows with setcap. See setuid binaries.