|
|
|
@ -7,7 +7,6 @@ import (
|
|
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
|
_ "github.com/google/gopacket/layers"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"proxy/cmd"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -25,7 +24,7 @@ func main() {
|
|
|
|
|
|
|
|
|
|
// Reads from an input and writes to and output,
|
|
|
|
|
// do things to the content in between.
|
|
|
|
|
// For now only output the frames information
|
|
|
|
|
// For now only output the packet's information
|
|
|
|
|
// Is meant to be run concurrently with "go pipeForward(...)"
|
|
|
|
|
func pipeForward(reader io.Reader, writer io.Writer, prefix string) {
|
|
|
|
|
for {
|
|
|
|
@ -36,7 +35,7 @@ func pipeForward(reader io.Reader, writer io.Writer, prefix string) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
frameLengthInt := int(binary.BigEndian.Uint16(frameLength))
|
|
|
|
|
os.Stdout.WriteString(fmt.Sprintf("%s Frame length: %d\n", prefix, frameLengthInt))
|
|
|
|
|
fmt.Printf("%s Frame length: %d\n", prefix, frameLengthInt)
|
|
|
|
|
|
|
|
|
|
// Read actual frame
|
|
|
|
|
frameBytes := make([]byte, frameLengthInt)
|
|
|
|
@ -45,15 +44,23 @@ func pipeForward(reader io.Reader, writer io.Writer, prefix string) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert frame to full stack packet
|
|
|
|
|
packet := gopacket.NewPacket(frameBytes, layers.LayerTypeEthernet, gopacket.Default)
|
|
|
|
|
frame := packet.Layer(layers.LayerTypeEthernet).(*layers.Ethernet)
|
|
|
|
|
|
|
|
|
|
// Handle Ethernet frame
|
|
|
|
|
frame := packet.Layer(layers.LayerTypeEthernet).(*layers.Ethernet)
|
|
|
|
|
fmt.Printf("src: %s\ndst: %s\ntyp: %s\n", frame.SrcMAC, frame.DstMAC, frame.EthernetType)
|
|
|
|
|
|
|
|
|
|
switch frame.EthernetType {
|
|
|
|
|
case layers.EthernetTypeARP:
|
|
|
|
|
// Handle ARP packet
|
|
|
|
|
if frame.EthernetType == layers.EthernetTypeARP {
|
|
|
|
|
arpPacket := packet.Layer(layers.LayerTypeARP).(*layers.ARP)
|
|
|
|
|
fmt.Printf("%#v", arpPacket)
|
|
|
|
|
fmt.Printf("%sARP Packet:\n%#v\n", prefix, arpPacket)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle DHCP packet
|
|
|
|
|
if dhcpLayer := packet.Layer(layers.LayerTypeDHCPv4); dhcpLayer != nil {
|
|
|
|
|
dhcpPacket, _ := dhcpLayer.(*layers.DHCPv4)
|
|
|
|
|
fmt.Printf("%sDHCP Packet:\n%#v\n", prefix, dhcpPacket)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Forward original frame to other plug
|
|
|
|
|