MCPcopy Create free account
hub / github.com/pion/ice / parseAddr

Function parseAddr

addr.go:38–74  ·  view source on GitHub ↗
(in net.Addr)

Source from the content-addressed store, hash-verified

36}
37
38func parseAddr(in net.Addr) (netip.Addr, int, NetworkType, error) {
39 host := func(ip net.IP, zone string) (netip.Addr, int, NetworkType, error) {
40 a, err := ipAddrToNetIP(ip, zone)
41 if err != nil {
42 return netip.Addr{}, 0, 0, err
43 }
44
45 return a, 0, 0, nil
46 }
47
48 sock := func(ip net.IP, zone string, port int, v4, v6 NetworkType) (netip.Addr, int, NetworkType, error) {
49 a, err := ipAddrToNetIP(ip, zone)
50 if err != nil {
51 return netip.Addr{}, 0, 0, err
52 }
53
54 nt := v6
55 if a.Is4() {
56 nt = v4
57 }
58
59 return a, port, nt, nil
60 }
61
62 switch a := in.(type) {
63 case *net.IPNet:
64 return host(a.IP, "")
65 case *net.IPAddr:
66 return host(a.IP, a.Zone)
67 case *net.UDPAddr:
68 return sock(a.IP, a.Zone, a.Port, NetworkTypeUDP4, NetworkTypeUDP6)
69 case *net.TCPAddr:
70 return sock(a.IP, a.Zone, a.Port, NetworkTypeTCP4, NetworkTypeTCP6)
71 default:
72 return netip.Addr{}, 0, 0, addrParseError{in}
73 }
74}
75
76type addrParseError struct {
77 addr net.Addr

Callers 9

parseAddrFromIfaceFunction · 0.85
addrEqualFunction · 0.85
findRemoteCandidateMethod · 0.85
sendBindingSuccessMethod · 0.85
handleInboundRequestMethod · 0.85

Calls 1

ipAddrToNetIPFunction · 0.85

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…