nat

package
v0.0.0-...-9b6e4cd Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMultipleNAT is an error returned when multiple NATs have been
	// detected.
	ErrMultipleNAT = errors.New("multiple NATs detected")
)

Functions

This section is empty.

Types

type PMP

type PMP struct {
	// contains filtered or unexported fields
}

PMP is a concrete implementation of the Traversal interface that uses the NAT-PMP technique.

func DiscoverPMP

func DiscoverPMP(timeout time.Duration) (*PMP, error)

DiscoverPMP attempts to scan the local network for a NAT-PMP enabled device within the given timeout.

func (*PMP) AddPortMapping

func (p *PMP) AddPortMapping(port uint16) error

AddPortMapping enables port forwarding for the given port.

func (*PMP) DeletePortMapping

func (p *PMP) DeletePortMapping(port uint16) error

DeletePortMapping disables port forwarding for the given port.

func (*PMP) ExternalIP

func (p *PMP) ExternalIP() (net.IP, error)

ExternalIP returns the external IP address of the NAT-PMP enabled device.

func (*PMP) ForwardedPorts

func (p *PMP) ForwardedPorts() []uint16

ForwardedPorts returns a list of ports currently being forwarded.

func (*PMP) Name

func (p *PMP) Name() string

Name returns the name of the specific NAT traversal technique used.

type Traversal

type Traversal interface {
	// ExternalIP returns the external IP address.
	ExternalIP() (net.IP, error)

	// AddPortMapping adds a port mapping for the given port between the
	// private and public addresses.
	AddPortMapping(port uint16) error

	// DeletePortMapping deletes a port mapping for the given port between
	// the private and public addresses.
	DeletePortMapping(port uint16) error

	// ForwardedPorts returns the ports currently being forwarded using NAT
	// traversal.
	ForwardedPorts() []uint16

	// Name returns the name of the specific NAT traversal technique used.
	Name() string
}

Traversal is an interface that brings together the different NAT traversal techniques.

type UPnP

type UPnP struct {
	// contains filtered or unexported fields
}

UPnP is a concrete implementation of the Traversal interface that uses the UPnP technique.

func DiscoverUPnP

func DiscoverUPnP(ctx context.Context) (*UPnP, error)

DiscoverUPnP scans the local network for a UPnP enabled device.

func (*UPnP) AddPortMapping

func (u *UPnP) AddPortMapping(port uint16) error

AddPortMapping enables port forwarding for the given port.

func (*UPnP) DeletePortMapping

func (u *UPnP) DeletePortMapping(port uint16) error

DeletePortMapping disables port forwarding for the given port.

func (*UPnP) ExternalIP

func (u *UPnP) ExternalIP() (net.IP, error)

ExternalIP returns the external IP address of the UPnP enabled device.

func (*UPnP) ForwardedPorts

func (u *UPnP) ForwardedPorts() []uint16

ForwardedPorts returns a list of ports currently being forwarded.

func (*UPnP) Name

func (u *UPnP) Name() string

Name returns the name of the specific NAT traversal technique used.

Jump to

Keyboard shortcuts

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