snail007/goproxy · critical

no address Found, net.InterfaceAddrs: %v

Error message

no address Found, net.InterfaceAddrs: %v

What it means

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.

Source

Thrown at utils/functions.go:259

			var ip net.IP
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}
			// if ip == nil || ip.IsLoopback() {
			// 	continue
			// }
			ip = ip.To4()
			if ip == nil {
				continue // not an ipv4 address
			}
			addresses = append(addresses, ip)
		}
	}
	if len(addresses) == 0 {
		return nil, fmt.Errorf("no address Found, net.InterfaceAddrs: %v", addresses)
	}
	//only need first
	return addresses, nil
}
func UDPPacket(srcAddr string, packet []byte) []byte {
	addrBytes := []byte(srcAddr)
	addrLength := uint16(len(addrBytes))
	bodyLength := uint16(len(packet))
	pkg := new(bytes.Buffer)
	binary.Write(pkg, binary.LittleEndian, addrLength)
	binary.Write(pkg, binary.LittleEndian, addrBytes)
	binary.Write(pkg, binary.LittleEndian, bodyLength)
	binary.Write(pkg, binary.LittleEndian, packet)
	return pkg.Bytes()
}
func ReadUDPPacket(conn *net.Conn) (srcAddr string, packet []byte, err error) {
	reader := bufio.NewReader(*conn)
	var addrLength uint16

View on GitHub (pinned to e6d6a821db)

Solutions

  1. 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`).
  2. 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`).
  3. 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).
  4. 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).

Example fix

// before
ip = ip.To4()
if ip == nil {
	continue // not an ipv4 address
}
addresses = append(addresses, ip)

// after
if ip4 := ip.To4(); ip4 != nil {
	addresses = append(addresses, ip4)
} else if ip != nil && ip.To16() != nil {
	addresses = append(addresses, ip) // keep IPv6 as fallback
}
Defensive patterns

Strategy: validation

Validate before calling

ifaces, err := net.Interfaces()
hasV4 := false
if err == nil {
	for _, iface := range ifaces {
		if iface.Flags&net.FlagUp == 0 {
			continue
		}
		addrs, _ := iface.Addrs()
		for _, a := range addrs {
			var ip net.IP
			switch v := a.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}
			if ip != nil && ip.To4() != nil {
				hasV4 = true
			}
		}
	}
}
if !hasV4 {
	return errors.New("host has no usable IPv4 address; cannot start proxy")
}
addrs, err := utils.GetAllInterfaceAddr()

Type guard

func hasIPv4Address(addrs []net.IP) bool {
	for _, ip := range addrs {
		if ip != nil && ip.To4() != nil {
			return true
		}
	}
	return false
}

Try / catch

addrs, err := utils.GetAllInterfaceAddr()
if err != nil {
	log.Fatalf("no local IPv4 address available, check network config: %v", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of snail007/goproxy@e6d6a821db (2026-09-03). Data as JSON: /api/errors/aef6ee535c8a7979. Report an issue: GitHub.