-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl2.go
More file actions
44 lines (38 loc) · 1007 Bytes
/
l2.go
File metadata and controls
44 lines (38 loc) · 1007 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
// Package l2 is a set of utility functions for manipulating network devices
// at the layer two networking level.
package l2
import (
"io"
)
// Something which you can read ethernet frames from. This is distinct from
// io.Reader because you cannot slice l2 ethernet frames arbitrarily.
type FrameReader interface {
ReadFrame() (EthFrame, error)
}
// Something which you can write ethernet frames to. This is distinct from
// io.Reader because you cannot slice l2 ethernet frames arbitrarily.
type FrameWriter interface {
WriteFrame(EthFrame) error
}
type FrameReadWriter interface {
FrameReader
FrameWriter
}
type FrameReadWriteCloser interface {
FrameReader
FrameWriter
io.Closer
}
// Local equivalent of io.Copy, will shove frames from a FrameReader
// into a FrameWriter
func SendFrames(source FrameReader, destination FrameWriter) error {
for {
p, err := source.ReadFrame()
if err != nil {
return err
}
if err = destination.WriteFrame(p); err != nil {
return err
}
}
}