determineNetworkType determines the type of network based on the short network string and an IP address.
(network string, ip netip.Addr)
| 120 | // determineNetworkType determines the type of network based on |
| 121 | // the short network string and an IP address. |
| 122 | func 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 | } |
searching dependent graphs…