portmap

package module
v0.0.0-...-dd30022 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 10 Imported by: 2 modules, 1 package

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.

README

Map TCP and UDP ports using NAT-PMP or UPNP.  Unlike some other libraries,
guarantee that we don't override other clients' ports, and that the
mappings will expire even if the client crashes.

See portmap-example for an example.

Documentation

Overview

Package portmap implements port mapping using NAT-PMP or uPNP.

Index

Constants

View Source
const (
	NATPMP = 1
	UPNP   = 2
	All    = NATPMP | UPNP
)

Variables

This section is empty.

Functions

func Map

func Map(ctx context.Context, label string, internal uint16, kind int, f func(proto string, status Status, err error)) error

Map runs a portmapping loop for both TCP and UDP. The kind parameter indicates the portmapping protocols to attempt.

The label is passed to the UPNP server (it is not used with NAT-PMP) and may be displayed in the router's user interface.

The callback function is called whenever a mapping is established or changes, or when an error occurs; it may be nil.

Types

type Status

type Status struct {
	Internal, External uint16
	Lifetime           time.Duration
}

Status is passed to the callback of Map

type WANIPConnection

type WANIPConnection interface {
	GetSpecificPortMappingEntryCtx(
		context.Context, string, uint16, string,
	) (uint16, string, bool, string, uint32, error)
	AddPortMappingCtx(
		context.Context, string, uint16, string, uint16, string,
		bool, string, uint32,
	) error
	DeletePortMappingCtx(context.Context, string, uint16, string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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