add dns handler

This commit is contained in:
ginuerzh
2021-12-29 23:45:58 +08:00
parent 8600ee7c5d
commit 9b3d7e1110
15 changed files with 541 additions and 39 deletions

View File

@ -1,17 +0,0 @@
package tap
import "net"
type packetConn struct {
net.Conn
}
func (c *packetConn) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
n, err = c.Read(b)
addr = c.Conn.RemoteAddr()
return
}
func (c *packetConn) WriteTo(b []byte, addr net.Addr) (n int, err error) {
return c.Write(b)
}

View File

@ -2,6 +2,7 @@ package tap
import (
"context"
"errors"
"fmt"
"io"
"net"
@ -122,7 +123,12 @@ func (h *tapHandler) handleLoop(ctx context.Context, conn net.Conn, addr net.Add
if err != nil {
return err
}
pc = &packetConn{cc}
var ok bool
pc, ok = cc.(net.PacketConn)
if !ok {
return errors.New("invalid connection")
}
} else {
if h.md.tcpMode {
if addr != nil {