libwifi: an 802.11 frame parsing and generation library written in C

https://news.ycombinator.com/rss Hits: 20
Summary

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 and macOS 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. libwifi exposes functions and structs to make parsing and generating WiFi frames very easy, and examples can be found in the source examples directory. When using libwifi, be sure to pass -lwifi to the linker, and make sure that the libwifi shared library is installed on the system. Parsing The generic flow of a program using libwifi to parse frames is a loop that reads captured packets as raw data, such as with libpcap from a file or monitor interface, then parse the frame into a common datatype, then parse again to retrieve frame specific data. static int got_radiotap = 0; int main(int argc, const char *argv[]) { pcap_t handle = {0}; char errbuf[PCAP_ERRBUF_SIZE] = {0}; if ((handle = pcap_create(argv[2], errbuf)) == NULL) { exit(EXIT_FAILURE); } if (pcap_activate(handle) != 0) { pcap_close(handle); exit(EXIT_FAILURE); } int linktype = pcap_datalink(handle); if (linktype == DLT_IEEE802_11_RADIO) { got_radiotap = 1; } else if (linktype == DLT_IEEE802_11) { got_radiotap = 0; } else { pcap_close(handle); exit(EXIT_FAILURE); } pd = pcap_dump_open(handle, PCAP_SAVEFILE); pcap_loop(handle, -1 /*INFINITY*/, &parse_packet, (unsigned char *) pd); } The data from the libpcap loop is then given to libwifi_get_frame() which checks for frame validity and type/subtype, and stores the data in a struct libwifi_frame. void parse_packet(unsigned char *args, const struct pcap_pkthdr *header, const unsigned char *packet) { unsigned long data_len = header->caplen; unsigned char *data = (unsigned char *) packet; struct li...

First seen: 2025-11-15 23:56

Last seen: 2025-11-16 18:58