mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 20:07:38 +03:00
31 lines
636 B
Go
31 lines
636 B
Go
package network
|
|
|
|
import (
|
|
"strings"
|
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
)
|
|
|
|
var ErrUnknownNetwork = E.New("unknown network")
|
|
|
|
//goland:noinspection GoNameStartsWithPackageName
|
|
const (
|
|
NetworkIP = "ip"
|
|
NetworkTCP = "tcp"
|
|
NetworkUDP = "udp"
|
|
NetworkICMPv4 = "icmpv4"
|
|
NetworkICMPv6 = "icmpv6"
|
|
)
|
|
|
|
//goland:noinspection GoNameStartsWithPackageName
|
|
func NetworkName(network string) string {
|
|
if strings.HasPrefix(network, "tcp") {
|
|
return NetworkTCP
|
|
} else if strings.HasPrefix(network, "udp") {
|
|
return NetworkUDP
|
|
} else if strings.HasPrefix(network, "ip") {
|
|
return NetworkIP
|
|
} else {
|
|
return network
|
|
}
|
|
}
|