fix(listener/tap): support custom TAP adapter name on Windows (issue #772)

The songgao/water library's InterfaceName parameter is a selection filter
that searches the Windows registry for an existing adapter with a matching
friendly name — it cannot name a new adapter during creation. Passing
name=tap0 caused the library to fail before even creating the adapter.

Fix by omitting InterfaceName from water.New(), letting Windows auto-name
the adapter, then renaming via netsh if a custom name was specified.

Also add directory validation to file handler to catch misconfig early.
This commit is contained in:
ginuerzh
2026-06-08 20:05:57 +08:00
parent 28e5922fce
commit 078cdbcb81
2 changed files with 32 additions and 5 deletions
+9
View File
@@ -4,6 +4,7 @@ package file
import (
"context"
"fmt"
"io"
"net"
"net/http"
@@ -57,6 +58,14 @@ func (h *fileHandler) Init(md md.Metadata) (err error) {
return
}
if h.md.dir != "" {
if info, err := os.Stat(h.md.dir); err != nil {
return fmt.Errorf("file handler: directory %q: %w", h.md.dir, err)
} else if !info.IsDir() {
return fmt.Errorf("file handler: %q is not a directory", h.md.dir)
}
}
fs := http.FileServer(http.Dir(h.md.dir))
h.handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut {