Created
March 27, 2015 23:37
-
-
Save BobuSumisu/91a3197939c7d8296eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import foreign) | |
(foreign-declare "#include <pcap.h>") | |
(define-foreign-variable PCAP_ERRBUF_SIZE int) | |
(define-foreign-variable BUFSIZ int) | |
(define errbuf (make-string PCAP_ERRBUF_SIZE)) | |
;; char *pcap_lookupdev(char *errbuf); | |
(define %pcap-lookupdev | |
(foreign-lambda c-string "pcap_lookupdev" c-string)) | |
(define (pcap-lookupdev) | |
(%pcap-lookupdev errbuf)) | |
;; pcap_t *pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, char *errbuf); | |
(define %pcap-open-live | |
(foreign-lambda (c-pointer (struct "pcap")) "pcap_open_live" c-string int bool int c-string)) | |
(define (pcap-open-live dev) | |
(%pcap-open-live dev BUFSIZ #f 0 errbuf)) | |
(let* ((dev (pcap-lookupdev)) | |
(pcap (pcap-open-live dev))) | |
(print errbuf)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment