Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Support for gzip compressed files in pcap source #31

Merged
merged 2 commits into from
May 7, 2023

Conversation

fako1024
Copy link
Owner

@fako1024 fako1024 commented May 6, 2023

Closes #30

@fako1024 fako1024 added the enhancement New feature or request label May 6, 2023
@fako1024 fako1024 added this to the Initial Release (v1) milestone May 6, 2023
@fako1024 fako1024 self-assigned this May 6, 2023
@fako1024 fako1024 linked an issue May 6, 2023 that may be closed by this pull request
@fako1024 fako1024 requested a review from els0r May 6, 2023 08:31
@@ -248,13 +262,13 @@ func testCaptureMethods(t *testing.T, fn func(t *testing.T, src *Source)) {
}
}

//go:embed testdata/*
var pcaps embed.FS
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@els0r Don't know if you ever used this, but I stumbled across it while doing mock test extension on goProbe. It's a really nice and easy way to embed test files from the repository (e.g. pcap files) inside the test binary (which makes it portable) without having to rely on crude mechanisms like base-64 embedding in .go files: https://pkg.go.dev/embed

// Parse the main header
if err := obj.read(obj.buf); err != nil {
return nil, err
}

// If required, swap endianess as defined here:
// https://wiki.wireshark.org/Development/LibpcapFileFormat
obj.header = *(*Header)(unsafe.Pointer(&obj.buf[0]))
obj.header = *(*Header)(unsafe.Pointer(&obj.buf[0])) // #nosec G103
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but I started to audit the unsafe use as suggested by the Linter (basically telling it "I know what I'm doing here"), will do the same everywhere else soon.

obj := Source{
Reader: r,
reader: bufio.NewReader(r),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped the "normal" io.Reader in a buffered one in order to support peeking ahead (probably also increasing performance for large files).

Copy link
Collaborator

@els0r els0r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@fako1024 fako1024 merged commit e2a8860 into main May 7, 2023
@fako1024 fako1024 deleted the 30-support-for-gzip-compressed-files-in-pcap-source branch May 7, 2023 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for gzip-compressed files in pcap source
2 participants