nat

package module
v0.0.0-...-445e7fe Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: Apache-2.0 Imports: 13 Imported by: 4

README

go-nat

GoDoc status

Documentation

Overview

Package nat implements NAT handling facilities

Index

Constants

This section is empty.

Variables

View Source
var ErrNoExternalAddress = errors.New("no external address")
View Source
var ErrNoInternalAddress = errors.New("no internal address")
View Source
var ErrNoNATFound = errors.New("no NAT found")

Functions

func IsGlobalIP

func IsGlobalIP(trial net.IP) string

IsGlobalIP determs passed ip address is global or not. if ip address is global , it returns address type(ip4 or ip6).

Types

type MappedPort

type MappedPort struct {
	Protocol     string
	InternalPort int
	ExternalPort *int32
	// contains filtered or unexported fields
}

MappedPort holds mapped port information by NAT.

type NAT

type NAT interface {
	// Type returns the kind of NAT port mapping service that is used
	Type() string

	// GetDeviceAddress returns the internal address of the gateway device.
	GetDeviceAddress() (addr net.IP, err error)

	// GetExternalAddress returns the external address of the gateway device.
	GetExternalAddress() (addr net.IP, err error)

	// GetInternalAddress returns the address of the local host.
	GetInternalAddress() (addr net.IP, err error)

	// AddPortMapping maps a port on the local host to an external port.
	AddPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (mappedExternalPort int, err error)

	// DeletePortMapping removes a port mapping.
	DeletePortMapping(protocol string, internalPort int) (err error)
}

protocol is either "udp" or "tcp"

func DiscoverGateway

func DiscoverGateway() (NAT, error)

DiscoverGateway attempts to find a gateway device.

type NetStatus

type NetStatus struct {
	Nat        NAT
	GlobalIP   net.IP
	MappedPort []*MappedPort
}

NetStatus holds NAT info, globlal IP address of this machine, and mapped port info by NAT.

func NewNetStatus

func NewNetStatus() (*NetStatus, error)

NewNetStatus make a new NetStatus struct, and gest global IP address from interface and NAT by UPnP and PMP.

func (*NetStatus) LoopPortMapping

func (ns *NetStatus) LoopPortMapping(protocol string, internalPort int, description string, timeout time.Duration) (*MappedPort, error)

LoopPortMapping mapped port by NAT annd go looping to map continually.

func (*NetStatus) StopPortMapping

func (ns *NetStatus) StopPortMapping(m *MappedPort) error

StopPortMapping stops port mapping loop.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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