From 24d11ef61875cf6fcb8c661d83f9e5fb7006cd78 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sat, 11 May 2013 14:58:29 +0200 Subject: Add stats procedure --- bpf-interface.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bpf-interface.scm b/bpf-interface.scm index a76228f..2022b52 100644 --- a/bpf-interface.scm +++ b/bpf-interface.scm @@ -8,7 +8,7 @@ ;;; OS X seems to support only the smallest common denominator. (module bpf-interface (bpf-open bpf-close bpf? bpf-buffer-length bpf-flush! - bpf-interface bpf-interface-set! + bpf-interface bpf-interface-set! bpf-stats bpf-datalink-type bpf-datalink-type-set! bpf-list-datalink-types bpf-read-timeout bpf-read-timeout-set!) @@ -191,5 +191,23 @@ (ioctl (bpf-fd bpf) (foreign-value "BIOCSRTIMEOUT" int) (location tv)) (void))) +(define (bpf-stats bpf) + (let ((st (make-blob (foreign-value "sizeof(struct bpf_stat)" int)))) + (ioctl (bpf-fd bpf) (foreign-value "BIOCGSTATS" int) (location st)) + (let ((result '())) + (let-syntax ((add-stat! + (syntax-rules () + ((_ ?scheme-name ?c-name) + (set! result + (alist-cons '?scheme-name + ((foreign-lambda* unsigned-integer64 + (((c-pointer "struct bpf_stat") st)) + "C_return((uint64_t)st->" ?c-name ");") + (location st)) + result)))))) + (add-stat! received "bs_recv") + (add-stat! dropped "bs_drop") + (cond-expand (netbsd (add-stat! captured "bs_capt"))) + result)))) ) -- cgit v1.2.3