:: Re: [DNG] Debugging netman auto-con…
トップ ページ
このメッセージを削除
このメッセージに返信
著者: Rainer Weikusat
日付:  
To: dng
題目: Re: [DNG] Debugging netman auto-connect.
Edward Bartolo <edbarx@???> writes:
> Since yesterday I have been trying to understand why "char**
> essid_list" is working inside getInstalledEssidList(&count,
> essid_list) but failing as soon as I try to access essid_list[0]
> outside the function.
>
> Both the source and the gdb text output are attached.
>
> Any helpful pointers are appreciated.


The prototype of getInstalledEssidList is

int getInstalledEssidList(int* count, char** essid_list)

and you call that as

char** essid_list;

[...]

getInstalledEssidList(&count, essid_list);

C passes everything by value, hence, getInstalledEssidList gets called
with a copy of the value of the essid_list of the caller (an
uninitialized pointer) and then goes on to modify this copy, ie, changes
don't affect anything outside of the function. In theory, you could pass
a *** and then modify the original pointer but it's a good idea to avoid
avoidable levels of indirection. The easiest way to do something like
this is to return the char ** from the function, returning NULL to
signal failure/ "didn't find anyhting".

NB: getRadiatingWifiList obviously suffers from the same problem and
will need to be modified in the same way.

--------------
--- automated_scanner.c 2015-09-11 14:42:34.319852358 +0100
+++ a.c 2015-09-11 14:50:28.937357676 +0100
@@ -41,11 +41,14 @@
} wifi_quality;


-int getInstalledEssidList(int* count, char** essid_list)
+char **getInstalledEssidList(int* count)
 {
+       char **essid_list;
        DIR * dir;
        struct dirent * ent;
        int el_size = 0; // stands for essid_list size
+
+       essid_list = NULL;


        // First get a list of installed wireless "interfaces" files
        if ((dir = opendir(IFACES_PATH)) != 0) {
@@ -81,10 +84,10 @@
                        IFACES_PATH, strerror(errno)
                );


-               return old_errno;
+               return NULL;
        }


-       return 0;
+       return essid_list;
 }


 int getRadiatingWifiList(int* active_wifis, void** active_wifi_list)
@@ -199,7 +202,7 @@
        char* scan_buffer;


        // get a list of currently installed wifi essids
-       getInstalledEssidList(&count, essid_list);
+       essid_list = getInstalledEssidList(&count);
        //fprintf(stdout, essid_list[0], "\n"); 


        // get a list of irradiating wifis
-----------------