mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 07:54:40 +03:00
mox!
This commit is contained in:
21
mox-/ip.go
Normal file
21
mox-/ip.go
Normal file
@ -0,0 +1,21 @@
|
||||
package mox
|
||||
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
// Network returns tcp4 or tcp6, depending on the ip.
|
||||
// This network can be passed to Listen instead of "tcp", which may start listening
|
||||
// on both ipv4 and ipv6 for addresses 0.0.0.0 and ::, which can lead to errors
|
||||
// about the port already being in use.
|
||||
// For invalid IPs, "tcp" is returned.
|
||||
func Network(ip string) string {
|
||||
v := net.ParseIP(ip)
|
||||
if v == nil {
|
||||
return "tcp"
|
||||
}
|
||||
if v.To4() != nil {
|
||||
return "tcp4"
|
||||
}
|
||||
return "tcp6"
|
||||
}
|
Reference in New Issue
Block a user