mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
initial commit
This commit is contained in:
parent
a9977e0a62
commit
4a028c3fe3
7 changed files with 377 additions and 0 deletions
40
waterutil/tap.go
Normal file
40
waterutil/tap.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package waterutil
|
||||
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
type Tagging int
|
||||
|
||||
// Indicating whether/how a MAC frame is tagged. The value is number of bytes taken by tagging.
|
||||
const (
|
||||
NotTagged Tagging = 0
|
||||
Tagged Tagging = 4
|
||||
DoubleTagged Tagging = 8
|
||||
)
|
||||
|
||||
func MACDestination(macFrame []byte) net.HardwareAddr {
|
||||
return net.HardwareAddr(macFrame[:6])
|
||||
}
|
||||
|
||||
func MACSource(macFrame []byte) net.HardwareAddr {
|
||||
return net.HardwareAddr(macFrame[6:12])
|
||||
}
|
||||
|
||||
func MACTagging(macFrame []byte) Tagging {
|
||||
if macFrame[12] == 0x81 && macFrame[13] == 0x00 {
|
||||
return Tagged
|
||||
} else if macFrame[12] == 0x88 && macFrame[13] == 0xa8 {
|
||||
return DoubleTagged
|
||||
}
|
||||
return NotTagged
|
||||
}
|
||||
|
||||
func MACEthertype(macFrame []byte) Ethertype {
|
||||
ethertypePos := 12 + MACTagging(macFrame)
|
||||
return Ethertype{macFrame[ethertypePos], macFrame[ethertypePos+1]}
|
||||
}
|
||||
|
||||
func MACPayload(macFrame []byte) []byte {
|
||||
return macFrame[12+MACTagging(macFrame)+2:]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue