-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.go
48 lines (40 loc) · 839 Bytes
/
util.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
package main
import (
"fmt"
"net"
"sort"
)
func makeInterfaceMap() map[string]string {
interfaceTable := make(map[string]string)
interfaces, _ := net.Interfaces()
for _, intf := range interfaces {
key := fmt.Sprintf("%d-%s", intf.Flags, intf.HardwareAddr.String())
addrs, _ := intf.Addrs()
for _, addr := range addrs {
key = fmt.Sprintf("%s-%s", key, addr.String())
}
interfaceTable[intf.Name] = key
}
return interfaceTable
}
func interfaceMapKeys(ifs map[string]string) []string {
var ret []string
for k, _ := range ifs {
ret = append(ret, k)
}
sort.Strings(ret)
return ret
}
func interfaceListChanged(listA []string, listB []string) bool {
if len(listA) != len(listB) {
return true
}
equal := true
for i, v := range listA {
if listB[i] != v {
equal = false
break
}
}
return !equal
}