{"record":{"id":"c7e48c540fa96368","repo":"probelabs/goreplay","slug":"snapshot-length-error-q-interface-q","errorCode":null,"errorMessage":"snapshot length error: %q, interface: %q","messagePattern":"snapshot length error: %q, interface: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/capture/capture.go","lineNumber":448,"sourceCode":"\n\tvar snap int\n\n\tif !l.config.Snaplen {\n\t\tinfs, _ := net.Interfaces()\n\t\tfor _, i := range infs {\n\t\t\tif i.Name == ifi.Name {\n\t\t\t\tsnap = i.MTU + 200\n\t\t\t}\n\t\t}\n\t}\n\n\tif snap == 0 {\n\t\tsnap = 64<<10 + 200\n\t}\n\n\terr = inactive.SetSnapLen(snap)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"snapshot length error: %q, interface: %q\", err, ifi.Name)\n\t}\n\tif l.config.BufferSize > 0 {\n\t\terr = inactive.SetBufferSize(int(l.config.BufferSize))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"handle buffer size error: %q, interface: %q\", err, ifi.Name)\n\t\t}\n\t}\n\tif l.config.BufferTimeout == 0 {\n\t\tl.config.BufferTimeout = 2000 * time.Millisecond\n\t}\n\terr = inactive.SetTimeout(l.config.BufferTimeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"handle buffer timeout error: %q, interface: %q\", err, ifi.Name)\n\t}\n\thandle, err = inactive.Activate()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"PCAP Activate device error: %q, interface: %q\", err, ifi.Name)\n\t}","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/probelabs/goreplay/blob/251e45abd242886bb64ff2b2dc98789556b56330/internal/capture/capture.go#L430-L466","documentation":"PcapHandle computes a snapshot length (default 64KiB+200 when unset) and applies it with inactive.SetSnapLen. Failure is wrapped as \"snapshot length error: <err>, interface: <name>\". This means libpcap rejected the requested snaplen on the not-yet-activated handle.","triggerScenarios":"Calling PcapHandle after l.config.Snaplen-derived value is invalid (e.g. negative, absurdly large, or zero path mishandled) so SetSnapLen fails on the inactive handle.","commonSituations":"Config supplying a negative or enormous snaplen from a YAML/env value; unit confusion (bits vs bytes); platform limits on snaplen; snaplen unset edge cases in custom builds.","solutions":["Validate the snaplen is a positive, sane value (e.g. 1..262144) before calling PcapHandle","Use the default (64<<10 + 200) by leaving snap unset unless you need truncation","Clamp the configured snaplen to the interface MTU or a maximum of 65535","Log the computed snap value to confirm what is being passed"],"exampleFix":"// before\nsnap := cfg.Snaplen // could be -1 from bad config\nerr = inactive.SetSnapLen(snap)\n// after\nif snap < 1 || snap > 65535 { snap = 64<<10 + 200 }\nerr = inactive.SetSnapLen(snap)","handlingStrategy":"validation","validationCode":"if cfg.Snaplen != 0 && (cfg.Snaplen < 1 || cfg.Snaplen > 65535) {\n    return fmt.Errorf(\"snaplen %d out of range 1..65535\", cfg.Snaplen)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"snapshot length error\") {\n    log.Warnf(\"snaplen rejected, using default: %v\", err)\n    cfg.Snaplen = 0\n    handle, err = l.PcapHandle(ifi)\n}","preventionTips":["Clamp configured snaplen to 1..65535","Use 0/default (64KiB+200) unless truncation is intentional","Guard against negative values from YAML/env config parsing"],"tags":["go","pcap","snaplen","libpcap"],"backgroundTag":"invalid-snaplen","analyzedSha":"251e45abd242886bb64ff2b2dc98789556b56330","analyzedAt":"2026-09-02T16:44:11.369Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}