Skip to content

Conversation

@malor
Copy link

@malor malor commented Jun 3, 2024

Hey, @rossmacarthur!

I was playing around with the code and I wonder what you think about the idea of adding support for:

  1. Building Radiotap values programmatically
  2. Serializing Radiotap values into the wire format

The former is sort of already possible by the nature of having all fields of the Radiotap struct declared as public, but it's also annoying as the Header value needs to be updated accordingly afterwards. Also, some of the types do not currently implement Default which makes it tedious. A builder struct should make this straightforward.

And then we can implement serialization on top of that to support the use case of building Radiotap headers for packet injection.

Thank you!

malor added 2 commits May 13, 2024 21:01
All the fields of the Radiotap struct are public, and the struct
already implements Default, so while it *is* possible to build values
in code, doing so is inconvenient: the Header value has to be populated
correctly based on which fields are set and in which order they appear
in the serialized format. A dedicated builder struct allows to do it
fluently and prevent potential mistakes.

This requires minimal changes to the existing API, most of which are
optional:

* Kind::bit() offers a conversion from an enum variant back to a bit
number value; that value defines the order in which fields appear
in the serialized format

* Radiotap::build() is a helper function that starts the build process

* Implementing Default makes passing flag values slightly less verbose

The primary motivation for this change is to allow building Radiotap
values programmatically and later serialize them to the wire format.
Add a new method called `unparse()` that serializes a Radiotap value
into a stream of bytes according to the rules of the Radiotap wire
format. In conjunction with the `build()` method this allows to build
Radiotap values programmatically, e.g. for packet injection.

Adding a new test uncovered a few issues in the existing code related
to the precedence of bitwise operations that are now fixed.
@malor malor changed the title Add supporting for building and serializing Radiotap values Add support for building and serializing Radiotap values Jun 3, 2024
@msdrigg
Copy link

msdrigg commented Aug 8, 2024

I'd love to see this too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants