Filter only wifi interface list and show

This commit is contained in:
lakinduakash 2019-04-16 09:41:44 +05:30
parent 30907f82e9
commit e0777ff70c
3 changed files with 79 additions and 3 deletions

View File

@ -10,7 +10,7 @@
#include "read_config.h"
#define BUFSIZE 1024
#define BUFSIZE 512
#define SUDO "pkexec --user root"
@ -28,6 +28,7 @@ char cmd_kill[BUFSIZE];
char running_info[BUFSIZE];
char interface_list[BUFSIZE];
char wifi_interface_list[BUFSIZE];
const char* g_ssid=NULL;
const char* g_pass=NULL;
@ -247,3 +248,68 @@ char** get_interface_list(int *length){
return NULL;
}
static int init_get_wifi_interface_list(){
const char* cmd="iw dev | awk '$1==\"Interface\"{print $2}' ";
FILE *fp;
if ((fp = popen(cmd, "r")) == NULL) {
printf("Error opening pipe!\n");
return -1;
}
while (fgets(wifi_interface_list, BUFSIZE, fp) != NULL) {
// Do whatever you want here...
}
if (pclose(fp)) {
printf("Command not found or exited with error status\n");
return -1;
}
return 0;
}
char** get_wifi_interface_list(int *length){
if(init_get_wifi_interface_list()==0){
char *a=strdup(wifi_interface_list);
char *b=strdup(wifi_interface_list);
char * pch;
pch = strtok (a,"\n");
int i=0;
while (pch != NULL)
{
pch = strtok (NULL, "\n");
i++;
}
static char** arr;
arr =malloc(i * sizeof(char*));
free(a);
pch = strtok (b,"\n");
i=0;
while (pch != NULL)
{
printf("%s", pch);
arr[i]=strdup(pch);
pch = strtok (NULL, "\n");
i++;
}
*length= i;
return arr;
}
return NULL;
}

View File

@ -23,4 +23,6 @@ static int init_get_interface_list();
char** get_interface_list(int*);
const char* build_kill_create_ap_command(char* pid);
char** get_wifi_interface_list(int *length);
#endif //WIHOTSPOT_H_PROP_H

View File

@ -34,7 +34,9 @@ GError *error = NULL;
const char** iface_list;
const char** wifi_iface_list;
int iface_list_length;
int wifi_iface_list_length;
char* running_info[3];
guint id;
@ -159,7 +161,7 @@ void init_ui_from_config(WIData* data){
gtk_entry_set_text(data->pass,values->pass);
if(values->iface_wifi!=NULL){
int idw=find_str(values->iface_wifi,iface_list,iface_list_length);
int idw=find_str(values->iface_wifi,wifi_iface_list,wifi_iface_list_length);
if(idw !=-1){
gtk_combo_box_set_active(combo_wifi,idw);
@ -180,13 +182,19 @@ void init_ui_from_config(WIData* data){
void init_interface_list(){
iface_list_length=0;
wifi_iface_list_length=0;
iface_list=(const char**)get_interface_list(&iface_list_length);
wifi_iface_list=(const char**)get_wifi_interface_list(&wifi_iface_list_length);
for (int i = 0; i < iface_list_length; i++){
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_wifi), iface_list[i]);
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_internet), iface_list[i]);
}
for (int i = 0; i < wifi_iface_list_length; i++){
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_wifi), wifi_iface_list[i]);
}
}