Skip to content

solidpulse/pcap-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Golang pcap-reader

Golang pcap-reader reads files that are in lib pcap file format. pcap files are usually generated by tools like tcpdump and wireshark.

Example:

package main

import (
	"fmt"
	"io"

	"github.com/evnix/pcap-reader"
)

func main() {

	fname := "/var/file.pcap"
	pcaprdr := pcapreader.PCapReader{}
	pcaprdr.Open(fname)
	defer pcaprdr.Close()
	fmt.Println(pcaprdr.PcapHdr.MagicNumber)

	for {
		packetHeader, data, err := pcaprdr.ReadNextPacket()
		if err == io.EOF {
			fmt.Println("Reached end of file.")
			break
		}
		fmt.Println("Packet Header:", packetHeader)
		fmt.Println("Data:", data)
	}

}

For more info on the libpcap file format, refer: https://wiki.wireshark.org/Development/LibpcapFileFormat

About

Golang pcap file reader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages