stun

package
v1.104.4 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: BSD-3-Clause Imports: 7 Imported by: 14 modules, 26 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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)
}

func Response

func Response(txID TxID, addrPort netip.AddrPort) []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 netip.AddrPort, err error)

ParseResponse parses a successful binding response STUN packet. The IP address is extracted from the XOR-MAPPED-ADDRESS attribute.

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