// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MIT
// Package ipnet contains helper functions around net and IP
package ipnetimport ()var errFailedToCastAddr = errors.New("failed to cast net.Addr to *net.UDPAddr or *net.TCPAddr")// AddrIPPort extracts the IP and Port from a net.Addr.func ( net.Addr) (net.IP, int, error) { , := .(*net.UDPAddr)if {return .IP, .Port, nil } , := .(*net.TCPAddr)if {return .IP, .Port, nil }returnnil, 0, errFailedToCastAddr}// AddrEqual asserts that two net.Addrs are equal// Currently only supports UDP but will be extended in the future to support others.func (, net.Addr) bool { , := .(*net.UDPAddr)if ! {returnfalse } , := .(*net.UDPAddr)if ! {returnfalse }return .IP.Equal(.IP) && .Port == .Port}// FingerprintAddr generates a fingerprint from net.UDPAddr or net.TCPAddr's// which can be used for indexing maps.func ( net.Addr) string {switch a := .(type) {case *net.UDPAddr:return .IP.String()case *net.TCPAddr: // Do we really need this case?return .IP.String() }return""// Should never happen}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.