-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost-table.lisp
More file actions
37 lines (33 loc) · 1.2 KB
/
host-table.lisp
File metadata and controls
37 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(in-package :lispcap)
(defclass host ()
((mac :accessor host-mac
:initarg :mac)
(ip :accessor host-ip
:initarg :ip)
(last-activity :accessor host-last-activity
:initarg :last-activity)))
(defun update-host-activity (table mac &key (ip nil))
(setf (gethash mac table)
(make-instance 'host
:mac mac
:ip ip
:last-activity (get-universal-time))))
(defun print-host-table (table)
(apply #'concatenate
'string
(loop
for host being the hash-value of table
collect (format nil "~A ~A ~A~%"
(format-mac (host-mac host))
(format-ip (host-ip host))
(- (get-universal-time)
(host-last-activity host))))))
(defun get-inactive-hosts (table timeout)
(let ((inactive-hosts '())
(current-time (get-universal-time)))
(maphash (lambda (mac host)
(declare (ignore mac))
(if (>= (- current-time (host-last-activity host)) timeout)
(push host inactive-hosts)))
table)
inactive-hosts))