C code to get the same information like iwlist wlan scan

Started by
2 comments, last by hplus0603 7 years ago

Welcome is there any possibility to get the same information in application in C like iwlist wlan scan in terminal ? Only what I found is : How can I get a list of available wireless networks on Linux? which does not work and show only ssid of available network. I would like to get mainly ssid and mac adresses devices available on interface WLAN.

Advertisement

Well, those tools are open source and written in C, so you can just grab the sources and see how they did it.

Stephen M. Webb
Professional Free Software Developer

Another option would be to avoid duplicating the code but instead to create a pipe(), fork() your process, then in the child set stdin / stdout to use the pipe and finally exec() the iwlist program so that the parent process can read the output from the pipe and parse it.

This is essentially what happens when you use the unix "|" on the command line to pipe the output of one process to the input of another.

I agree; those tools are written in C, so you can do whatever they do.

I don't know what your install options are. For example, if you need to be able to build and install for systems where you can't guarantee that iwlist is installed, you may want to include the equivalent code instead. Else, just use pipe/fork/exec, or even the simplistic popen() function.

Note that some functions may need root privileges, so may not be great for using in a piece of software you ship to end users.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement