summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpf-interface.scm20
1 files changed, 19 insertions, 1 deletions
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))))
)