parsing ssid with iwconfig in c
- by user1781595
I am about building a bar for DWM (ubuntu linux), showing wifi details such as the ssid.
Thats my code:
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] )
{
FILE *fp;
int status;
char path[1035];
/* Open the command for reading. */
fp = popen("iwconfig", "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit;
}
char s[500];
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
sprintf(s,"%s%s",s, path);
}
//printf("%s",s);
/* close */
pclose(fp);
char delimiter[1] = "s";
char *ptr;
ptr = strtok(s, delimiter);
printf("SSID: %s\n", ptr);
return 0;
}
i am getting overflowerrors and dont know what to do.
I dont think, thats a good way to get the ssid either... :/
Suggestions?