MCPcopy
hub / github.com/nextdns/nextdns / isLocalhostMode

Function isLocalhostMode

run.go:494–517  ·  view source on GitHub ↗

isLocalhostMode returns true if listen is only listening for the local host.

(c *config.Config)

Source from the content-addressed store, hash-verified

492
493// isLocalhostMode returns true if listen is only listening for the local host.
494func isLocalhostMode(c *config.Config) bool {
495 if c.SetupRouter {
496 // The listen arg is irrelevant when in router mode.
497 return false
498 }
499 for _, listen := range c.Listens {
500 if host, _, err := net.SplitHostPort(listen); err == nil {
501 switch host {
502 case "localhost", "127.0.0.1", "::1":
503 continue
504 }
505 if ips := hosts.LookupHost(host); len(ips) > 0 {
506 for _, ip := range ips {
507 if !net.ParseIP(ip).IsLoopback() {
508 return false
509 }
510 }
511 } else if !net.ParseIP(host).IsLoopback() {
512 return false
513 }
514 }
515 }
516 return true
517}
518
519func maybeUseResolvedCompatListen(c *config.Config, log host.Logger) {
520 if runtime.GOOS != "linux" || c.SetupRouter || !resolved.Available() {

Callers 2

runFunction · 0.85
Test_isLocalhostModeFunction · 0.85

Calls 1

LookupHostFunction · 0.92

Tested by 1

Test_isLocalhostModeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…