{"record":{"id":"d40561f70dda8bbc","repo":"jeessy2/ddns-go","slug":"s-d40561","errorCode":null,"errorMessage":"网卡 %s 没有可用的单播地址","messagePattern":"网卡 (.+?) 没有可用的单播地址","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/http_client_util.go","lineNumber":112,"sourceCode":"\t}\n}\n\n// GetLocalAddrFromInterface 根据网卡名称获取本地IP地址\nfunc GetLocalAddrFromInterface(ifaceName string) (string, error) {\n\tiface, err := net.InterfaceByName(ifaceName)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"找不到网卡 %s: %v\", ifaceName, err)\n\t}\n\taddrs, err := iface.Addrs()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"获取网卡 %s 地址失败: %v\", ifaceName, err)\n\t}\n\tfor _, addr := range addrs {\n\t\tif ipNet, ok := addr.(*net.IPNet); ok && ipNet.IP.IsGlobalUnicast() {\n\t\t\treturn ipNet.IP.String(), nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"网卡 %s 没有可用的单播地址\", ifaceName)\n}\n\n// CreateHTTPClientWithInterface 创建绑定指定网卡的HTTP客户端\nfunc CreateHTTPClientWithInterface(ifaceName string) *http.Client {\n\tif ifaceName == \"\" {\n\t\treturn CreateHTTPClient()\n\t}\n\tlocalIP, err := GetLocalAddrFromInterface(ifaceName)\n\tif err != nil {\n\t\tLog(\"绑定网卡失败, 将使用默认网卡. 网卡: %s, 错误: %v\", ifaceName, err)\n\t\treturn CreateHTTPClient()\n\t}\n\tlocalAddr := &net.TCPAddr{IP: net.ParseIP(localIP)}\n\tboundDialer := newHTTPDialer(localAddr)\n\tsetLinuxBindToDevice(boundDialer, ifaceName)\n\ttransport := &http.Transport{\n\t\tProxy: http.ProxyFromEnvironment,\n\t\tDialContext: func(ctx context.Context, network, address string) (net.Conn, error) {","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/util/http_client_util.go#L94-L130","documentation":"GetLocalAddrFromInterface found the interface and read its addresses, but none of them were a global unicast address, so there is no IP the library can use as the client's bind address. Only addresses passing net.IP.IsGlobalUnicast() (public/universe scope, not loopback, link-local, or multicast) are accepted. This error means 'interface <name> has no usable unicast address'.","triggerScenarios":"Calling GetLocalAddrFromInterface/CreateHTTPClientWithInterface on an interface whose only addresses are loopback (127.0.0.1/::1), link-local (169.254.x.x, fe80::/10), or multicast-only — e.g. an interface that is UP but never got a DHCP lease.","commonSituations":"DHCP failure leaving only an APIPA 169.254.x.x address on the NIC; freshly created veth/bridge with no IP; VPN tun device up but unconfigured; point-to-point links with only link-local addressing.","solutions":["Check `ip addr show <iface>` — the interface needs a global-scope address; fix DHCP or assign a static address","Select a different interface that has a real (global unicast) IP address","Wait for DHCP/SLAAC to complete before initializing the client, or re-trigger the DHCP request","If you intentionally bind to a link address, this API cannot help — remove the interface binding and use the default client"],"exampleFix":"// before\nclient := util.CreateHTTPClientWithInterface(\"eth1\") // eth1 only has 169.254.10.20 (APIPA)\n// after\ndhclient eth1 # or assign a static global address, then:\nclient := util.CreateHTTPClientWithInterface(\"eth1\")","handlingStrategy":"validation","validationCode":"func ifaceHasUsableAddr(name string) bool {\n\tiface, err := net.InterfaceByName(name)\n\tif err != nil { return false }\n\taddrs, _ := iface.Addrs()\n\tfor _, a := range addrs {\n\t\tif ipnet, ok := a.(*net.IPNet); ok && ipnet.IP.IsGlobalUnicast() { return true }\n\t}\n\treturn false\n}\n// guard: if !ifaceHasUsableAddr(cfg.Interface) { alert/fix network first }","typeGuard":null,"tryCatchPattern":"_, err := util.GetLocalAddrFromInterface(ifaceName)\nif err != nil {\n\tlog.Printf(\"interface %s has no global unicast address (%v); using default client\", ifaceName, err)\n\tclient = util.CreateHTTPClient()\n}","preventionTips":["Ensure DHCP succeeds or a static global address is assigned before binding","Alert on APIPA/link-local-only addresses (169.254.0.0/16, fe80::/10) on monitored NICs","Check `ip addr show` for a 'global' scope address, not just interface UP state","Delay client creation until network-manager/DHCP reports the interface configured"],"tags":["network","interface-binding","go","unicast-address"],"backgroundTag":"no-suitable-interface-address","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}