mosers
/
eaas-vde-proxy
Archiviert
1
0
Fork 0

Output frame information [Close #2]

main
Simon Moser vor 3 Jahren
Ursprung dd72949e15
Commit 048c5f2feb
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

@ -1,3 +1,5 @@
module proxy module proxy
go 1.13 go 1.13
require github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7 // indirect

@ -0,0 +1,12 @@
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7 h1:lez6TS6aAau+8wXUP3G9I3TGlmPFEq2CTxBaRqY6AGE=
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7/go.mod h1:U6ZQobyTjI/tJyq2HG+i/dfSoFUt8/aZCM+GKtmFk/Y=
github.com/mdlayher/raw v0.0.0-20190606142536-fef19f00fc18/go.mod h1:7EpbotpCmVZcu+KCX4g9WaRNuu11uyhiW7+Le1dKawg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190419010253-1f3472d942ba/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606122018-79a91cf218c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

@ -1,11 +1,13 @@
package main package main
import ( import (
"encoding/binary"
"fmt" "fmt"
"github.com/mdlayher/ethernet"
"io" "io"
"log"
"os" "os"
"proxy/cmd" "proxy/cmd"
"unicode"
) )
// Start the two plugs and run two concurrent forward methods // Start the two plugs and run two concurrent forward methods
@ -22,27 +24,43 @@ func main() {
// Reads from an input and writes to and output, // Reads from an input and writes to and output,
// do things to the content in between. // do things to the content in between.
// For now only output it in xxd format. // For now only output the frames information
// Is meant to be run concurrently with "go pipeForward(...)" // Is meant to be run concurrently with "go pipeForward(...)"
func pipeForward(reader io.Reader, writer io.Writer, prefix string) { func pipeForward(reader io.Reader, writer io.Writer, prefix string) {
i := 0
for { for {
bytes := make([]byte, 16) // Read frame length and print it
bytesReadable := make([]byte, 16) frameLength := make([]byte, 2)
_, err := reader.Read(bytes) _, err := reader.Read(frameLength)
if err == io.EOF { if err == io.EOF {
break break
} }
for i, ch := range bytes { frameLengthInt := int(binary.BigEndian.Uint16(frameLength))
if ch > unicode.MaxASCII || ch < '\u0020' { os.Stdout.WriteString(fmt.Sprintf("%s Frame length: %d\n", prefix, frameLengthInt))
bytesReadable[i] = '\u002E'
} else { // Read actual frame
bytesReadable[i] = ch frameBytes := make([]byte, frameLengthInt)
_, err = reader.Read(frameBytes)
if err == io.EOF {
break
} }
// Marshal frame from binary
var frame ethernet.Frame
if e := (&frame).UnmarshalBinary(frameBytes); e != nil {
log.Printf("failed to unmarshal frame: %#v\n", e)
} }
xxdString := fmt.Sprintf("%s%08x: %04x %04x %04x %04x %04x %04x %04x %04x %s\n", prefix, i, bytes[0:1], bytes[2:3], bytes[4:5], bytes[6:7], bytes[8:9], bytes[10:11], bytes[12:13], bytes[14:15], bytesReadable)
os.Stdout.WriteString(xxdString) // Print frame information
writer.Write(bytes) fmt.Printf(
i += 16 "src: %s\ndst: %s\ntyp: %s\npayload\n%x\n",
frame.Source,
frame.Destination,
frame.EtherType,
frame.Payload,
)
// Forward original frame to other plug
writer.Write(frameLength)
writer.Write(frameBytes)
} }
} }

Binäre Datei nicht angezeigt.