func (r *PacketReader) ReadAndDump(target Target) error {
	packetChan := r.packetSource.Packets()
	if r.dumper.Name() == "conn" {
		go r.handleConn(target)
	} else {
		go r.handlePacket(target)
	}
	go r.checkBufferdPacket(packetChan)
	for {
		select {
		case <-r.ctx.Done():
			return nil
		case packet := <-packetChan:
			r.packetBuffer <- packet
		}
	}
}
ReadAndDump from gopacket.PacketSource
package reader
import (
	"context"
	"encoding/binary"
	"fmt"
	"net"
	"runtime"
	"strconv"
	"strings"
	"time"
	"github.com/google/gopacket"
	"github.com/google/gopacket/layers"
	"github.com/k1LoW/tcpdp/dumper"
	"github.com/rs/xid"
	"go.uber.org/zap"
)
const anyIP = "0.0.0.0"
var packetTTL = 600        
var maxPacketLen = 0xFFFF  
type Target struct {
	TargetHosts []TargetHost
}
type TargetHost struct {
	Host string
	Port uint16
}
func (t Target) Match(host string, port uint16) bool {
	for _, h := range t.TargetHosts {
		if (h.Host == "" || h.Host == host) && h.Port == port {
			return true
		}
	}
	return false
}
func ParseTarget(t string) (Target, error) {
	ts := strings.Split(strings.Replace(t, " ", "", -1), "||")
	targets := []TargetHost{}
	for _, t := range ts {
		var port uint16
		var host string
		if t == "" {
			host = ""
			port = uint16(0)
		} else if strings.Contains(t, ":") {
			tAddr, err := net.ResolveTCPAddr("tcp", t)
			if err != nil {
				return Target{}, err
			}
			host = tAddr.IP.String()
			port = uint16(tAddr.Port)
		} else if strings.Contains(t, ".") {
			host = t
			port = uint16(0)
		} else {
			host = ""
			port64, err := strconv.ParseUint(t, 10, 64)
			if err != nil {
				return Target{}, err
			}
			port = uint16(port64)
		}
		targets = append(targets, TargetHost{
			Host: host,
			Port: port,
		})
	}
	return Target{
		TargetHosts: targets,
	}, nil
}
func NewBPFFilterString(target Target) string {
	targets := target.TargetHosts
	fs := []string{}
	for _, target := range targets {
		host := target.Host
		port := target.Port
		f := fmt.Sprintf("(host %s and port %d)", host, port)
		if (host == "" || host == anyIP) && port > 0 {
			f = fmt.Sprintf("(port %d)", port)
		} else if (host != "" && host != anyIP) && port == 0 {
			f = fmt.Sprintf("(host %s)", host)
		} else if (host == "" || host == anyIP) && port == 0 {
			return "tcp"
		}
		fs = append(fs, f)
	}
	return fmt.Sprintf("tcp and (%s)", strings.Join(fs, " or "))
}
type PacketReader struct {
	ctx            context.Context
	cancel         context.CancelFunc
	packetSource   *gopacket.PacketSource
	dumper         dumper.Dumper
	pValues        []dumper.DumpValue
	logger         *zap.Logger
	packetBuffer   chan gopacket.Packet
	proxyProtocol  bool
	enableInternal bool
}
func NewPacketReader(
	ctx context.Context,
	cancel context.CancelFunc,
	packetSource *gopacket.PacketSource,
	dumper dumper.Dumper,
	pValues []dumper.DumpValue,
	logger *zap.Logger,
	internalBufferLength int,
	proxyProtocol bool,
	enableInternal bool,
) PacketReader {
	internalPacketBuffer := make(chan gopacket.Packet, internalBufferLength)
	reader := PacketReader{
		ctx:            ctx,
		cancel:         cancel,
		packetSource:   packetSource,
		dumper:         dumper,
		pValues:        pValues,
		logger:         logger,
		packetBuffer:   internalPacketBuffer,
		proxyProtocol:  proxyProtocol,
		enableInternal: enableInternal,
	}
	return reader
}