|
@@ -25,6 +25,17 @@ func AddrLookupHostname(addr net.Addr) string {
|
25
|
25
|
return LookupHostname(IPString(addr))
|
26
|
26
|
}
|
27
|
27
|
|
|
28
|
+// AddrIsLocal returns whether the address is from a trusted local connection (loopback or unix).
|
|
29
|
+func AddrIsLocal(addr net.Addr) bool {
|
|
30
|
+ if tcpaddr, ok := addr.(*net.TCPAddr); ok {
|
|
31
|
+ return tcpaddr.IP.IsLoopback()
|
|
32
|
+ }
|
|
33
|
+ if _, ok := addr.(*net.UnixAddr); ok {
|
|
34
|
+ return true
|
|
35
|
+ }
|
|
36
|
+ return false
|
|
37
|
+}
|
|
38
|
+
|
28
|
39
|
// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
|
29
|
40
|
func LookupHostname(addr string) string {
|
30
|
41
|
names, err := net.LookupAddr(addr)
|