network

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	System     portType = iota // system or well-known ports
	Registered                 // registered ports
	Dynamic                    // dynamic, private or ephemeral ports
)
View Source
const (
	MaxSystem port = iota + 1023
	MinRegistered
)
View Source
const (
	MaxRegistered port = iota + 49151
	MinDynamic
)
View Source
const (
	MaxDynamic port = iota + 65535
	Invalid
)
View Source
const (
	MinSystem port = iota
)

Variables

View Source
var All = rangeOf(System, Dynamic)
View Source
var NonDynamic = rangeOf(System, Registered)
View Source
var NonSystem = rangeOf(Registered, Dynamic)

Functions

This section is empty.

Types

type Port

type Port interface {
	IsSet() bool
	IsValid() bool
	IsValidForType(portType) bool
	IsValidForTypeRange(*portTypeRange) bool
	Uint64() uint64
	Addr(string) string
}

Port is an interface to ensure consistency - use NewPort(), NewPortForType() or NewPortForTypeRange() functions to obtain a valid Port

func NewPort

func NewPort[PI PortInput](pi PI) (Port, error)

NewPort returns a Port if the argument has a valid TCP/UDP port number (no limitation of port type or type range), error otherwise

func NewPortForType

func NewPortForType[PI PortInput](pi PI, pt portType) (Port, error)

NewPortForType returns a Port if the argument has a valid TCP/UDP port number for the requested port type, error otherwise

func NewPortForTypeRange

func NewPortForTypeRange[PI PortInput](pi PI, ptr *portTypeRange) (p Port, err error)

NewPortForTypeRange returns a Port if the argument has a valid TCP/UDP port number for the requested port type range, error otherwise

func ParseAddress

func ParseAddress(s string) (string, Port, error)

ParseAddress parses the input string to validate the following:

  1. It has a mandatory IP address component in IPv4 dotted decimal, IPv6 or IPv4-mapped IPv6 form (see also net.ParseIP())
  2. It has an optional valid TCP/UDP port number (no limitation of port type or type range), separated from the address component by ':'
  3. If the port exists and the address is in IPv6 or IPv4-mapped IPv6 form, the address component MUST be enclosed by square brackets ('[' and ']'), e.g. "[2001:0db8:85a3::8a2e:0370:7334]:80"; in all other cases, the address component MAY be enclosed by square brackets

If all validations pass, the function returns the address component as a string and the Port; otherwise, an error is returned

func ParseAddressForPortType

func ParseAddressForPortType(s string, pt portType) (string, Port, error)

ParseAddressForPortType behaves like ParseAddress, only that the port validation (#2) is limited to the specified port type

func ParseAddressForPortTypeRange

func ParseAddressForPortTypeRange(s string, ptr *portTypeRange) (address string, p Port, err error)

ParseAddressForPortTypeRange behaves like ParseAddress, only that the port validation (#2) is limited to the specified port type range

type PortInput

type PortInput interface {
	~uint64 | ~string
}

Jump to

Keyboard shortcuts

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