mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 10:10:08 -08:00
commit
b975c6f182
1 changed files with 10 additions and 7 deletions
11
irc/net.go
11
irc/net.go
|
|
@ -28,7 +28,13 @@ func AddrLookupHostname(addr net.Addr) string {
|
|||
// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
|
||||
func LookupHostname(addr string) string {
|
||||
names, err := net.LookupAddr(addr)
|
||||
if err != nil || len(names) < 1 || !IsHostname(names[0]) {
|
||||
if err == nil && len(names) > 0 {
|
||||
candidate := strings.TrimSuffix(names[0], ".")
|
||||
if IsHostname(candidate) {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
|
@ -37,9 +43,6 @@ func LookupHostname(addr string) string {
|
|||
return addr
|
||||
}
|
||||
|
||||
return names[0]
|
||||
}
|
||||
|
||||
var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
|
||||
|
||||
// IsHostname returns whether we consider `name` a valid hostname.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue