-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelpers.go
More file actions
52 lines (42 loc) · 733 Bytes
/
helpers.go
File metadata and controls
52 lines (42 loc) · 733 Bytes
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
package gomanuf
import (
"fmt"
"strconv"
"strings"
)
func macToUint64(mac string) (uint64, error) {
parts := strings.Split(mac, ":")
var hexStr strings.Builder
for _, p := range parts {
if p != "" {
hexStr.WriteString(p)
}
}
hex := hexStr.String()
switch len(hex) {
case 6:
hex += "000000"
case 12:
default:
return 0, fmt.Errorf("invalid MAC format: %s", mac)
}
val, err := strconv.ParseUint(hex, 16, 64)
if err != nil {
return 0, err
}
return val, nil
}
func maskMac(mac uint64, cidr uint8) uint64 {
var mask uint64
switch cidr {
case 24:
mask = 0xFFFFFF000000
case 28:
mask = 0xFFFFFFF00000
case 36:
mask = 0xFFFFFFFFF000
default:
mask = 0xFFFFFFFFFFFF
}
return mac & mask
}