1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00
v2fly/common/net/network.go

52 lines
875 B
Go
Raw Normal View History

2015-10-30 15:56:46 +01:00
package net
import (
"strings"
)
2017-08-22 15:15:09 +02:00
func (n Network) SystemString() string {
switch n {
2017-01-03 14:53:59 +01:00
case Network_TCP:
2016-09-20 10:44:44 +02:00
return "tcp"
case Network_UDP:
2016-09-20 10:44:44 +02:00
return "udp"
2020-10-29 15:30:38 +08:00
case Network_UNIX:
return "unix"
2016-09-20 10:44:44 +02:00
default:
return "unknown"
}
2016-06-04 00:38:22 +02:00
}
2018-11-20 17:05:32 +01:00
// HasNetwork returns true if the network list has a certain network.
2018-04-03 17:51:01 +02:00
func HasNetwork(list []Network, network Network) bool {
for _, value := range list {
2018-11-20 16:58:26 +01:00
if value == network {
2018-04-03 17:51:01 +02:00
return true
}
}
return false
}
func ParseNetwork(net string) Network {
switch strings.ToLower(net) {
case "tcp":
return Network_TCP
case "udp":
return Network_UDP
case "unix":
return Network_UNIX
default:
return Network_Unknown
}
}
2021-09-06 22:58:48 +08:00
func ParseNetworks(netlist string) []Network {
strlist := strings.Split(netlist, ",")
nl := make([]Network, len(strlist))
for idx, network := range strlist {
nl[idx] = ParseNetwork(network)
}
return nl
}