Skip to content

Golang package to decode and encode SAP announcements according to RFC 2974

License

Notifications You must be signed in to change notification settings

holoplot/go-sap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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{
		IDHash:      0x2342,
		Origin:      net.ParseIP("192.168.1.100"),
		PayloadType: sap.SDPPayloadType,
		Payload:     sdp,
	}

	ctx, cancel := context.WithCancel(context.Background())

	go func() {
		// This blocks
		err := sap.AnnouncePeriodically(ctx, net.ParseIP("239.255.255.255"), p)
		if err != nil && !errors.Is(err, context.Canceled) {
			panic(err)
		}
	}()

	time.Sleep(2 * time.Second())

	// Send the deletion package and stop announcing.
	cancel()
}

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

About

Golang package to decode and encode SAP announcements according to RFC 2974

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages