Debian Codegraph @

debian/go/src/github.com/modelcontextprotocol/go-sdk/internal/util/net.go

raw symbols SCIP
1 // Copyright 2025 The Go MCP SDK Authors. All rights reserved.
2 // Use of this source code is governed by the license
3 // that can be found in the LICENSE file.
4 package util
5
6 import (
7 "net"
8 "net/netip"
9 "strings"
10 )
11
12 func IsLoopback(addr string) bool {
13 host, _, err := net.SplitHostPort(addr)
14 if err != nil {
15 // If SplitHostPort fails, it might be just a host without a port.
16 host = strings.Trim(addr, "[]")
17 }
18 if host == "localhost" {
19 return true
20 }
21 ip, err := netip.ParseAddr(host)
22 if err != nil {
23 return false
24 }
25 return ip.IsLoopback()
26 }