-
Notifications
You must be signed in to change notification settings - Fork 0
/
arp.go
60 lines (49 loc) · 856 Bytes
/
arp.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package arp
import (
"time"
)
type ArpEntry struct {
MacAddress string
IPAddress string
Iface string
Permanent bool
}
type ArpTable map[string]ArpEntry
var (
stop = make(chan struct{})
arpCache = &cache{
table: make(ArpTable),
}
)
func AutoRefresh(t time.Duration) {
go func() {
for {
select {
case <-time.After(t):
arpCache.Refresh()
case <-stop:
return
}
}
}()
}
func StopAutoRefresh() {
stop <- struct{}{}
}
func CacheUpdate() {
arpCache.Refresh()
}
func CacheLastUpdate() time.Time {
return arpCache.Updated
}
func CacheUpdateCount() int {
return arpCache.UpdatedCount
}
// Search looks up the MAC address for an IP address
// in the arp table
func Search(ip string) ArpEntry {
return arpCache.Search(ip)
}
func ReverseSearch(mac string) []ArpEntry {
return arpCache.ReverseSearch(mac)
}