Add new sources to get and set command line properties

This commit is contained in:
lakinduakash 2019-04-13 03:47:17 +05:30
parent 2acb716ff6
commit 324f2937cc
2 changed files with 67 additions and 0 deletions

55
src/ui/h_prop.c Normal file
View File

@ -0,0 +1,55 @@
//
// Created by lakinduakash on 13/04/19.
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "h_prop.h"
#define BUFSIZE 1024
#define SUDO "sudo"
#define CREATE_AP "create_ap"
char cmd[BUFSIZE];
int parse_output(char *cmd) {
char buf[BUFSIZE];
FILE *fp;
if ((fp = popen(cmd, "r")) == NULL) {
printf("Error opening pipe!\n");
return -1;
}
while (fgets(buf, BUFSIZE, fp) != NULL) {
// Do whatever you want here...
printf("OUTPUT: %s", buf);
}
if(pclose(fp)) {
printf("Command not found or exited with error status\n");
return -1;
}
return 0;
}
char * build_command(char* iface_src,char* iface_dest,char* ssid, char* pass){
snprintf(cmd,BUFSIZE,"%s %s %s %s %s %s",SUDO,CREATE_AP,iface_src,iface_dest,ssid,pass);
return cmd;
}
int startShell(char* cmd){
parse_output(cmd);
}

12
src/ui/h_prop.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by lakinduakash on 13/04/19.
//
#ifndef WIHOTSPOT_H_PROP_H
#define WIHOTSPOT_H_PROP_H
int parse_output(char *);
char * build_command(char*, char*,char*, char*);
int startShell(char*);
#endif //WIHOTSPOT_H_PROP_H