libiwinfo: reuse existing temporary interface for scanning

This commit is contained in:
Jo-Philipp Wich 2010-10-12 06:43:46 +00:00
parent 62fe7c0e77
commit 1423d3556e

View file

@ -1138,7 +1138,7 @@ static void nl80211_get_scancrypto(const char *spec,
int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
{
int freq, rssi, qmax, count;
int freq, rssi, qmax, count, is_tmp = 0;
char *res;
char cmd[256];
char ssid[128] = { 0 };
@ -1245,10 +1245,24 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
{
if( (res = nl80211_ifname2phy(ifname)) != NULL )
{
/*
* This is a big ugly hack, just look away.
*/
/* Got a temp interface, don't create yet another one */
if( !strncmp(ifname, "tmp.", 4) )
{
sprintf(cmd, "ifconfig %s up 2>/dev/null", ifname);
if( WEXITSTATUS(system(cmd)) )
return -1;
wext_get_scanlist(ifname, buf, len);
sprintf(cmd, "ifconfig %s down 2>/dev/null", ifname);
(void) WEXITSTATUS(system(cmd));
return 0;
}
/* Spawn a new scan interface */
else
{
sprintf(cmd, "ifconfig %s down 2>/dev/null", ifname);
if( WEXITSTATUS(system(cmd)) )
goto out;
@ -1281,6 +1295,7 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
return 0;
}
}
}
return -1;
}