txthinking/brook · error
Invalid v4 IP
Error message
Invalid v4 IP
What it means
Constructor validation in NewDHCPServer: at least one of the serverip, start, mask, or gateway arguments failed net.ParseIP(...).To4() (nil), i.e. it is empty, malformed, or an IPv6 address, and a DHCPv4 server cannot be built from it. The generic guard does not say which argument is at fault, so all four must be checked.
Source
Thrown at dhcpserver.go:40
"path/filepath"
"time"
"github.com/krolaw/dhcp4"
)
type DHCPServer struct {
Listen net.PacketConn
ServerIP net.IP
Start net.IP
Count int
Leases map[int]string
Options dhcp4.Options
Cache string
}
func NewDHCPServer(iface, serverip, start, mask string, count int, gateway string, dnsserver []string, cache string) (*DHCPServer, error) {
if net.ParseIP(serverip).To4() == nil || net.ParseIP(start).To4() == nil || net.ParseIP(mask).To4() == nil || net.ParseIP(gateway).To4() == nil {
return nil, errors.New("Invalid v4 IP")
}
dnsserverips := make([]net.IP, 0)
for _, v := range dnsserver {
if net.ParseIP(v).To4() == nil {
return nil, errors.New("Invalid v4 IP")
}
dnsserverips = append(dnsserverips, net.ParseIP(v).To4())
}
if cache == "" {
s, err := os.UserHomeDir()
if err != nil {
return nil, err
}
cache = filepath.Join(s, ".brook.dhcpserver")
}
b, err := os.ReadFile(cache)
if err != nil && !os.IsNotExist(err) {
return nil, errView on GitHub (pinned to 5cd13ef3b1)
Solutions
- Check each argument (serverip, start, mask, gateway) is a valid dotted-quad IPv4 address
- Ensure no argument is empty or an IPv6 address
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at dhcpserver.go:40 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of txthinking/brook@5cd13ef3b1 (2026-09-06).
Data as JSON: /api/errors/1b04d90783c3a077.
Report an issue: GitHub.