Skip to content

Commit

Permalink
bufix: fix "Can't send statistics for non existent interface"
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Apr 29, 2024
1 parent cca4c04 commit de8547d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cmd/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math"
"os"
"runtime"
"sort"
)

func getWriters(opts Options, pcache *metadata.ProcessCache) ([]writer.PacketWriter, error) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions internal/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit de8547d

Please sign in to comment.