mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-24 22:15:45 +03:00
40884624c2
Updates #5990. Squashed commit of the following: commit 1d5d3451c855681a631b85652417ee1bebadab01 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Jul 11 20:11:45 2023 +0300 all: allow ignoring root in querylog and stats
32 lines
647 B
Go
32 lines
647 B
Go
package aghnet
|
|
|
|
import (
|
|
"net/netip"
|
|
"strings"
|
|
)
|
|
|
|
// GenerateHostname generates the hostname from ip. In case of using IPv4 the
|
|
// result should be like:
|
|
//
|
|
// 192-168-10-1
|
|
//
|
|
// In case of using IPv6, the result is like:
|
|
//
|
|
// ff80-f076-0000-0000-0000-0000-0000-0010
|
|
//
|
|
// ip must be either an IPv4 or an IPv6.
|
|
func GenerateHostname(ip netip.Addr) (hostname string) {
|
|
if !ip.IsValid() {
|
|
// TODO(s.chzhen): Get rid of it.
|
|
panic("aghnet generate hostname: invalid ip")
|
|
}
|
|
|
|
ip = ip.Unmap()
|
|
hostname = ip.StringExpanded()
|
|
|
|
if ip.Is4() {
|
|
return strings.ReplaceAll(hostname, ".", "-")
|
|
}
|
|
|
|
return strings.ReplaceAll(hostname, ":", "-")
|
|
}
|