What is libwifi?

libwifi is a fast, simple C shared library with a permissive license for generating and parsing a wide variety of 802.11 wireless frames on Linux with a few lines of straight forward code.

It is written with a simple-to-use approach while also exposing features that allow more advanced use, with clean and readable code being a priority.

Other goals of the library include cross-architecture support, clean compilation without warnings and strict error checking.

How do I use it?

libwifi exposes functions and structs to make a task very easy, and examples can be found in the source examples directory.

When compiling, be sure to pass -lwifi to the linker, and make sure that the libwifi shared library is installed.

Any supported 802.11 frame can be parsed in 2 ways:
  • Turning raw data into a libwifi_frame:
    This step (done via libwifi_get_frame()) is used to transform raw bytes, such as those sniffed from a monitor interface or from a pcap, into a frame with a header and body, as well as some fields to help with later use (such as LIBWIFI_FLAGS_FCS_PRESENT).
  • Extracting more data from a libwifi_frame:
    With a libwifi_frame, you can now extract more data from the frame header and body by using one of the frame parsers, such as libwifi_parse_beacon(). This function will ingest a libwifi_frame who's type and subtype is Management and Beacon respectfully, and store the data in a libwifi_bss struct. This makes it trivial to obtain things like the SSID, Channel, and Encryption information from a given frame.

How do I build it?

The build system is implemented with CMake. To build it, clone the repository and run the following commands.
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release
$ make -j8
$ sudo make install

How fast is it?

There is a simple benchmark for measuring Beacon parsing (including all tagged parameters) performance in the benchmark directory. Here are the results when ran on an i7-1185G7 at 3.00GHz.
$ ./benchmark_beacon
Run 1: 0.0000190 Seconds
Run 2: 0.0000030 Seconds
Run 3: 0.0000020 Seconds
Run 4: 0.0000010 Seconds
Run 5: 0.0000010 Seconds
Run 6: 0.0000010 Seconds
Run 7: 0.0000020 Seconds
Run 8: 0.0000020 Seconds
Run 9: 0.0000020 Seconds
Run 10: 0.0000010 Seconds
Run 11: 0.0000010 Seconds
Run 12: 0.0000010 Seconds

Where are the docs?

The source code for libwifi is fully documented with code comments, including diagrams for structs and frame layouts where necessary.