stun

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: BSD-3-Clause Imports: 5 Imported by: 26

Documentation

Overview

Package STUN generates STUN request packets and parses response packets.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSTUN            = errors.New("response is not a STUN packet")
	ErrNotSuccessResponse = errors.New("STUN packet is not a response")
	ErrMalformedAttrs     = errors.New("STUN response has malformed attributes")
	ErrNotBindingRequest  = errors.New("STUN request not a binding request")
	ErrWrongSoftware      = errors.New("STUN request came from non-Tailscale software")
	ErrNoFingerprint      = errors.New("STUN request didn't end in fingerprint")
	ErrWrongFingerprint   = errors.New("STUN request had bogus fingerprint")
)

Functions

func Is

func Is(b []byte) bool

Is reports whether b is a STUN message.

func Request

func Request(tID TxID) []byte

Request generates a binding request STUN packet. The transaction ID, tID, should be a random sequence of bytes.

Example
package main

import (
	"fmt"

	"tailscale.com/net/stun"
)

func main() {
	txID := stun.NewTxID()
	req := stun.Request(txID)
	fmt.Printf("%x\n", req)
}
Output:

func Response

func Response(txID TxID, ip net.IP, port uint16) []byte

Response generates a binding response.

Types

type TxID

type TxID [12]byte

TxID is a transaction ID.

func NewTxID

func NewTxID() TxID

NewTxID returns a new random TxID.

func ParseBindingRequest

func ParseBindingRequest(b []byte) (TxID, error)

ParseBindingRequest parses a STUN binding request.

It returns an error unless it advertises that it came from Tailscale.

func ParseResponse

func ParseResponse(b []byte) (tID TxID, addr []byte, port uint16, err error)

ParseResponse parses a successful binding response STUN packet. The IP address is extracted from the XOR-MAPPED-ADDRESS attribute. The returned addr slice is owned by the caller and does not alias b.

Directories

Path Synopsis
Package stuntest provides a STUN test server.
Package stuntest provides a STUN test server.

Jump to

Keyboard shortcuts

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