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 ¶
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 ¶
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 ¶
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.
Click to show internal directories.
Click to hide internal directories.