Skip to content

Commit

Permalink
Avoid gopacket/pcap import to ease builds
Browse files Browse the repository at this point in the history
We want to avoid importing `gopacket/pcap`; it forces CGO_ENABLED=1,
which makes cross-compilation more challenging, which makes publishing
binaries more difficult.

fixes, when running `bin/build`:

```
vendor/github.com/gopacket/gopacket/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
```

fixes, when running acceptance tests:

```
../vendor/github.com/gopacket/gopacket/pcap/pcap_unix.go:35:10: fatal error: 'pcap.h' file not found
```

Signed-off-by: Brian Cunnie <[email protected]>
  • Loading branch information
aramprice authored and cunnie committed Nov 28, 2023
1 parent fbc14eb commit 2768232
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pcap/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/gopacket/gopacket"
"github.com/gopacket/gopacket/layers"
"github.com/gopacket/gopacket/pcap"
"github.com/gopacket/gopacket/pcapgo"
"golang.org/x/crypto/ssh"

Expand Down Expand Up @@ -286,18 +285,16 @@ func openPcapHandle(tcpdumpCmd string, session *ssh.Session, wg *sync.WaitGroup,
// The pcap handle can be created without blocking after readable exists.
out := make(chan gopacket.Packet)
go func() {
handle, err := pcap.OpenOfflineFile(readable)
ngReader, err := pcapgo.NewNgReader(readable, pcapgo.NgReaderOptions{}) // which NgReaderOptions should I set?
if err != nil {
cancel(openHandleError)
return
}

packetSource := gopacket.NewPacketSource(handle, layers.LayerTypeEthernet)
packetSource := gopacket.NewPacketSource(ngReader, layers.LayerTypeEthernet)

// Run a goroutine that will write packets to the channel
go func() {
defer handle.Close()

for packet := range packetSource.Packets() {
out <- packet
}
Expand Down

0 comments on commit 2768232

Please sign in to comment.