{"record":{"id":"1b04d90783c3a077","repo":"txthinking/brook","slug":"invalid-v4-ip","errorCode":null,"errorMessage":"Invalid v4 IP","messagePattern":"Invalid v4 IP","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dhcpserver.go","lineNumber":40,"sourceCode":"\t\"path/filepath\"\n\t\"time\"\n\n\t\"github.com/krolaw/dhcp4\"\n)\n\ntype DHCPServer struct {\n\tListen   net.PacketConn\n\tServerIP net.IP\n\tStart    net.IP\n\tCount    int\n\tLeases   map[int]string\n\tOptions  dhcp4.Options\n\tCache    string\n}\n\nfunc NewDHCPServer(iface, serverip, start, mask string, count int, gateway string, dnsserver []string, cache string) (*DHCPServer, error) {\n\tif net.ParseIP(serverip).To4() == nil || net.ParseIP(start).To4() == nil || net.ParseIP(mask).To4() == nil || net.ParseIP(gateway).To4() == nil {\n\t\treturn nil, errors.New(\"Invalid v4 IP\")\n\t}\n\tdnsserverips := make([]net.IP, 0)\n\tfor _, v := range dnsserver {\n\t\tif net.ParseIP(v).To4() == nil {\n\t\t\treturn nil, errors.New(\"Invalid v4 IP\")\n\t\t}\n\t\tdnsserverips = append(dnsserverips, net.ParseIP(v).To4())\n\t}\n\tif cache == \"\" {\n\t\ts, err := os.UserHomeDir()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tcache = filepath.Join(s, \".brook.dhcpserver\")\n\t}\n\tb, err := os.ReadFile(cache)\n\tif err != nil && !os.IsNotExist(err) {\n\t\treturn nil, err","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/txthinking/brook/blob/5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8/dhcpserver.go#L22-L58","documentation":"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.","triggerScenarios":"Thrown at dhcpserver.go:40 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check each argument (serverip, start, mask, gateway) is a valid dotted-quad IPv4 address","Ensure no argument is empty or an IPv6 address"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8","analyzedAt":"2026-09-06T04:35:00.432Z","contentChangedAt":"2026-09-06T04:35:00.432Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}