Hi there,

I am looking for a C API that would let me interact with my wireless NIC (such as listing available SSIDs etc...)? Well, a bit of googling revealed there is no API high level APIs in FreeBSD.

I had a quick look at some of the code in /usr/src/sys/net80211, but I really would appreciate any recommendations you could give in terms of any ioctl(2) usage examples, further reading (tutorials...) etc...

/usr/src/sbin/ifconfig/ifieee80211.c has some useful code in it (such as implementation list_scan() function that is called when ifconfig wlan0 list scan is invoked) but I could not see any usage example for ioctl(2).
Last edited:
Thanks for all the answers....I also have found some bits that could be useful for anybody looking for a similar reference on FreeBSD IEEE802.11 implementation. For googlers and other FreeBSD Forum folks.....

ondra_knezour, although libficonfig looks like a promising project, it does not seem to include any IEEE802.11 related code at all, and I doubt the project has such a goal.... But I really like the project, watching the GitHub repo now :)

Re my OP, having a more closer look at /usr/src/sbin/ifconfig/ifieee80211.c file has revealed that it has lots of code from lib80211 in it. This API, i.e. lib80211, is an effort to migrate IEEE802.11 related code out of ifconfig source code. This is how Adrian Chadd explains it


I've started migrating net80211 specific bits out of ifconfig into a library.


I'd like to commit this initial step in a couple of days so I can
easily add more to things.

I'd love feedback. ;)


The man page for lib80211 is not installed on my system, but if you have the source on your disk, you can view the man page simply by
% man /usr/src/lib/lib/lib80211/lib80211.3

There is also a good reading for those who would like to learn more about FreeBSD's IEEE 802.11 protocol stack, the net80211(4) manual page, which should be read after having a look at netintro(4).
And, here is a simple example...this code does not make use of lib80211 but should give an idea about how one could use ioctl(2) calls to gather information from wlan(4) device.

#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <net80211/ieee80211_ioctl.h>
#include <string.h>

int main(int argc, char **argv){
  struct ieee80211req ireq;  /* see net80211(4) */
  struct ieee80211_channel channel;  /* /usr/include/net80211/_ieee80211.h */
  int sock;

  if ((sock = socket(AF_LOCAL,SOCK_DGRAM,0)) == -1) {
  return -1;

  /* prepare the ireq struct */
  memset(&ireq, 0,sizeof(ireq));
  strncpy(ireq.i_name, argv[1], sizeof(ireq.i_name));
  ireq.i_type = IEEE80211_IOC_CURCHAN; /* see net80211(4) for other possible request types */
  ireq.i_data = &channel; /* ioctl(2) will store requested information into the address pointed by i_data */
  ireq.i_len = sizeof(channel);

  /* see net80211(4) for IEEE 802.11 device ioctl(2) request types */
  if (ioctl(sock, SIOCG80211, &ireq) == -1){
  return -1;

  /* print something  */
  printf("WLAN Frequency = %d MHz\n", channel.ic_freq);
  printf("IEEE Channel Number  = %d\n", channel.ic_ieee);

  return 0;

~/code/ioctl_test % ifconfig -l 
em0 iwn0 lo0 wlan0 ue0
~/code/ioctl_test % clang ioctl_test.c -o ioctl_test
~/code/ioctl_test % ./ioctl_test wlan0 
WLAN Frequency = 2437 MHz
IEEE Channel Number  = 6
~/code/ioctl_test %