1package mox
2
3import (
4 "net"
5)
6
7// Network returns tcp4 or tcp6, depending on the ip.
8// This network can be passed to Listen instead of "tcp", which may start listening
9// on both ipv4 and ipv6 for addresses 0.0.0.0 and ::, which can lead to errors
10// about the port already being in use.
11// For invalid IPs, "tcp" is returned.
12func Network(ip string) string {
13 v := net.ParseIP(ip)
14 if v == nil {
15 return "tcp"
16 }
17 if v.To4() != nil {
18 return "tcp4"
19 }
20 return "tcp6"
21}
22