summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Bex <peter@more-magic.net>2013-05-11 14:58:29 +0200
committerPeter Bex <peter@more-magic.net>2016-03-04 21:38:49 +0100
commit24d11ef61875cf6fcb8c661d83f9e5fb7006cd78 (patch)
tree0b663061785355819027cae67be77b420058bacd
parenta0a351a09386b00de031938633b2d324ceee33f1 (diff)
downloadbpf-24d11ef61875cf6fcb8c661d83f9e5fb7006cd78.tar.gz
Add stats procedure
-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))))
)