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

Function determineNetworkType

networktype.go:122–142  ·  view source on GitHub ↗

determineNetworkType determines the type of network based on the short network string and an IP address.

(network string, ip netip.Addr)

Source from the content-addressed store, hash-verified

120// determineNetworkType determines the type of network based on
121// the short network string and an IP address.
122func determineNetworkType(network string, ip netip.Addr) (NetworkType, error) {
123 // we'd rather have an IPv4-mapped IPv6 become IPv4 so that it is usable.
124 ip = ip.Unmap()
125 switch {
126 case strings.HasPrefix(strings.ToLower(network), udp):
127 if ip.Is4() {
128 return NetworkTypeUDP4, nil
129 }
130
131 return NetworkTypeUDP6, nil
132
133 case strings.HasPrefix(strings.ToLower(network), tcp):
134 if ip.Is4() {
135 return NetworkTypeTCP4, nil
136 }
137
138 return NetworkTypeTCP6, nil
139 }
140
141 return NetworkType(0), fmt.Errorf("%w from %s %s", ErrDetermineNetworkType, network, ip)
142}

Callers 6

NewCandidateRelayFunction · 0.85
setIPAddrMethod · 0.85

Calls 2

NetworkTypeTypeAlias · 0.85
ErrorfMethod · 0.45

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…