X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;ds=inline;f=wifiscand%2Fwifiscand.c;h=d0df690f3053a982e8fd332a8d07ba5c942b17c0;hb=e4cb350eceeaa7a50e20de154c9f59139703eefb;hp=5f94f2f7fcc870eca566d607fcd9445a747a5082;hpb=2133ef6dbeff4688ec66ecf3ae7eee97389a48c9;p=wifihood diff --git a/wifiscand/wifiscand.c b/wifiscand/wifiscand.c index 5f94f2f..d0df690 100644 --- a/wifiscand/wifiscand.c +++ b/wifiscand/wifiscand.c @@ -99,22 +99,22 @@ void* makeScan(WirelessInterface* wlan, gchar *message) { if ( delay == 0 ) { - scan = (ScanInfo**) malloc( 25 * sizeof(ScanInfo *) ); - memset(scan, 0, 25 * sizeof(ScanInfo *) ); - *scan = NULL; - int i; - for (i=0; i<25; i++) *(scan+i) = NULL; + int i = 1; // To acount for the final NULL + struct wireless_scan *ap = context.result; + while ( ap != NULL ) { + ap = ap->next; + i++; + } + scan = (ScanInfo**) malloc( i * sizeof(ScanInfo *) ); + memset(scan, 0, i * sizeof(ScanInfo *) ); - i = 0; - ScanInfo *sc = NULL; + ScanInfo **sc = scan; /* Extract values */ - struct wireless_scan *ap = context.result; - while ( ap != NULL && i < 25 ) { - WirelessInterface_ScanItem(ap, &sc); - *(scan+i) = sc; + ap = context.result; + while ( ap != NULL ) { + WirelessInterface_ScanItem(ap, sc++); ap = ap->next; - i++; } } else { @@ -188,6 +188,17 @@ gint dbus_req_handler(const gchar * interface, const gchar * method, return OSSO_ERROR; } + /* Get range stuff */ + iwrange range; + int has_range = (iw_get_range_info(appdata->iface.sock, appdata->iface.ifname, &range) >= 0); + + /* Check if the interface could support scanning. */ + if((!has_range) || (range.we_version_compiled < 14)) { + retval->value.s = (gchar *) realloc(retval->value.s,35*sizeof(gchar *)); + snprintf(retval->value.s,35,"Interface doesn't support scanning"); + return OSSO_ERROR; + } + struct ifreq frq; strncpy(frq.ifr_name, appdata->iface.ifname, IFNAMSIZ); if(ioctl(appdata->iface.sock, SIOCGIFFLAGS, &frq)) { @@ -242,15 +253,19 @@ gint dbus_req_handler(const gchar * interface, const gchar * method, return OSSO_ERROR; } - int i; - for (i=0; i<25&&*(scan+i)!=NULL; i++) { - ScanInfo* sc = *(scan+i); - retval->value.s = (gchar *) realloc(retval->value.s,23*(i+1)*sizeof(gchar *)); + int i = 0; + while ( *(scan+i) != NULL ) i++; + retval->value.s = (gchar *) malloc( (22*i+1) * sizeof(gchar *) ); if ( retval->value.s == NULL ) { retval->value.s = "Error allocating memory"; return OSSO_ERROR; - } - sprintf(retval->value.s+strlen(retval->value.s),"%s:%d ",sc->mac,sc->rssi); + } + memset(retval->value.s, '\0', (22*i+1) * sizeof(gchar *) ); + i = 0; + while ( *scan != NULL ) { + sprintf(retval->value.s+(22*i),"%s:%d ",(*scan)->mac,(*scan)->rssi); + scan++; + i++; } retval->value.s[strlen(retval->value.s)-1] = '\0';