Skip to content

OpenOfflineFile not working with os.Open #774

@XSAM

Description

@XSAM

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()

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions