diff --git a/cmd/writer.go b/cmd/writer.go index f716aead..674fb68c 100644 --- a/cmd/writer.go +++ b/cmd/writer.go @@ -13,6 +13,7 @@ import ( "math" "os" "runtime" + "sort" ) func getWriters(opts Options, pcache *metadata.ProcessCache) ([]writer.PacketWriter, error) { @@ -46,19 +47,25 @@ func newPcapWriter(w io.Writer, pcache *metadata.ProcessCache) (*writer.PcapNGWr var interfaces []pcapgo.NgInterface for _, dev := range devices { interfaces = append(interfaces, pcapgo.NgInterface{ + Index: dev.Ifindex, Name: dev.Name, Filter: opts.pcapFilter, OS: runtime.GOOS, LinkType: layers.LinkTypeEthernet, SnapLength: uint32(math.MaxUint16), + //TimestampResolution: 9, }) } + sort.Slice(interfaces, func(i, j int) bool { + return interfaces[i].Index < interfaces[j].Index + }) pcapWriter, err := pcapgo.NewNgWriterInterface(w, interfaces[0], pcapgo.NgWriterOptions{ SectionInfo: pcapgo.NgSectionInfo{ Hardware: runtime.GOARCH, OS: runtime.GOOS, Application: fmt.Sprintf("ptcpdump %s", internal.Version), + Comment: "ptcpdump: https://github.com/mozillazg/ptcpdump", }, }) if err != nil { diff --git a/go.mod b/go.mod index 2d04ece0..070311a6 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,6 @@ require ( ) replace ( - github.com/gopacket/gopacket => github.com/mozillazg/gopacket v0.0.0-20240420072046-71afeafe42df + github.com/gopacket/gopacket => github.com/mozillazg/gopacket v0.0.0-20240429121216-bf7893b04e11 github.com/x-way/pktdump => github.com/mozillazg/pktdump v0.0.0-20240422135914-a9ab652291b1 ) diff --git a/go.sum b/go.sum index a1cc8221..d151f47f 100644 --- a/go.sum +++ b/go.sum @@ -75,8 +75,8 @@ github.com/mdlayher/netlink v1.6.0/go.mod h1:0o3PlBmGst1xve7wQ7j/hwpNaFaH4qCRyWC github.com/mdlayher/socket v0.0.0-20210307095302-262dc9984e00/go.mod h1:GAFlyu4/XV68LkQKYzKhIo/WW7j3Zi0YRAz/BOoanUc= github.com/mdlayher/socket v0.1.1 h1:q3uOGirUPfAV2MUoaC7BavjQ154J7+JOkTWyiV+intI= github.com/mdlayher/socket v0.1.1/go.mod h1:mYV5YIZAfHh4dzDVzI8x8tWLWCliuX8Mon5Awbj+qDs= -github.com/mozillazg/gopacket v0.0.0-20240420072046-71afeafe42df h1:dP09t/Mu44X7itTtVKr0H+NCCvpROItG5FMkPkzUhT4= -github.com/mozillazg/gopacket v0.0.0-20240420072046-71afeafe42df/go.mod h1:lnXM4VDqJTe4d2NoZr8DZMtidkhss2Y82QFlamXWfXo= +github.com/mozillazg/gopacket v0.0.0-20240429121216-bf7893b04e11 h1:c5vYy0pngzBHc8NcxiGTckc2qpQzw4ImPesF2qAU8Ok= +github.com/mozillazg/gopacket v0.0.0-20240429121216-bf7893b04e11/go.mod h1:lnXM4VDqJTe4d2NoZr8DZMtidkhss2Y82QFlamXWfXo= github.com/mozillazg/pktdump v0.0.0-20240422135914-a9ab652291b1 h1:hAP2PH4czj22vr78Dh6dPlXlxDsKK/uYNxPiE9jvRUM= github.com/mozillazg/pktdump v0.0.0-20240422135914-a9ab652291b1/go.mod h1:InLCDK8kgkk26VtyPZ51e0igf15eiXDMvvQuV62Wqmw= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/internal/dev/dev.go b/internal/dev/dev.go index 28b75e8a..aeadb825 100644 --- a/internal/dev/dev.go +++ b/internal/dev/dev.go @@ -38,6 +38,7 @@ func GetDevices(names []string) (map[int]Device, error) { for _, lk := range allLinks { if lk.Attrs().Name == name { links = append(links, lk) + continue } } }