On Fri, Jan 02, 2015 at 09:02:53PM +0100, Simon Nicolussi wrote: > Hello, > > 31C3 had lots of access points sharing a network ID. Coming up with an > AWK script to determine the network with the best coverage is easy, but > still harder than simply choosing the first one that ifconfig iwn0 scan > would spit out if only its output was sorted by signal strength (and in > decreasing order, as by convention).
Thanks! I like this. Works as expected for me on STAs and APs. Note that 'ifconfig scan' is also used to list associated STAs when running as AP. So this will also sort associated STAs by received signal strength indication. > Index: ifconfig.c > =================================================================== > RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v > retrieving revision 1.290 > diff -u -p -u -r1.290 ifconfig.c > --- ifconfig.c 1 Jan 2015 22:53:39 -0000 1.290 > +++ ifconfig.c 2 Jan 2015 18:29:06 -0000 > @@ -2221,6 +2221,17 @@ ieee80211_listchans(void) > } > } > > +/* > + * Returns an integer less than, equal to, or greater than zero if nr1's > + * RSSI is respectively greater than, equal to, or less than nr2's RSSI. > + */ > +static int > +rssicmp(const void *nr1, const void *nr2) > +{ > + const struct ieee80211_nodereq *x = nr1, *y = nr2; > + return y->nr_rssi < x->nr_rssi ? -1 : y->nr_rssi > x->nr_rssi; > +} > + > void > ieee80211_listnodes(void) > { > @@ -2256,6 +2267,8 @@ ieee80211_listnodes(void) > > if (!na.na_nodes) > printf("\t\tnone\n"); > + else > + qsort(nr, na.na_nodes, sizeof(*nr), rssicmp); > > for (i = 0; i < na.na_nodes; i++) { > printf("\t\t"); > > -- > Simon Nicolussi <si...@sinic.name> > http{s,}://{www.,}sinic.name/