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