X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=listener.lsp;h=ceefed46da0b86bfec0e5549aebce86f6b9f9e40;hb=45a86f2b3e502e41dda26426e6e1e60ba088006f;hp=bd823f2fc7c2faf31a9a88a9ff9085fff534c770;hpb=05a9c528d8aee0373f52fa1bc72250e7f3625e76;p=rrq%2Fhourglass.git diff --git a/listener.lsp b/listener.lsp index bd823f2..ceefed4 100644 --- a/listener.lsp +++ b/listener.lsp @@ -11,9 +11,7 @@ (signal 2 (fn (x) (exit 0))) # The following is for Devuan GNU+Linux -(constant 'LIBC (exists file? '("/lib/x86_64-linux-gnu/libc.so.6" - "/lib/i386-linux-gnu/libc.so.6" - ))) +(constant 'LIBC SITE:libc) (import LIBC "ioctl" "int" "int" "long" "void*" ) (import LIBC "perror" "void" "char*" ) (import LIBC "ntohl" "int" "int" ) @@ -31,18 +29,23 @@ (if (null? a) v (nil? v) true (null? (1 a)) v (a 1)))) # Set logging mode. -(constant 'listener-log-ip (mainarg "-l" nil)) - # Open the tap named by "-t tapX" on the command line, or "tap0" byt # default. Then make a TUNSETIFF call to initialize it (as # IFF_TAP|IFF_NO_PI). -(constant 'IFNAME (mainarg "-t" "tap0") 'IFD (open "/dev/net/tun" "u") ) +(constant + 'listener-log-ip SITE:listener.ip + 'IFNAME SITE:listener.tap + 'PORTS SITE:listener.ports + 'IFD (open SITE:listener.tundev "u") + 'ACTNAMEFMT "%d%02d%02d-network.dat" + 'ACTDIR SITE:listener.activity.dir + 'ACTFILEFMT (format "%s/%s" ACTDIR ACTNAMEFMT ) +) (unless (number? IFD) (die "open")) (unless (zero? (ioctl IFD 0x400454ca (pack "s16 u s22" IFNAME 0x1002 ""))) (die (string "set " IFNAME))) # The TCP ports of interest -(constant 'PORTS '(80 443)) # Set up for optional tracking of IP addresses (define counter:counter nil) @@ -67,12 +70,13 @@ # This funcion collates all given ips, and it extends the log line # with the list of ips used during the minute. (setf next-mark 0 packet-count 0) + (define (mark-active t) ; buffer (when listener-log-ip (track-data)) (inc packet-count) ;(write-line 2 (string (list t packet-count ports (counter)))) (when (>= t next-mark) - (let ((d (format "activity/%d%02d%02d-network.dat" (0 3 (date-list t)))) + (let ((d (format ACTFILEFMT (0 3 (date-list t)))) (c (map string (counter)))) (append-file d (string t " " packet-count " " (join c " ") "\n")) (setf next-mark (+ t 60) packet-count 0)