github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/network/name.go (about) 1 package network 2 3 import ( 4 "strings" 5 6 E "github.com/sagernet/sing/common/exceptions" 7 ) 8 9 var ErrUnknownNetwork = E.New("unknown network") 10 11 //goland:noinspection GoNameStartsWithPackageName 12 const ( 13 NetworkIP = "ip" 14 NetworkTCP = "tcp" 15 NetworkUDP = "udp" 16 NetworkICMPv4 = "icmpv4" 17 NetworkICMPv6 = "icmpv6" 18 ) 19 20 //goland:noinspection GoNameStartsWithPackageName 21 func NetworkName(network string) string { 22 if strings.HasPrefix(network, "tcp") { 23 return NetworkTCP 24 } else if strings.HasPrefix(network, "udp") { 25 return NetworkUDP 26 } else if strings.HasPrefix(network, "ip") { 27 return NetworkIP 28 } else { 29 return network 30 } 31 }