Documentation ¶
Overview ¶
Package netutil provides net-related utility functions/types.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustParseCIDR ¶
Types ¶
type ErrBlocked ¶
type ErrBlocked struct { Host string Network NamedNetwork }
ErrBlocked is an error returned by NetworkBlocklist.Control (thus net.Dialer.DialContext) when outgoing host is blocked by NetworkBlocklist.
func (ErrBlocked) Error ¶
func (e ErrBlocked) Error() string
type NamedNetwork ¶
type NetworkBlocklist ¶
type NetworkBlocklist struct { V4 []NamedNetwork V6 []NamedNetwork }
NetworkBlocklist is a blocklist that blocks dialing to specified networks.
var PrivateNetworkBlocklist NetworkBlocklist
PrivateNetworkBlocklist is a blocklist that blocks dialing to private networks.
func (NetworkBlocklist) Control ¶
func (l NetworkBlocklist) Control(network, address string, c syscall.RawConn) error
Control is intended to be passed to net.Dialer.Control in order to block dialing to networks specified in l.
Example ¶
transport := http.DefaultTransport.(*http.Transport).Clone() transport.DialContext = (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, Control: PrivateNetworkBlocklist.Control, }).DialContext client := &http.Client{ Transport: transport, } _, err := client.Get("http://[::1]/") fmt.Println(err)
Output: Get "http://[::1]/": dial tcp [::1]:80: host is blocked (Loopback Address)
Click to show internal directories.
Click to hide internal directories.