-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethernet.go
46 lines (38 loc) · 839 Bytes
/
ethernet.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
package packet
import (
"errors"
"net"
golayers "github.com/google/gopacket/layers"
)
type Ethernet struct {
layer *golayers.Ethernet
}
func EthernetLayer() *Ethernet {
return &Ethernet{
layer: &golayers.Ethernet{
EthernetType: golayers.EthernetTypeLLC,
},
}
}
func (e *Ethernet) SetSrcMAC(macStr string) error {
mac, err := net.ParseMAC(macStr)
if err != nil {
return errors.New("invalid source MAC address")
}
e.layer.SrcMAC = mac
return nil
}
func (e *Ethernet) SetDstMAC(macStr string) error {
mac, err := net.ParseMAC(macStr)
if err != nil {
return errors.New("invalid destination MAC address")
}
e.layer.DstMAC = mac
return nil
}
func (e *Ethernet) SetEthernetType(ethType golayers.EthernetType) {
e.layer.EthernetType = ethType
}
func (e *Ethernet) Layer() *golayers.Ethernet {
return e.layer
}