portmapper

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package portmapper is a minimal NAT-PMP (RFC 6886) client for requesting a UDP port mapping from a home gateway.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapping

type Mapping struct {
	ExternalAddr netip.AddrPort
	Lifetime     time.Duration
}

Mapping is a UDP port mapping returned by a gateway.

type NATPMPClient

type NATPMPClient struct {
	Gateway netip.Addr
	Port    uint16
	Timeout time.Duration
}

NATPMPClient is a minimal NAT-PMP client.

func (NATPMPClient) ExternalIPv4

func (c NATPMPClient) ExternalIPv4(ctx context.Context) (netip.Addr, error)

ExternalIPv4 returns the public IPv4 address reported by the gateway.

func (NATPMPClient) MapUDP

func (c NATPMPClient) MapUDP(ctx context.Context, internalPort uint16, suggestedExternalPort uint16, lifetime time.Duration) (Mapping, error)

MapUDP maps internalPort through the NAT-PMP gateway, requesting the given lifetime. A lifetime of 0 deletes the mapping (RFC 6886 §3.4): the gateway removes any mapping for internalPort and returns a zero Mapping.

Jump to

Keyboard shortcuts

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