You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RawNet is a Go library for low-level network packet manipulation. It provides tools for parsing, inspecting, and creating raw network packets at layers 2, 3, and 4 of the OSI model.
Features
Parse and create Ethernet frames (Layer 2)
Support for IPv4 and IPv6 packets (Layer 3)
Support for TCP, UDP, ICMP, and IGMP protocols (Layer 4)
Virtual network circuit simulation
Checksum calculation and validation
VLAN tagging support
Easy packet field manipulation
Installation
go get github.com/KarpelesLab/rawnet
Usage
Creating a Virtual Network Circuit
// Create a new virtual network circuitcircuit:=rawnet.NewCircuit()
// Bridge a device to the circuitcircuit.BridgeDevice(myNetworkDevice)
// Enable debug loggingcircuit.SetDebug(true)
Working with L2 Packets
// Handle an L2 packetfunc (d*MyDevice) HandleL2Packet(src rawnet.L2Device, pkt rawnet.L2Packet) error {
// Get source and destination MAC addressessrcMac:=pkt.GetSourceMac()
dstMac:=pkt.GetDestinationMac()
// Get ethertype and VLAN infoethertype, vlan, l3p:=pkt.GetL3Packet()
// Process based on packet type// ...
}
Working with L3 Packets
// Access IP addressessrcIP:=l3p.GetSourceIP()
dstIP:=l3p.GetDestinationIP()
// Create a new L3 packet with modified sourcenewPacket:=l3p.WithNewSource(myIP, myPort)
// Create a new L3 packet with modified destinationnewPacket:=l3p.WithNewDst(targetIP, targetPort)
Build and Test
make all # Build the library
make deps # Install dependencies
make test # Run tests