0

I am doing a standard fork/execl in C++ on my Ubuntu PC to scan for Wi-Fi SSIDs. It looks like the interface name is not taking effect when called with excel.

execl( "/sbin/iwlist", "wlp4s0", "scanning", (char*) NULL );

This succeeds but I get this in stderr:

lo Interface doesn't support scanning.

enp0s25 Interface doesn't support scanning.

It looks like iwlist is trying to scan all interfaces.

If instead I do:

system( "/sbin/iwlist wlp4s0 scanning" );

I do not get these messages in stderr.

Is there something I am doing wrong in my execl call?

Nathan Owen
  • 155
  • 10

1 Answers1

0

Figured it out.

In bash you always write something like

command arg1 arg2 ...

When the program 'command' parses the its arguments, the first argument (argv[0]) is 'command'.

However, when you call 'command' using using execl like this:

execl( "/path/to/command", "arg1", "arg2", (char*) NULL );

the first argument it gets is 'arg1'. This clearly does not work if the command is expecting this as argv[1] and is instead getting it as argv[0].

This explains why the command was ignoring my "wlp4s0" ifname. It was simply ignoring the first argument which it expected to be the command name/path.

So the solution to my original problem is this:

execl( "/sbin/iwlist", "iwlist", "wlp4s0", "scanning", (char*) NULL );
Nathan Owen
  • 155
  • 10