netutils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4BitLen = net.IPv4len * 8
	IPv6BitLen = net.IPv6len * 8
)

Bit lengths of IP addresses.

Variables

This section is empty.

Functions

func CloneIPNet

func CloneIPNet(n *net.IPNet) (clone *net.IPNet)

func CloneIPs

func CloneIPs(ips []net.IP) (clone []net.IP)

func CloneURL

func CloneURL(u *url.URL) (clone *url.URL)

CloneURL returns a deep clone of u. The User pointer of clone is the same, since a *url.Userinfo is effectively an immutable value.

func ExtractIPAddress

func ExtractIPAddress(r *http.Request) (string, error)

func IPAndPortFromAddr

func IPAndPortFromAddr(addr net.Addr) (ip net.IP, port int)

func IPv4Zero

func IPv4Zero() (ip net.IP)

func IPv4allrouter

func IPv4allrouter() (ip net.IP)

func IPv4allsys

func IPv4allsys() (ip net.IP)

func IPv4bcast

func IPv4bcast() (ip net.IP)

func IPv6Zero

func IPv6Zero() (ip net.IP)

func IsValidHostInnerRune

func IsValidHostInnerRune(r rune) (ok bool)

IsValidHostInnerRune returns true if r is a valid inner—that is, neither initial nor final—rune for a hostname label.

func IsValidHostOuterRune

func IsValidHostOuterRune(r rune) (ok bool)

IsValidHostOuterRune returns true if r is a valid initial or final rune for a hostname label.

func JoinHostPort

func JoinHostPort(host string, port int) (hostport string)

JoinHostPort is a convenient wrapper for net.JoinHostPort with port of type int. As opposed to net.JoinHostPort it also trims the host from square brackets if any. This may be useful when passing url.URL.Host field containing an IPv6 address.

func ParseIP

func ParseIP(s string) (ip net.IP, err error)

func ParseIPv4

func ParseIPv4(s string) (ip net.IP, err error)

func ParseSubnet

func ParseSubnet(s string) (n *net.IPNet, err error)

func ParseSubnets

func ParseSubnets(ss ...string) (ns []*net.IPNet, err error)

func SingleIPSubnet

func SingleIPSubnet(ip net.IP) (n *net.IPNet)

func SplitHost

func SplitHost(hostport string) (host string, err error)

SplitHost is a wrapper for net.SplitHostPort for cases when the hostport may or may not contain a port.

func SplitHostPort

func SplitHostPort(hostport string) (host string, port int, err error)

SplitHostPort is a convenient wrapper for net.SplitHostPort with port of type int.

func ValidateIP

func ValidateIP(ip net.IP) (err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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