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

Display ARP nad DHCP packets

main
Simon Moser vor 3 Jahren
Ursprung 9df909edd1
Commit b93f6b3e8f
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

@ -66,8 +66,8 @@ Keep in mind:
### Go:
* Internet layer packet modification: https://github.com/google/gopacket / https://pkg.go.dev/github.com/google/gopacket
* Link layer frame modification: https://github.com/mdlayher/ethernet / https://pkg.go.dev/github.com/mdlayher/ethernet (not recently updated, alternative?)
* gopacket (~libpcap): https://github.com/google/gopacket / https://pkg.go.dev/github.com/google/gopacket
* (Link layer frame modification: https://github.com/mdlayher/ethernet / https://pkg.go.dev/github.com/mdlayher/ethernet)
### Rust:

@ -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