1
0
Fork 0
forked from External/ergo

allow WEBIRC to set the TLS flag over local plaintext connections

This commit is contained in:
Shivaram Lingamneni 2018-01-31 21:07:57 -05:00
parent 09a17b32be
commit b7f66fb1de
2 changed files with 16 additions and 3 deletions

View file

@ -25,6 +25,17 @@ func AddrLookupHostname(addr net.Addr) string {
return LookupHostname(IPString(addr))
}
// AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).
func AddrIsLocal(addr net.Addr) bool {
if tcpaddr, ok := addr.(*net.TCPAddr); ok {
return tcpaddr.IP.IsLoopback()
}
if _, ok := addr.(*net.UnixAddr); ok {
return true
}
return false
}
// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
func LookupHostname(addr string) string {
names, err := net.LookupAddr(addr)