Documentation
¶
Overview ¶
Package netutil contains network-related utilities common among dnsproxy packages.
TODO(a.garipov): Move improved versions of these into netutil in module golibs.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortIPAddrs ¶
SortIPAddrs sorts addrs in accordance with the protocol preferences. Invalid addresses are sorted near the end. Zones are ignored.
TODO(a.garipov): Use netip.Addr instead of net.IPAddr everywhere where this is called.
Example ¶
package main
import (
"fmt"
"net"
"github.com/AdguardTeam/dnsproxy/internal/netutil"
)
func main() {
printAddrs := func(header string, addrs []net.IPAddr) {
fmt.Printf("%s:\n", header)
for i, a := range addrs {
fmt.Printf("%d: %s\n", i+1, a.IP)
}
fmt.Println()
}
addrs := []net.IPAddr{{
IP: net.ParseIP("1.2.3.4"),
}, {
IP: net.ParseIP("1.2.3.5"),
}, {
IP: net.ParseIP("2a00::1234"),
}, {
IP: net.ParseIP("2a00::1235"),
}, {
IP: nil,
}}
netutil.SortIPAddrs(addrs, false)
printAddrs("IPv4 preferred", addrs)
netutil.SortIPAddrs(addrs, true)
printAddrs("IPv6 preferred", addrs)
}
Output: IPv4 preferred: 1: 1.2.3.4 2: 1.2.3.5 3: 2a00::1234 4: 2a00::1235 5: <nil> IPv6 preferred: 1: 2a00::1234 2: 2a00::1235 3: 1.2.3.4 4: 1.2.3.5 5: <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.