Skip to content
/ ethernet Public

Implementation of Ethernet 802.3, VLAN, 802.1P, 802.11 (Wireless Ethernet) frame serialization/deserialization library written in Go

License

Notifications You must be signed in to change notification settings

0x9ef/ethernet

Repository files navigation

Ethernet Frame Serializarion/Deserazization library written in Go

The library implements frame serialization/deserialization in pure Go. The list of the supported Ethernet standards:

Usage Examples

See the *_test.go files.

How to Encode?

	dstAddr := ethernet.NewHardwareAddr(0x8C, 0x8E, 0xC4, 0xFF, 0x9E, 0xA2)
	srcAddr := ethernet.NewHardwareAddr(0x8C, 0x8E, 0xC4, 0xAA, 0x4E, 0xF1)
	f := ethernet.NewFrame(srcAddr, dst, []byte("Hello :)"))
	f.SetTag8021q(&ethernet.Tag8021q{Tpid: 0x8100, Tci: ethernet.Encode8021qTci(3, 0, 1024)})
	b := f.Marshal()

How to Decode?

	b := f.Marshal()

	var f Frame
	err := ethernet.Unmarshal(b, &f)
	if err != nil {
		panic(err)
	}

	pcp, dei, vlan := ethernet.Decode8021qTci(f.Tag8021q().Tci)
	fmt.Println("PCP:", pcp)
	fmt.Println("DEI:", dei)
	fmt.Println("VLAN ID:", vlan)
	fmt.Println("EtherType:", f.EtherType())
	fmt.Println("Checksum (FCS):", f.FCS())

License

MIT

About

Implementation of Ethernet 802.3, VLAN, 802.1P, 802.11 (Wireless Ethernet) frame serialization/deserialization library written in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages