mirror of
https://github.com/mandiant/gopacket
synced 2026-06-21 13:57:02 +00:00
90038dcfc2
Splits pkg/transport into a router (tcp.go) plus two platform-specific direct dialers: direct_libc.go preserves the existing cgo libc connect() path on Unix (so proxychains can still hook it), and direct_portable.go provides a pure-Go fallback for CGO_ENABLED=0 and Windows builds. Adds proxy.go with: - Configure(Options) / ConfigureProxy to wire a SOCKS5 URL (socks5 or socks5h), with ALL_PROXY / all_proxy env fallback read directly via os.Getenv (not proxy.FromEnvironment, whose sync.Once cache is not test-friendly). - DialContext routing through the configured proxy, or directDial. - DialUDP returning ErrUDPUnderProxy when proxied, rather than silently leaking UDP packets past the SOCKS5. - IsProxyConfigured and ProxyURL for callers that need to short-circuit features that can't be tunneled. - libcForwarder so the TCP leg to the SOCKS5 proxy itself still goes through libc, enabling proxychains -> gopacket -> -proxy chaining. Tests: - export_test.go exposes ResetForTest for test isolation (Configure panics on double-call, so each test resets package state). - socks5_server_test.go hand-rolls a minimal in-process SOCKS5 server (CONNECT + no-auth, ~130 LOC, no new deps). - proxy_test.go covers invalid scheme rejection, socks5/socks5h accept, ALL_PROXY env fallback, double-call panic, default state, DialUDP/DialContext UDP rejection, credential redaction, direct-path behavior when unconfigured, and an end-to-end round-trip through the in-process SOCKS5.