znet

package
v0.0.0-...-9840c0c Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 7 Imported by: 6

Documentation

Overview

Package znet contains utilities for network communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrivateIP

func PrivateIP(addr net.IP) bool

PrivateIP reports if this is a private non-public IP address.

func PrivateIPString

func PrivateIPString(ip string) bool

PrivateIPString reports if this is a private non-public IP address.

This will return true for anything that is not an IP address, such as "example.com" or "localhost".

func RemovePort

func RemovePort(host string) string

RemovePort removes the "port" part of an hostname.

This only works for "host:port", and not URLs. See net.SplitHostPort.

func SafeDialer

func SafeDialer(allowedNets []string, allowedPorts []int) *net.Dialer

SafeDialer is only alllowed to connect to the listed networks and ports on non-private addresses.

Any attempt to connect to e.g. "127.0.0.1" will return an error. This is intended for clients that should only connect to external resources from user input.

If the allowed lists are empty then "tcp4", "tcp6", "80", and "443" are used.

The Timeout and KeepAlive are set to 30 seconds.

Also see zhttputil.SafeTransport() and zhttputil.SafeClient().

Types

This section is empty.

Jump to

Keyboard shortcuts

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