add sniffer utility

This commit is contained in:
ginuerzh
2024-10-02 22:51:23 +08:00
parent 3c8add4b82
commit c42a44abb6
46 changed files with 1369 additions and 2723 deletions
+23
View File
@@ -3,6 +3,7 @@ package net
import (
"context"
"fmt"
"io"
"net"
"runtime"
"strings"
@@ -96,3 +97,25 @@ func (lc *ListenConfig) ListenPacket(ctx context.Context, network, address strin
}
return lc.ListenConfig.ListenPacket(ctx, network, address)
}
type readWriteConn struct {
net.Conn
r io.Reader
w io.Writer
}
func NewReadWriteConn(r io.Reader, w io.Writer, c net.Conn) net.Conn {
return &readWriteConn{
Conn: c,
r: r,
w: w,
}
}
func (c *readWriteConn) Read(p []byte) (int, error) {
return c.r.Read(p)
}
func (c *readWriteConn) Write(p []byte) (int, error) {
return c.w.Write(p)
}