go-sap

module
v0.0.0-...-4265b25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: MIT

README

godoc license

go-sap

A Go package to decode and encode SAP packets as described in RFC 2974.

Example

Also see the demo applications in the cmd/ folder.

Encode and send

import "github.com/holoplot/go-sap/pkg/sap"

func main() {
	sdp := []byte{
		// your SDP here
	}

	p := &sap.Packet{
		Type:        sap.MessageTypeAnnouncement,
		IDHash:      0x2342,
		Origin:      net.ParseIP("192.168.1.100"),
		PayloadType: sap.SDPPayloadType,
		Payload:     sdp,
	}

	s, err := sap.NewSender(net.ParseIP("239.255.255.255"), p)
	if err != nil {
		panic(err)
	}

	s.AnnouncePeriodically(context.Background())
}

Receive and decode

import "github.com/holoplot/go-sap/pkg/sap"

func main() {
	l, err := sap.NewListener(net.ParseIP("239.255.255.255"), nil)
	if err != nil {
		panic(err)
	}

	for {
		b, err := l.ReadPacketRaw()
		if err != nil {
			panic(err)
		}

		p, err := sap.DecodePacket(b)
		if err != nil {
			panic(err)
		}

		// Use the content of the packet
	}
}

License

MIT

Directories

Path Synopsis
cmd
pkg
sap

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL