- * Read /proc/net/wireless to get the latest statistics
- */
-static int
-iw_getstats(char * ifname,
- iwstats * stats)
-{
- FILE * f=fopen("/proc/net/wireless","r");
- char buf[256];
- char * bp;
- int t;
- if(f==NULL)
- return -1;
- /* Loop on all devices */
- while(fgets(buf,255,f))
- {
- bp=buf;
- while(*bp&&isspace(*bp))
- bp++;
- /* Is it the good device ? */
- if(strncmp(bp,ifname,strlen(ifname))==0 && bp[strlen(ifname)]==':')
- {
- /* Skip ethX: */
- bp=strchr(bp,':');
- bp++;
- /* -- status -- */
- bp = strtok(bp, " ");
- sscanf(bp, "%X", &t);
- stats->status = (unsigned short) t;
- /* -- link quality -- */
- bp = strtok(NULL, " ");
- if(strchr(bp,'.') != NULL)
- stats->qual.updated |= 1;
- sscanf(bp, "%d", &t);
- stats->qual.qual = (unsigned char) t;
- /* -- signal level -- */
- bp = strtok(NULL, " ");
- if(strchr(bp,'.') != NULL)
- stats->qual.updated |= 2;
- sscanf(bp, "%d", &t);
- stats->qual.level = (unsigned char) t;
- /* -- noise level -- */
- bp = strtok(NULL, " ");
- if(strchr(bp,'.') != NULL)
- stats->qual.updated += 4;
- sscanf(bp, "%d", &t);
- stats->qual.noise = (unsigned char) t;
- /* -- discarded packets -- */
- bp = strtok(NULL, " ");
- sscanf(bp, "%d", &stats->discard.nwid);
- bp = strtok(NULL, " ");
- sscanf(bp, "%d", &stats->discard.code);
- bp = strtok(NULL, " ");
- sscanf(bp, "%d", &stats->discard.misc);
- fclose(f);
- return 0;
- }
- }
- fclose(f);
- return -1;
-}
-
-/*------------------------------------------------------------------*/
-/*