google / google/gopacket

OpenOfflineFile not working with os.Open

Open
#774 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I am using the `OpenOfflineFile` function to read libpcap data. I have tried these following functions:

- `os.Open()`
- `*TCPConn.File()`
- `os.Stdin`

Only `os.Stdin` works fine. The others will throw *Read Error* after normally read few packages.

Here is the sample code about `os.Open()`

```go
file, err = os.Open("/tmp/tmp.pcap")
handle, err := pcap.OpenOfflineFile(file)
source := gopacket.NewPacketSource(handle, handle.LinkType())

// Fetch packet
for {
packet, err := source.NextPacket()
// Will throw `Read Error`
if err != nil {
if err == io.EOF {
break
}
break
}
}
```

Environment:
- macOS 10.14.6, Golang 1.14.1, libpcap 1.9.1
- Docker 19.03.5, Base image: debian: 10.3, Golang 1.14.2, libpcap 1.9.1

-----

PS: `OpenOffline` works fine. But I want to read libpcap data through TCP connection.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.