mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 03:02:48 +01:00
commit
b975c6f182
17
irc/net.go
17
irc/net.go
@ -28,16 +28,19 @@ func AddrLookupHostname(addr net.Addr) string {
|
|||||||
// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
|
// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
|
||||||
func LookupHostname(addr string) string {
|
func LookupHostname(addr string) string {
|
||||||
names, err := net.LookupAddr(addr)
|
names, err := net.LookupAddr(addr)
|
||||||
if err != nil || len(names) < 1 || !IsHostname(names[0]) {
|
if err == nil && len(names) > 0 {
|
||||||
// return original address if no hostname found
|
candidate := strings.TrimSuffix(names[0], ".")
|
||||||
if len(addr) > 0 && addr[0] == ':' {
|
if IsHostname(candidate) {
|
||||||
// fix for IPv6 hostnames (so they don't start with a colon), same as all other IRCds
|
return candidate
|
||||||
addr = "0" + addr
|
|
||||||
}
|
}
|
||||||
return addr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return names[0]
|
// return original address if no hostname found
|
||||||
|
if len(addr) > 0 && addr[0] == ':' {
|
||||||
|
// fix for IPv6 hostnames (so they don't start with a colon), same as all other IRCds
|
||||||
|
addr = "0" + addr
|
||||||
|
}
|
||||||
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
|
var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
|
||||||
|
Loading…
Reference in New Issue
Block a user