{"record":{"id":"aef6ee535c8a7979","repo":"snail007/goproxy","slug":"no-address-found-net-interfaceaddrs-v","errorCode":null,"errorMessage":"no address Found, net.InterfaceAddrs: %v","messagePattern":"no address Found, net\\.InterfaceAddrs: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"utils/functions.go","lineNumber":259,"sourceCode":"\t\t\tvar ip net.IP\n\t\t\tswitch v := addr.(type) {\n\t\t\tcase *net.IPNet:\n\t\t\t\tip = v.IP\n\t\t\tcase *net.IPAddr:\n\t\t\t\tip = v.IP\n\t\t\t}\n\t\t\t// if ip == nil || ip.IsLoopback() {\n\t\t\t// \tcontinue\n\t\t\t// }\n\t\t\tip = ip.To4()\n\t\t\tif ip == nil {\n\t\t\t\tcontinue // not an ipv4 address\n\t\t\t}\n\t\t\taddresses = append(addresses, ip)\n\t\t}\n\t}\n\tif len(addresses) == 0 {\n\t\treturn nil, fmt.Errorf(\"no address Found, net.InterfaceAddrs: %v\", addresses)\n\t}\n\t//only need first\n\treturn addresses, nil\n}\nfunc UDPPacket(srcAddr string, packet []byte) []byte {\n\taddrBytes := []byte(srcAddr)\n\taddrLength := uint16(len(addrBytes))\n\tbodyLength := uint16(len(packet))\n\tpkg := new(bytes.Buffer)\n\tbinary.Write(pkg, binary.LittleEndian, addrLength)\n\tbinary.Write(pkg, binary.LittleEndian, addrBytes)\n\tbinary.Write(pkg, binary.LittleEndian, bodyLength)\n\tbinary.Write(pkg, binary.LittleEndian, packet)\n\treturn pkg.Bytes()\n}\nfunc ReadUDPPacket(conn *net.Conn) (srcAddr string, packet []byte, err error) {\n\treader := bufio.NewReader(*conn)\n\tvar addrLength uint16","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/snail007/goproxy/blob/e6d6a821db80e7f47ee6e981a144984e1d4ddb3d/utils/functions.go#L241-L277","documentation":"GetAllInterfaceAddr enumerates net.Interfaces() and collects only IPv4 addresses (it calls ip.To4() and skips anything else). If, after iterating all interfaces, the list is still empty, it returns \"no address Found, net.InterfaceAddrs: []\". The library requires at least one usable local IPv4 address (e.g. to build source addresses for UDP packets), so it treats an empty result as a hard failure.","triggerScenarios":"Calling GetAllInterfaceAddr (directly or via IsDeadLoop) on a host where net.InterfaceAddrs() returns no address convertible to IPv4: no interfaces are up, all addresses are IPv6-only, or the process runs in a network namespace/container with no assigned IPv4 addresses.","commonSituations":"Running the proxy inside a Docker/Kubernetes pod configured IPv6-only; running on a host with all interfaces down; restricted network namespaces (e.g. sandboxed CI runners) with only a loopback that has no IPv4; minimal VM images without networking configured at boot.","solutions":["Verify the machine actually has an IPv4 address: run `ip -4 addr` (or `ip addr`) and bring an interface up / assign an address if missing (e.g. `ip link set eth0 up && dhclient eth0`).","If running in a container, check the network configuration: use a network driver/CNI that assigns IPv4, or explicitly create an IPv4 network (e.g. `docker network create --driver bridge`).","If the host is intentionally IPv6-only, patch GetAllInterfaceAddr to also accept IPv6 addresses (remove the strict To4() filter or add a parallel IPv6 branch).","As a last resort in restricted environments, ensure loopback has an IPv4 address (127.0.0.1) since the code does not exclude loopback interfaces (that check is commented out)."],"exampleFix":"// before\nip = ip.To4()\nif ip == nil {\n\tcontinue // not an ipv4 address\n}\naddresses = append(addresses, ip)\n\n// after\nif ip4 := ip.To4(); ip4 != nil {\n\taddresses = append(addresses, ip4)\n} else if ip != nil && ip.To16() != nil {\n\taddresses = append(addresses, ip) // keep IPv6 as fallback\n}","handlingStrategy":"validation","validationCode":"ifaces, err := net.Interfaces()\nhasV4 := false\nif err == nil {\n\tfor _, iface := range ifaces {\n\t\tif iface.Flags&net.FlagUp == 0 {\n\t\t\tcontinue\n\t\t}\n\t\taddrs, _ := iface.Addrs()\n\t\tfor _, a := range addrs {\n\t\t\tvar ip net.IP\n\t\t\tswitch v := a.(type) {\n\t\t\tcase *net.IPNet:\n\t\t\t\tip = v.IP\n\t\t\tcase *net.IPAddr:\n\t\t\t\tip = v.IP\n\t\t\t}\n\t\t\tif ip != nil && ip.To4() != nil {\n\t\t\t\thasV4 = true\n\t\t\t}\n\t\t}\n\t}\n}\nif !hasV4 {\n\treturn errors.New(\"host has no usable IPv4 address; cannot start proxy\")\n}\naddrs, err := utils.GetAllInterfaceAddr()","typeGuard":"func hasIPv4Address(addrs []net.IP) bool {\n\tfor _, ip := range addrs {\n\t\tif ip != nil && ip.To4() != nil {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}","tryCatchPattern":"addrs, err := utils.GetAllInterfaceAddr()\nif err != nil {\n\tlog.Fatalf(\"no local IPv4 address available, check network config: %v\", err)\n}","preventionTips":["Verify with `ip -4 addr` that the host/container has an IPv4 address before deploying.","Use container network drivers/CNIs that assign IPv4 (avoid IPv6-only pods).","Add a startup readiness check that fails fast if no IPv4 interface exists.","Remember the code accepts loopback too — a bare namespace with only 127.0.0.1 will still pass."],"tags":["network","go","ipv4","interface-enumeration"],"backgroundTag":"no-network-interface-ipv4","analyzedSha":"e6d6a821db80e7f47ee6e981a144984e1d4ddb3d","analyzedAt":"2026-09-03T15:32:42.750Z","contentChangedAt":"2026-09-03T15:32:42.750Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}